Skip to content
Open

Done #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions part-1/1/src/main/java/org/example/ClickCounterApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.example;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ClickCounterApp extends JFrame implements ActionListener {

private JButton clickButton;
private JLabel counterLabel;
private int counter = 0;

public ClickCounterApp() {

setTitle("Click Counter ๏̯̃๏ ");
counterLabel = new JLabel("Clicks : 0" , SwingConstants.CENTER);
clickButton = new JButton("Click Me");
clickButton.addActionListener(this);

setSize(200, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new BorderLayout());
add(counterLabel , BorderLayout.CENTER);
add(clickButton , BorderLayout.SOUTH);

getContentPane().setBackground(Color.decode("#d3b1ed"));



}


@Override
public void actionPerformed(ActionEvent e){
counter++;
counterLabel.setText("Clicks : " + counter);
}

}
9 changes: 9 additions & 0 deletions part-1/1/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example;
import javax.swing.*;


public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(() ->new ClickCounterApp().setVisible(true));
}
}
Empty file removed part-2/E2.java
Empty file.
51 changes: 51 additions & 0 deletions part-2/GreetingFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GreetingFormApp extends JFrame implements ActionListener {
private JTextField nameField;
private JButton greetButton;
private JLabel messageLabel;

public GreetingFormApp() {
setTitle("Greeting Form");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
getContentPane().setBackground(Color.decode("#FFD1DC"));



nameField = new JTextField(15);
greetButton = new JButton("Greet");
messageLabel = new JLabel("Enter your name and press Greet.", SwingConstants.CENTER);

greetButton.addActionListener(this);

JPanel inputPanel = new JPanel();
inputPanel.add(new JLabel("Name:"));
inputPanel.add(nameField);
inputPanel.add(greetButton);

messageLabel.setFont(new Font("Comic Sans MS", Font.BOLD, 16));
nameField.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
setLayout(new BorderLayout());
add(inputPanel, BorderLayout.NORTH);
add(messageLabel, BorderLayout.CENTER);
}

@Override
public void actionPerformed(ActionEvent e) {
String name = nameField.getText().trim();
if (name.isEmpty()) {
messageLabel.setText("Please enter a name.");
} else {
messageLabel.setText("Hello, " + name + "!");
}
}


}
7 changes: 7 additions & 0 deletions part-2/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import javax.swing.*;
public class Main{
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new GreetingFormApp().setVisible(true));
}

}
7 changes: 7 additions & 0 deletions part-3/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import javax.swing.*;

public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new ThemeColorSelectorApp().setVisible(true));
}
}
49 changes: 49 additions & 0 deletions part-3/ThemeColorSelectorApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ThemeColorSelectorApp extends JFrame implements ActionListener {
private JPanel mainPanel;
private JButton redButton;
private JButton greenButton;
private JButton blueButton;

public ThemeColorSelectorApp() {
setTitle("Theme Color Selector");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);

mainPanel = new JPanel();

redButton = new JButton("Red");
greenButton = new JButton("Green");
blueButton = new JButton("Blue");

redButton.setActionCommand("RED");
greenButton.setActionCommand("GREEN");
blueButton.setActionCommand("BLUE");

redButton.addActionListener(this);
greenButton.addActionListener(this);
blueButton.addActionListener(this);

JPanel buttonPanel = new JPanel();
buttonPanel.add(redButton);
buttonPanel.add(greenButton);
buttonPanel.add(blueButton);

setLayout(new BorderLayout());
add(buttonPanel, BorderLayout.NORTH);
add(mainPanel, BorderLayout.CENTER);
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case "RED": mainPanel.setBackground(Color.decode("#ff3232")); break;
case "GREEN": mainPanel.setBackground(Color.decode("#c5f7a5")); break;
case "BLUE": mainPanel.setBackground(Color.decode("#cce9ff")); break;
}
}
}
7 changes: 7 additions & 0 deletions part-4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import javax.swing.*;

public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new RegistrationFormApp().setVisible(true));
}
}
92 changes: 92 additions & 0 deletions part-4/RegistrationFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class RegistrationFormApp extends JFrame implements ActionListener {
private JTextField txtName;
private JTextField txtEmail;
private JPasswordField txtPassword;
private JRadioButton rbMale, rbFemale;
private JCheckBox cbJava, cbPython, cbCpp;
private JButton btnSubmit;
private GridBagConstraints gbc;

public RegistrationFormApp() {
setTitle("User Registration");
setSize(500, 350);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);

JPanel panel = new JPanel(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.fill = GridBagConstraints.HORIZONTAL;


gbc.gridx = 0; gbc.gridy = 0;
panel.add(new JLabel("Name:"), gbc);
gbc.gridx = 1;
txtName = new JTextField(20);
panel.add(txtName, gbc);


gbc.gridx = 0; gbc.gridy = 1;
panel.add(new JLabel("Email:"), gbc);
gbc.gridx = 1;
txtEmail = new JTextField(20);
panel.add(txtEmail, gbc);


gbc.gridx = 0; gbc.gridy = 2;
panel.add(new JLabel("Password:"), gbc);
gbc.gridx = 1;
txtPassword = new JPasswordField(20);
panel.add(txtPassword, gbc);


gbc.gridx = 0; gbc.gridy = 3;
panel.add(new JLabel("Gender:"), gbc);
gbc.gridx = 1;
rbMale = new JRadioButton("Male"); rbFemale = new JRadioButton("Female");
ButtonGroup bg = new ButtonGroup(); bg.add(rbMale); bg.add(rbFemale);
JPanel genderPanel = new JPanel(); genderPanel.add(rbMale); genderPanel.add(rbFemale);
panel.add(genderPanel, gbc);


gbc.gridx = 0; gbc.gridy = 4;
panel.add(new JLabel("Interests:"), gbc);
gbc.gridx = 1;
cbJava = new JCheckBox("Java"); cbPython = new JCheckBox("Python"); cbCpp = new JCheckBox("C++");
JPanel interestPanel = new JPanel();
interestPanel.add(cbJava); interestPanel.add(cbPython); interestPanel.add(cbCpp);
panel.add(interestPanel, gbc);


gbc.gridx = 1; gbc.gridy = 5;
gbc.anchor = GridBagConstraints.CENTER;
btnSubmit = new JButton("Submit");
btnSubmit.addActionListener(this);
panel.add(btnSubmit, gbc);

add(panel);
}

@Override
public void actionPerformed(ActionEvent e) {
String name = txtName.getText();
String email = txtEmail.getText();
String gender = rbMale.isSelected() ? "Male" : rbFemale.isSelected() ? "Female" : "Unspecified";
String interests = "";
if (cbJava.isSelected()) interests += "Java ";
if (cbPython.isSelected()) interests += "Python ";
if (cbCpp.isSelected()) interests += "C++ ";

JOptionPane.showMessageDialog(this,
"Name: " + name + "\n" +
"Email: " + email + "\n" +
"Gender: " + gender + "\n" +
"Interests: " + interests,
"Registration Details", JOptionPane.INFORMATION_MESSAGE);
}
}