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
36 changes: 36 additions & 0 deletions part-1/ClickCounterApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ClickCounterApp extends JFrame implements ActionListener {
private JLabel counterLabel;
private JButton clickButton;
private int count = 0;

public ClickCounterApp() {
this.setTitle("Click Counter");
this.counterLabel = new JLabel("Clicks: 0", 0);
this.clickButton = new JButton("Click Me");
this.clickButton.addActionListener(this);
this.setLayout(new BorderLayout());
this.add(this.counterLabel, "Center");
this.add(this.clickButton, "South");
this.setSize(400, 400);
this.setDefaultCloseOperation(3);
this.setLocationRelativeTo((Component)null);
}

public void actionPerformed(ActionEvent e) {
++this.count;
this.counterLabel.setText("Clicks: " + this.count);
}
}
Empty file removed part-1/E1.java
Empty file.
10 changes: 10 additions & 0 deletions part-1/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Main {
public static void main(String[] args) {

SwingUtilities.invokeLater(() -> new ClickCounterApp().setVisible(true));
}
}
43 changes: 43 additions & 0 deletions part-2/GreetingFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class GreetingFormApp extends JFrame implements ActionListener {
private JTextField nameField; // Field for user input
private JButton greetButton; // Button to trigger greeting
private JLabel messageLabel; // Label to display greeting

public GreetingFormApp() {
setTitle("Greeting Form");
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:"));
setSize(400,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
inputPanel.add(nameField);
inputPanel.add(greetButton);

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 + "!");
}
}


}
9 changes: 9 additions & 0 deletions part-2/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import javax.swing.*;

public class Main{

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

import javax.swing.*;


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



public class ThemeColorSelectorApp extends JFrame implements ActionListener {
private JPanel mainPanel; // The panel whose background will change
private JButton redButton; // Button to select red theme
private JButton greenButton; // Button to select green theme
private JButton blueButton; // Button to select blue theme

public ThemeColorSelectorApp() {
setTitle("Theme Color Selector");

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();
setSize(400,300);
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 "GREEN": mainPanel.setBackground(Color.GREEN); break;
case "BLUE": mainPanel.setBackground(Color.BLUE); break;
case "RED": mainPanel.setBackground(Color.RED); break;
}
}

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

public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new RegistrationFormApp().setVisible(true));
}

}
94 changes: 94 additions & 0 deletions part-4/RegistrationFormApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;



public class RegistrationFormApp extends JFrame implements ActionListener {
private JTextField txtName; // User name input
private JTextField txtEmail; // User email input
private JPasswordField txtPassword; // Password input
private JRadioButton rbMale, rbFemale; // Gender selection
private JCheckBox cbJava, cbPython, cbCpp; // Interests selection
private JButton btnSubmit; // Submit form button
private GridBagConstraints gbc; // Layout constraints

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;

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

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

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

// Row 3: Gender selection
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);

// Row 4: Interests selection
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);

// Row 5: Submit button
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);
}

}