From 0b3f3937819254fbef6ff28485ada26aea75373e Mon Sep 17 00:00:00 2001 From: MH Taherii Date: Thu, 8 May 2025 14:04:50 +0330 Subject: [PATCH 1/4] Ex1 --- part-1/ClickCounter.java | 29 +++++++++++++++++++++++++++++ part-1/E1.java | 0 part-1/Main.java | 7 +++++++ 3 files changed, 36 insertions(+) create mode 100644 part-1/ClickCounter.java delete mode 100644 part-1/E1.java create mode 100644 part-1/Main.java diff --git a/part-1/ClickCounter.java b/part-1/ClickCounter.java new file mode 100644 index 0000000..0512671 --- /dev/null +++ b/part-1/ClickCounter.java @@ -0,0 +1,29 @@ +import javax.swing.*; +import java.awt.*; + +public class ClickCounter { + private int count =0; + private JButton ClickButton; + private JLabel countClick; + public ClickCounter() { + JFrame frame = new JFrame("Click Counter"); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(300,200); + frame.setResizable(false); + frame.setLocationRelativeTo(null); +// frame.setLayout(null); + ClickButton = new JButton("Click"); +// ClickButton.setBounds(0,113,300,50); + countClick = new JLabel("Clicks: "+count,JLabel.CENTER); + ClickButton.addActionListener(e -> { + count++; + countClick.setText("Clicks: "+count); + }); + + frame.add(ClickButton,BorderLayout.SOUTH); + frame.add(countClick,BorderLayout.CENTER); + frame.setVisible(true); + } + +} 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..5e5d9e3 --- /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 ClickCounter()); + } +} From f787b677b91354f2c1c409b3ea8530d6981408a7 Mon Sep 17 00:00:00 2001 From: MH Taherii Date: Thu, 8 May 2025 15:19:00 +0330 Subject: [PATCH 2/4] Ex2 --- part-2/E2.java | 0 part-2/GreetingFormApp.java | 37 +++++++++++++++++++++++++++++++++++++ part-2/Main.java | 7 +++++++ 3 files changed, 44 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..8fe1b6e --- /dev/null +++ b/part-2/GreetingFormApp.java @@ -0,0 +1,37 @@ +import javax.swing.*; +import java.awt.*; + +public class GreetingFormApp { + private JLabel lblGreeting; + private JButton btnGreet; + private final JTextField txtGreeting; + + public GreetingFormApp() { + JFrame frame = new JFrame("Greeting"); + frame.setLayout(new FlowLayout()); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocationRelativeTo(null); + frame.setSize(300, 150); + txtGreeting = new JTextField( 20); + JLabel lblGreeting = new JLabel("welcome to my application", SwingConstants.CENTER); + JButton btnGreet = new JButton("Greet"); + btnGreet.addActionListener(e -> { + String greeting = txtGreeting.getText(); + if ( greeting.isEmpty()) { + JOptionPane.showMessageDialog(null, "please enter your name"); + + } else { + lblGreeting.setText("Hello, " + greeting + "!"); + } + + }); + JPanel panel = new JPanel(); + panel.add(txtGreeting); + panel.add(btnGreet); + frame.add(panel, BorderLayout.NORTH); + frame.add(lblGreeting, BorderLayout.CENTER); + frame.setVisible(true); + + + } +} diff --git a/part-2/Main.java b/part-2/Main.java new file mode 100644 index 0000000..3746419 --- /dev/null +++ b/part-2/Main.java @@ -0,0 +1,7 @@ +import javax.swing.*; + +public class Main { + public static void main(String[] args) { + SwingUtilities.invokeLater ( ()->new GreetingFormApp()); + } +} From ffe1e4970cca1b7ecf0196fce9881b5d5183caf9 Mon Sep 17 00:00:00 2001 From: MH Taherii Date: Sat, 10 May 2025 18:44:32 +0330 Subject: [PATCH 3/4] ex3 --- part-3/E3.java | 0 part-3/ThemeColorSelectorApp.java | 52 +++++++++++++++++++++++++++++++ part-3/ex1.java | 8 +++++ 3 files changed, 60 insertions(+) delete mode 100644 part-3/E3.java create mode 100644 part-3/ThemeColorSelectorApp.java create mode 100644 part-3/ex1.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/ThemeColorSelectorApp.java b/part-3/ThemeColorSelectorApp.java new file mode 100644 index 0000000..d5b4cce --- /dev/null +++ b/part-3/ThemeColorSelectorApp.java @@ -0,0 +1,52 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ThemeColorSelectorApp extends JFrame implements ActionListener { + private JFrame frame; + private JPanel Colorpanel; + private JButton RedButton; + private JButton GreenButton; + private JButton BlueButton; + + public ThemeColorSelectorApp(){ + frame = new JFrame("ThemeColorSelectorApp"); + setLayout(new BorderLayout()); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(400,400); + Colorpanel = new JPanel(); + RedButton = new JButton("Red"); + GreenButton = new JButton("Green"); + BlueButton = new JButton("Blue"); + JPanel buttonPanel = new JPanel(); + RedButton.setActionCommand("Red"); + GreenButton.setActionCommand("Green"); + BlueButton.setActionCommand("Blue"); + RedButton.addActionListener(this); + GreenButton.addActionListener(this); + buttonPanel.add(RedButton); + buttonPanel.add(BlueButton); + buttonPanel.add(GreenButton); + BlueButton.addActionListener(this); + frame.add(Colorpanel,BorderLayout.CENTER); + frame.add(buttonPanel,BorderLayout.NORTH); + + + + frame.setVisible(true); + } + + + @Override + public void actionPerformed(ActionEvent e) { + switch (e.getActionCommand()){ + case "Red": Colorpanel.setBackground(Color.RED); + break; + case "Green": Colorpanel.setBackground(Color.GREEN); + break; + case "Blue": Colorpanel.setBackground(Color.BLUE); + break; + } + } +} diff --git a/part-3/ex1.java b/part-3/ex1.java new file mode 100644 index 0000000..0661b7f --- /dev/null +++ b/part-3/ex1.java @@ -0,0 +1,8 @@ +import javax.swing.*; + +public class ex1 { + + public static void main(String[] args) { + SwingUtilities.invokeLater(()-> new ThemeColorSelectorApp()); + } +} From 5be67c4c5d4664cfb507fc1e4b5a2007c493f912 Mon Sep 17 00:00:00 2001 From: MH Taherii Date: Sat, 10 May 2025 22:28:22 +0330 Subject: [PATCH 4/4] ex4 --- part-4/E4.java | 0 part-4/Main.java | 7 +++ part-4/RegistrationFormApp.java | 106 ++++++++++++++++++++++++++++++++ 3 files changed, 113 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..34ea4a9 --- /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() ); + } +} diff --git a/part-4/RegistrationFormApp.java b/part-4/RegistrationFormApp.java new file mode 100644 index 0000000..64a99d5 --- /dev/null +++ b/part-4/RegistrationFormApp.java @@ -0,0 +1,106 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.*; +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("Registration Form"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + setSize(300, 300); + 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; + gbc.gridy = 0; + txtName = new JTextField(20); + panel.add(txtName, gbc); + gbc.gridx = 0; + gbc.gridy = 1; + panel.add(new JLabel("Email:"), gbc); + gbc.gridx = 1; + gbc.gridy = 1; + txtEmail = new JTextField(30); + panel.add(txtEmail, gbc); + gbc.gridx = 0; + gbc.gridy = 2; + panel.add(new JLabel("Password:"), gbc); + gbc.gridx = 1; + gbc.gridy = 2; + txtPassword = new JPasswordField(20); + panel.add(txtPassword, gbc); + gbc.gridx = 0; + gbc.gridy = 3; + panel.add(new JLabel("Gender:"), gbc); + gbc.gridx = 1; + gbc.gridy = 3; + RbMale = new JRadioButton("Male"); + RbFemale = new JRadioButton("Female"); + ButtonGroup buttonGroup = new ButtonGroup(); + buttonGroup.add(RbMale); + buttonGroup.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 Label("Interests: "), gbc); + gbc.gridx = 1; + gbc.gridy = 4; + 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, BorderLayout.CENTER); + setVisible(true); + } + @Override + public void actionPerformed(ActionEvent e) { + String name = txtName.getText(); + String email = txtEmail.getText(); + String Gender = RbMale.isSelected() ? "Male" : "Female"; + String interests = setInterests(); + JOptionPane.showMessageDialog(this, "Name: " + name + "\n" + + "Email: " + email + "\n" + + "Gender: " + Gender + "\n" + + "Interests: " + interests, "Registration Form", JOptionPane.INFORMATION_MESSAGE); + + + } + public String setInterests() { + String result = ""; + if (cbJava.isSelected()) { + result += "Java "; + } + if (cbPython.isSelected()) { + result += "Python "; + } + if (cbCpp.isSelected()) { + result += "C++ "; + } + return result; + } +}