Skip to content
Open
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
8 changes: 8 additions & 0 deletions part-1/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions part-1/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions part-1/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions part-1/.idea/part-1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions part-1/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added part-1/E1.class
Binary file not shown.
38 changes: 38 additions & 0 deletions part-1/E1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class E1 extends JFrame implements ActionListener {
JButton button;
JLabel label;
private int clickCount = 0;

public E1() {
button = new JButton("Click Me");
button.setPreferredSize(new Dimension(200, 50));
label = new JLabel("Clicks: 0", SwingConstants.CENTER);

button.addActionListener(this);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
this.setTitle("Click Counter");
this.setSize(400, 400);
this.getContentPane().setBackground(new Color(255, 182, 193));
this.add(button, BorderLayout.SOUTH);
this.add(label, BorderLayout.CENTER);
this.setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
clickCount++;
label.setText("Clicks: " + clickCount);
}
}
public static void main(String[] args) {
new E1();
}
}
Binary file added part-2/E2.class
Binary file not shown.
48 changes: 48 additions & 0 deletions part-2/E2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class E2 extends JFrame implements ActionListener {
private JButton button;
private JLabel label;
private JTextField textField;

public E2() {
button = new JButton("Greet");
button.setPreferredSize(new Dimension(100, 20));
button.addActionListener(this);

label = new JLabel("Enter your name and press Greet", SwingConstants.CENTER);
textField = new JTextField(20);

JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
inputPanel.add(new JLabel("Name:"));
inputPanel.add(textField);
inputPanel.add(button);

JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
mainPanel.add(label, BorderLayout.SOUTH);
mainPanel.add(inputPanel, BorderLayout.CENTER);

this.setTitle("Greeting Form");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 200);
this.add(mainPanel);
this.setVisible(true);
}

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

public static void main(String[] args) {
new E2();
}
}
Binary file added part-3/E3.class
Binary file not shown.
62 changes: 62 additions & 0 deletions part-3/E3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

public E3() {

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);

this.setTitle("Theme Color Selector");
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);

}

@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case "RED":
mainPanel.setBackground(Color.RED);
break;
case "GREEN":
mainPanel.setBackground(Color.GREEN);
break;
case "BLUE":
mainPanel.setBackground(Color.BLUE);
break;
}
}
public static void main(String[] args) {
new E3();
}
}
Binary file added part-4/E4.class
Binary file not shown.
103 changes: 103 additions & 0 deletions part-4/E4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class E4 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 E4() {
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 genderGroup = new ButtonGroup();
genderGroup.add(rbMale);
genderGroup.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);

this.setTitle("User Registration");
this.setSize(500, 350);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);

}

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

JOptionPane.showMessageDialog(this,
"Name: " + name + "\n" +
"Email: " + email + "\n" +
"Gender: " + gender + "\n" +
"Interests: " + interests.toString().trim(),
"Registration Details",
JOptionPane.INFORMATION_MESSAGE
);
}
public static void main(String[] args) {
new E4();
}
}