From 4ce527317aff978d1709f0497f66f04aa48f55d3 Mon Sep 17 00:00:00 2001 From: mahdinazariii Date: Fri, 16 May 2025 16:44:51 +0330 Subject: [PATCH 1/7] Add files via upload --- Main.java | 15 +++++++++++++++ MyFrame.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Main.java create mode 100644 MyFrame.java diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..f171717 --- /dev/null +++ b/Main.java @@ -0,0 +1,15 @@ +package org.example; + +import java.awt.event.ActionEvent; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + new MyFrame(); + + } + + + } + diff --git a/MyFrame.java b/MyFrame.java new file mode 100644 index 0000000..39a9d08 --- /dev/null +++ b/MyFrame.java @@ -0,0 +1,51 @@ +package org.example; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class MyFrame extends JFrame { + private JButton button; + private JLabel label; + private int count = 0; + + +//f + public MyFrame() { + this.setLayout(new BorderLayout()); + this.setTitle("Click Counter"); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setSize(400,150 ); + this.setResizable(false); + this.setLocationRelativeTo(null); + label = new JLabel(); + this.label.setText("Clicks = 0 " ); + this.label.setHorizontalAlignment(SwingConstants.CENTER); + this.label.setForeground(new Color(190,70,45)); + this.add(label); + button = new JButton("Click Me"); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + count++; + label.setText("Clicks = " + count); + } + }) + + ; + this.add(button, BorderLayout.SOUTH); + this.add(label, BorderLayout.CENTER); + this.setVisible(true); + + + + + + } + public void clickCounter() { + count++; + label.setText("Clicks = " + count); + } + +} From 06c26abdd77d6dcbbec3c57179dc58c7137ff4a2 Mon Sep 17 00:00:00 2001 From: mahdinazariii Date: Fri, 16 May 2025 16:45:16 +0330 Subject: [PATCH 2/7] Add files via upload --- part-1/Main.java | 15 +++++++++++++ part-1/MyFrame.java | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 part-1/Main.java create mode 100644 part-1/MyFrame.java diff --git a/part-1/Main.java b/part-1/Main.java new file mode 100644 index 0000000..f171717 --- /dev/null +++ b/part-1/Main.java @@ -0,0 +1,15 @@ +package org.example; + +import java.awt.event.ActionEvent; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + new MyFrame(); + + } + + + } + diff --git a/part-1/MyFrame.java b/part-1/MyFrame.java new file mode 100644 index 0000000..39a9d08 --- /dev/null +++ b/part-1/MyFrame.java @@ -0,0 +1,51 @@ +package org.example; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class MyFrame extends JFrame { + private JButton button; + private JLabel label; + private int count = 0; + + +//f + public MyFrame() { + this.setLayout(new BorderLayout()); + this.setTitle("Click Counter"); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setSize(400,150 ); + this.setResizable(false); + this.setLocationRelativeTo(null); + label = new JLabel(); + this.label.setText("Clicks = 0 " ); + this.label.setHorizontalAlignment(SwingConstants.CENTER); + this.label.setForeground(new Color(190,70,45)); + this.add(label); + button = new JButton("Click Me"); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + count++; + label.setText("Clicks = " + count); + } + }) + + ; + this.add(button, BorderLayout.SOUTH); + this.add(label, BorderLayout.CENTER); + this.setVisible(true); + + + + + + } + public void clickCounter() { + count++; + label.setText("Clicks = " + count); + } + +} From c19670a4d2c6d95cd50292967c78ca80a8c178dc Mon Sep 17 00:00:00 2001 From: mahdinazariii Date: Fri, 16 May 2025 16:45:36 +0330 Subject: [PATCH 3/7] Add files via upload --- part-2/Main.java | 5 +++++ part-2/MyFrame.java | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 part-2/Main.java create mode 100644 part-2/MyFrame.java diff --git a/part-2/Main.java b/part-2/Main.java new file mode 100644 index 0000000..2ed8a06 --- /dev/null +++ b/part-2/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + new MyFrame(); + } +} diff --git a/part-2/MyFrame.java b/part-2/MyFrame.java new file mode 100644 index 0000000..49edf2c --- /dev/null +++ b/part-2/MyFrame.java @@ -0,0 +1,40 @@ +import javax.swing.*; +import java.awt.*; + +public class MyFrame extends JFrame { + private JLabel label; + private JButton button; + private JTextField textField; + private JPanel panel; + public MyFrame(){ + this.setTitle("Greeting Form"); + this.setSize(350,150); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setResizable(false); + this.setLocationRelativeTo(null); + this.label = new JLabel("Enter your name and press greet", SwingConstants.CENTER); + this.button = new JButton("Greet"); + this.panel = new JPanel(); + this.textField = new JTextField(15); + panel.add(button); + panel.add(textField); + setLayout(new BorderLayout()); + add(label, BorderLayout.CENTER); + add(panel, BorderLayout.NORTH); + button.addActionListener(e -> { + String name = textField.getText(); + if (!name.isEmpty()) { + label.setText("Hello " + name + "!"); + + + }else{ + label.setText("please enter your name"); + } + }); + + + +this.setVisible(true); + } + +} From 152edd85d271e5fb41cf56ba26baa0f1ed7f0767 Mon Sep 17 00:00:00 2001 From: mahdinazariii Date: Fri, 16 May 2025 16:45:54 +0330 Subject: [PATCH 4/7] Add files via upload --- part-3/Main.java | 5 +++++ part-3/Myframe.java | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 part-3/Main.java create mode 100644 part-3/Myframe.java diff --git a/part-3/Main.java b/part-3/Main.java new file mode 100644 index 0000000..af084ad --- /dev/null +++ b/part-3/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + new Myframe().setVisible(true); + } +} diff --git a/part-3/Myframe.java b/part-3/Myframe.java new file mode 100644 index 0000000..9ab0fc4 --- /dev/null +++ b/part-3/Myframe.java @@ -0,0 +1,48 @@ +import javax.swing.*; +import java.awt.*; + +public class Myframe extends JFrame { + private JPanel panel; + private JButton redButton; + private JButton blueButton; + private JButton greenButton; + public Myframe() { + panel = new JPanel(); + this.setTitle("Theme color selector "); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setSize(400, 250); + this.setResizable(false); + this.setLocationRelativeTo(null); + JPanel buttonPanel = new JPanel(); + redButton = new JButton("Red"); + blueButton = new JButton("Blue"); + greenButton = new JButton("Green"); + redButton.setActionCommand("Red"); + blueButton.setActionCommand("Blue"); + greenButton.setActionCommand("Green"); + greenButton.addActionListener(e -> { + if(greenButton.getText().equals("Green")) { + panel.setBackground(Color.GREEN); + } + }); + blueButton.addActionListener(e -> { + if(blueButton.getText().equals("Blue")) { + panel.setBackground(Color.BLUE); + } + }); + redButton.addActionListener(e -> { + if(redButton.getText().equals("Red")) { + panel.setBackground(Color.RED); + } + }); + + + buttonPanel.add(redButton); + buttonPanel.add(blueButton); + buttonPanel.add(greenButton); + setLayout(new BorderLayout()); + add(buttonPanel, BorderLayout.NORTH); + add(panel, BorderLayout.CENTER); + + } +} From 1eb2e2bc37441ad81899c602189917f515911727 Mon Sep 17 00:00:00 2001 From: mahdinazariii Date: Fri, 16 May 2025 16:46:12 +0330 Subject: [PATCH 5/7] Add files via upload --- part-4/Main.java | 8 +++ part-4/RegistrationFormApp.java | 111 ++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 part-4/Main.java create mode 100644 part-4/RegistrationFormApp.java diff --git a/part-4/Main.java b/part-4/Main.java new file mode 100644 index 0000000..d51d737 --- /dev/null +++ b/part-4/Main.java @@ -0,0 +1,8 @@ +import javax.swing.*; + +public class Main { + public static void main(String[] args) { + new RegistrationFormApp().setVisible(true); + + } +} diff --git a/part-4/RegistrationFormApp.java b/part-4/RegistrationFormApp.java new file mode 100644 index 0000000..9c797a2 --- /dev/null +++ b/part-4/RegistrationFormApp.java @@ -0,0 +1,111 @@ +import javax.swing.*; +import java.awt.*; + + +public class RegistrationFormApp extends javax.swing.JFrame { + private TextField name; + private TextField email; + private JPasswordField password; + private JRadioButton female,male,rather; + private JCheckBox python,cpp,java; + private JButton submit; + private GridBagConstraints gbc; + + public RegistrationFormApp() { + this.setTitle("User Registration"); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setLocationRelativeTo(null); + this.setResizable(false); + this.setSize(500,350); + + + + JPanel panel = new JPanel(); + panel.setLayout(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; name = new TextField(20); + panel.add(name,gbc); + + gbc.gridx = 0; gbc.gridy = 1; + panel.add(new JLabel("Email :") , gbc); + gbc.gridx = 1 ; email = new TextField(20); + panel.add(email,gbc); + + gbc.gridx = 0; gbc.gridy = 2; + panel.add(new JLabel("Password : "),gbc); + gbc.gridx = 1 ; password = new JPasswordField(20); + panel.add(password,gbc); + + gbc.gridx = 0; gbc.gridy = 3; + panel.add(new JLabel("Gender :"),gbc); + gbc.gridx = 1 ; + male = new JRadioButton("Male"); + female = new JRadioButton("Female"); + rather = new JRadioButton("Rather not to say "); + ButtonGroup group = new ButtonGroup(); + group.add(male); + group.add(female); + group.add(rather); + JPanel genderPanel = new JPanel(); genderPanel.add(male); genderPanel.add(female); genderPanel.add(rather); + panel.add(genderPanel,gbc); + + + + gbc.gridx = 0; gbc.gridy = 4; + panel.add(new JLabel("Interests :"),gbc); + gbc.gridx = 1 ; + JPanel buttonPanel = new JPanel(); + java = new JCheckBox("Java"); python = new JCheckBox("Python"); cpp = new JCheckBox("CPP"); + buttonPanel.add(python); + buttonPanel.add(cpp); + buttonPanel.add(java); + panel.add(buttonPanel,gbc); + + + gbc.gridx = 1; gbc.gridy = 5; + + gbc.anchor = GridBagConstraints.CENTER; + submit = new JButton("Submit"); + panel.add(submit,gbc); + submit.addActionListener(e -> { + StringBuilder message = new StringBuilder(); + message.append("Name: " + name.getText() + "\n"); + message.append("Email: " + email.getText() + "\n"); + message.append("Password: " + password.getText() + "\n"); + message.append("Gender: "); + if(female.isSelected()) + message.append("Female"); + else if(male.isSelected()) + message.append("Male"); + else message.append("Rather"); + message.append("\n"); + message.append("Interests: "); + if(java.isSelected()) + message.append("Java"); + else if (python.isSelected()) + message.append("Python"); + else message.append("CPP"); + message.append("\n"); + + + JOptionPane.showMessageDialog(null, message.toString()); + }); + + + + + + + + +add(panel); + + + } + +} From b02ba4c2e7b6d0c97c0d94835be4d3b65bcadf5c Mon Sep 17 00:00:00 2001 From: mahdinazariii Date: Fri, 16 May 2025 16:46:41 +0330 Subject: [PATCH 6/7] Delete Main.java --- Main.java | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Main.java diff --git a/Main.java b/Main.java deleted file mode 100644 index f171717..0000000 --- a/Main.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.example; - -import java.awt.event.ActionEvent; - -//TIP To Run code, press or -// click the icon in the gutter. -public class Main { - public static void main(String[] args) { - new MyFrame(); - - } - - - } - From 613fe1bfbd877668d11e1dab436d3480b94c2796 Mon Sep 17 00:00:00 2001 From: mahdinazariii Date: Fri, 16 May 2025 16:46:49 +0330 Subject: [PATCH 7/7] Delete MyFrame.java --- MyFrame.java | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 MyFrame.java diff --git a/MyFrame.java b/MyFrame.java deleted file mode 100644 index 39a9d08..0000000 --- a/MyFrame.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.example; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -public class MyFrame extends JFrame { - private JButton button; - private JLabel label; - private int count = 0; - - -//f - public MyFrame() { - this.setLayout(new BorderLayout()); - this.setTitle("Click Counter"); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - this.setSize(400,150 ); - this.setResizable(false); - this.setLocationRelativeTo(null); - label = new JLabel(); - this.label.setText("Clicks = 0 " ); - this.label.setHorizontalAlignment(SwingConstants.CENTER); - this.label.setForeground(new Color(190,70,45)); - this.add(label); - button = new JButton("Click Me"); - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - count++; - label.setText("Clicks = " + count); - } - }) - - ; - this.add(button, BorderLayout.SOUTH); - this.add(label, BorderLayout.CENTER); - this.setVisible(true); - - - - - - } - public void clickCounter() { - count++; - label.setText("Clicks = " + count); - } - -}