From 547333c4ac63e7e97757491d0b5315d4bbe325a0 Mon Sep 17 00:00:00 2001 From: Shifu2006 Date: Sun, 11 May 2025 02:16:01 +0330 Subject: [PATCH 1/5] ctrl + c , ctrl + v --- part-1/ClickcounterApp.java | 32 ++++++++++++++++++++++++++++++++ part-1/E1.java | 0 part-1/Main.java | 7 +++++++ 3 files changed, 39 insertions(+) create mode 100644 part-1/ClickcounterApp.java delete mode 100644 part-1/E1.java create mode 100644 part-1/Main.java diff --git a/part-1/ClickcounterApp.java b/part-1/ClickcounterApp.java new file mode 100644 index 0000000..0f64faf --- /dev/null +++ b/part-1/ClickcounterApp.java @@ -0,0 +1,32 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ClickCounterApp extends JFrame implements ActionListener { + + public ClickCounterApp() { + setTitle("Click Counter"); + counterLabel = new JLabel("Clicks: 0", SwingConstants.CENTER); + clickButton = new JButton("Click Me"); + clickButton.addActionListener(this); + + setLayout(new BorderLayout()); + add(counterLabel, BorderLayout.CENTER); + add(clickButton, BorderLayout.SOUTH); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(300, 200); + } + + private JLabel counterLabel; // Displays the click count + private JButton clickButton; // Button to register clicks + private int count = 0; // Stores the current count + + @Override + public void actionPerformed(ActionEvent e) { + count++; // Increment the click counter + counterLabel.setText("Clicks: " + count); + } + + +} \ No newline at end of file diff --git a/part-1/E1.java b/part-1/E1.java deleted file mode 100644 index e69de29..0000000 diff --git a/part-1/Main.java b/part-1/Main.java new file mode 100644 index 0000000..3c3c9c7 --- /dev/null +++ b/part-1/Main.java @@ -0,0 +1,7 @@ +import javax.swing.*; + +public class Main { + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> new ClickCounterApp().setVisible(true)); + } +} \ No newline at end of file From 0e1a9cfb0212707e40bebb444bc07ef0d178ccc7 Mon Sep 17 00:00:00 2001 From: Shifu2006 Date: Sun, 11 May 2025 02:37:51 +0330 Subject: [PATCH 2/5] ctrl + c , ctrl + v --- part-2/E2.java | 0 part-2/GreetingFormApp.java | 41 +++++++++++++++++++++++++++++++++++++ part-2/Main.java | 7 +++++++ 3 files changed, 48 insertions(+) delete mode 100644 part-2/E2.java create mode 100644 part-2/GreetingFormApp.java create mode 100644 part-2/Main.java diff --git a/part-2/E2.java b/part-2/E2.java deleted file mode 100644 index e69de29..0000000 diff --git a/part-2/GreetingFormApp.java b/part-2/GreetingFormApp.java new file mode 100644 index 0000000..4826896 --- /dev/null +++ b/part-2/GreetingFormApp.java @@ -0,0 +1,41 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + + +public class GreetingFormApp extends JFrame implements ActionListener { + 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:")); + inputPanel.add(nameField); + inputPanel.add(greetButton); + + setLayout(new BorderLayout()); + add(inputPanel, BorderLayout.NORTH); + add(messageLabel, BorderLayout.CENTER); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(600, 200); + } + + @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 + "!"); + } + } + + private JTextField nameField; // Field for user input + private JButton greetButton; // Button to trigger greeting + private JLabel messageLabel; // Label to display greeting +} \ No newline at end of file diff --git a/part-2/Main.java b/part-2/Main.java new file mode 100644 index 0000000..b81b73f --- /dev/null +++ b/part-2/Main.java @@ -0,0 +1,7 @@ +import javax.swing.*; + +class Main { + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> new GreetingFormApp().setVisible(true)); + } +} \ No newline at end of file From be85c9b060cb802f0788ae7831781689af9e15ca Mon Sep 17 00:00:00 2001 From: Shifu2006 Date: Sun, 11 May 2025 02:44:50 +0330 Subject: [PATCH 3/5] :) --- part-3/E3.java | 0 part-3/Main.java | 7 +++++ part-3/ThemeColorSelectorApp.java | 49 +++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) delete mode 100644 part-3/E3.java create mode 100644 part-3/Main.java create mode 100644 part-3/ThemeColorSelectorApp.java diff --git a/part-3/E3.java b/part-3/E3.java deleted file mode 100644 index e69de29..0000000 diff --git a/part-3/Main.java b/part-3/Main.java new file mode 100644 index 0000000..cb06633 --- /dev/null +++ b/part-3/Main.java @@ -0,0 +1,7 @@ +import javax.swing.*; + +public class Main { + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> new ThemeColorSelectorApp().setVisible(true)); + } +} diff --git a/part-3/ThemeColorSelectorApp.java b/part-3/ThemeColorSelectorApp.java new file mode 100644 index 0000000..539e790 --- /dev/null +++ b/part-3/ThemeColorSelectorApp.java @@ -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 { + 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(); + buttonPanel.add(redButton); + buttonPanel.add(greenButton); + buttonPanel.add(blueButton); + + setLayout(new BorderLayout()); + add(buttonPanel, BorderLayout.NORTH); + add(mainPanel, BorderLayout.CENTER); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(300, 400); + } + + @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; + } + } + + 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 +} \ No newline at end of file From aa7b86f5d25d2e17830461b10446fd12dae3438b Mon Sep 17 00:00:00 2001 From: Shifu2006 Date: Sun, 11 May 2025 02:53:36 +0330 Subject: [PATCH 4/5] #_# --- part-4/E4.java | 0 part-4/Main.java | 7 +++ part-4/RegistrationFormApp.java | 93 +++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) delete mode 100644 part-4/E4.java create mode 100644 part-4/Main.java create mode 100644 part-4/RegistrationFormApp.java diff --git a/part-4/E4.java b/part-4/E4.java deleted file mode 100644 index e69de29..0000000 diff --git a/part-4/Main.java b/part-4/Main.java new file mode 100644 index 0000000..730c193 --- /dev/null +++ b/part-4/Main.java @@ -0,0 +1,7 @@ +import javax.swing.*; + +public class Main { + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> new RegistrationFormApp().setVisible(true)); + } +} diff --git a/part-4/RegistrationFormApp.java b/part-4/RegistrationFormApp.java new file mode 100644 index 0000000..4485c8c --- /dev/null +++ b/part-4/RegistrationFormApp.java @@ -0,0 +1,93 @@ +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.*; + + +public class RegistrationFormApp extends JFrame implements ActionListener { + 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); + } + + 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 +} From cd1e0520bf4fb651f9258ce92e3af3036665acc3 Mon Sep 17 00:00:00 2001 From: Shifu2006 Date: Sun, 11 May 2025 03:00:13 +0330 Subject: [PATCH 5/5] the end --- part-1/{ClickcounterApp.java => ClickCounterApp.java} | 1 + part-2/GreetingFormApp.java | 1 + part-3/ThemeColorSelectorApp.java | 1 + 3 files changed, 3 insertions(+) rename part-1/{ClickcounterApp.java => ClickCounterApp.java} (96%) diff --git a/part-1/ClickcounterApp.java b/part-1/ClickCounterApp.java similarity index 96% rename from part-1/ClickcounterApp.java rename to part-1/ClickCounterApp.java index 0f64faf..ee239b8 100644 --- a/part-1/ClickcounterApp.java +++ b/part-1/ClickCounterApp.java @@ -16,6 +16,7 @@ public ClickCounterApp() { add(clickButton, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300, 200); + setLocationRelativeTo(null); } private JLabel counterLabel; // Displays the click count diff --git a/part-2/GreetingFormApp.java b/part-2/GreetingFormApp.java index 4826896..aacc1fc 100644 --- a/part-2/GreetingFormApp.java +++ b/part-2/GreetingFormApp.java @@ -23,6 +23,7 @@ public GreetingFormApp() { add(messageLabel, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(600, 200); + setLocationRelativeTo(null); } @Override diff --git a/part-3/ThemeColorSelectorApp.java b/part-3/ThemeColorSelectorApp.java index 539e790..009c180 100644 --- a/part-3/ThemeColorSelectorApp.java +++ b/part-3/ThemeColorSelectorApp.java @@ -31,6 +31,7 @@ public ThemeColorSelectorApp() { add(mainPanel, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300, 400); + setLocationRelativeTo(null); } @Override