From 19e3d3eb3d43cd3b17b78f5d73b10f29fc217ce2 Mon Sep 17 00:00:00 2001 From: mahanfattahi Date: Fri, 16 May 2025 11:31:09 +0430 Subject: [PATCH] pase 1 graphic --- part-1/E1.java | 40 ++++++++++++++++++ part-2/E2.java | 44 ++++++++++++++++++++ part-3/E3.java | 53 ++++++++++++++++++++++++ part-4/E4.java | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 246 insertions(+) diff --git a/part-1/E1.java b/part-1/E1.java index e69de29..a6cd7fe 100644 --- a/part-1/E1.java +++ b/part-1/E1.java @@ -0,0 +1,40 @@ +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +public class Q1graphic extends Frame implements ActionListener { + + Button button; + Label label; + int count ; + + public Q1graphic() { + button = new Button("Click "); + button.addActionListener(this); + add(button); + + label = new Label("Clicks = " + count); + add(label); + + setSize(300 , 300); + setLayout(new FlowLayout()); + setVisible(true); + + addWindowListener( new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + + } + @Override + public void actionPerformed(ActionEvent e) { + count++; + label.setText("Clicks = "+ count); + } + public static void main(String[] args) { + new Q1graphic(); + } +} \ No newline at end of file diff --git a/part-2/E2.java b/part-2/E2.java index e69de29..9b2271b 100644 --- a/part-2/E2.java +++ b/part-2/E2.java @@ -0,0 +1,44 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class Q2graphic { + + public static void main(String[] args) { + + JFrame frame = new JFrame("Greeting App"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize( 300, 200); + frame.setLayout(null); + + JLabel label = new JLabel("Please Enter Your Name : "); + label.setBounds(50, 20, 200, 30); + frame.add(label); + + JTextField textfield = new JTextField(); + textfield.setBounds(50, 60, 200, 30); + frame.add(textfield); + + JButton button = new JButton("Greet"); + button.setBounds(50, 100, 200, 30); + frame.add(button); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String name = textfield.getText(); + if(name.isEmpty()) { + JOptionPane.showMessageDialog(frame, "Please Enter Your Name"); + } + else { + JOptionPane.showMessageDialog(frame, "Hello " + name + "!"); + JOptionPane.showMessageDialog(frame, "How Are You ? " + name ); + } + + } + }); + + frame.setVisible(true); + + } +} diff --git a/part-3/E3.java b/part-3/E3.java index e69de29..c547930 100644 --- a/part-3/E3.java +++ b/part-3/E3.java @@ -0,0 +1,53 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class Q3graphic { + + public static void main(String[] args) { + + JFrame frame = new JFrame("ColorChanger"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(300, 300); + frame.setLayout(null); + + JButton redButton = new JButton("RED"); + redButton.setBounds(20, 40, 100, 30); + frame.add(redButton); + + JButton greenButton = new JButton("GREEN"); + greenButton.setBounds(120, 40, 100, 30); + frame.add(greenButton); + + JButton blueButton = new JButton("BLUE"); + blueButton.setBounds(220, 40, 100, 30); + frame.add(blueButton); + + redButton.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + + frame.getContentPane().setBackground(Color.RED); + } + }); + + greenButton.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + + frame.getContentPane().setBackground(Color.GREEN); + } + }); + + blueButton.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e){ + + frame.getContentPane().setBackground(Color.BLUE); + } + }); + + frame.setVisible(true); + } +} diff --git a/part-4/E4.java b/part-4/E4.java index e69de29..5933d17 100644 --- a/part-4/E4.java +++ b/part-4/E4.java @@ -0,0 +1,109 @@ + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class Q4graphic { + + public static void main(String[] args) { + + JFrame frame = new JFrame("User Registration"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(500, 500); + frame.setLayout(null); + + JLabel username = new JLabel("USERNAME : "); + username.setBounds(10, 10, 100, 20); + frame.add(username); + + JTextField usernameField = new JTextField(); + usernameField.setBounds(100, 10, 200, 20); + frame.add(usernameField); + + JLabel email = new JLabel("EMAIL : "); + email.setBounds(10, 50, 100, 20); + frame.add(email); + + JTextField emailField = new JTextField(); + emailField.setBounds(100, 50, 200, 20); + frame.add(emailField); + + JLabel password = new JLabel("PASSWORD : "); + password.setBounds(10, 90, 100, 20); + frame.add(password); + + JPasswordField passwordField = new JPasswordField(); + passwordField.setBounds(100, 90, 200, 20); + frame.add(passwordField); + + JLabel gender = new JLabel("GENDER : "); + gender.setBounds(10, 130, 100, 20); + frame.add(gender); + + JRadioButton rbMALE = new JRadioButton("MALE"); + rbMALE.setBounds(100, 130, 100, 20); + frame.add(rbMALE); + + JRadioButton rbFEMALE = new JRadioButton("FEMALE"); + rbFEMALE.setBounds(200, 130, 100, 20); + frame.add(rbFEMALE); + + // Create a ButtonGroup to group the radio buttons + ButtonGroup genderGroup = new ButtonGroup(); + genderGroup.add(rbMALE); + genderGroup.add(rbFEMALE); + + JLabel interest = new JLabel("INTEREST IN : "); + interest.setBounds(10, 170, 100, 20); + frame.add(interest); + + JCheckBox java = new JCheckBox("JAVA"); + java.setBounds(100, 170, 100, 20); + frame.add(java); + + JCheckBox python = new JCheckBox("PYTHON"); + python.setBounds(200, 170, 110, 20); + frame.add(python); + + JCheckBox cPP = new JCheckBox("C++"); + cPP.setBounds(300, 170, 100, 20); + frame.add(cPP); + + JButton button = new JButton("SUBMIT"); + button.setBounds(100, 210, 100, 30); + frame.add(button); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String username = usernameField.getText(); + String email = emailField.getText(); + String password = new String(passwordField.getPassword()); + StringBuilder selectedOptions = new StringBuilder("INTERESTS : "); + if (java.isSelected()) { + selectedOptions.append("JAVA"); + } + if (python.isSelected()) { + selectedOptions.append("PYTHON"); + } + if (cPP.isSelected()) { + selectedOptions.append("C++"); + } + + if (username.isEmpty() || email.isEmpty() || password.isEmpty()) { + JOptionPane.showMessageDialog(frame, "Please Fill All Fields"); + } else { + String selectedGender = rbMALE.isSelected() ? "MALE" : (rbFEMALE.isSelected() ? "FEMALE" : "Not Specified"); + JOptionPane.showMessageDialog(frame, + "USERNAME : " + username + '\n' + + "EMAIL : " + email + '\n' + + "PASSWORD : " + password + '\n' + + "GENDER : " + selectedGender + '\n' + + "INTERESTS : " + selectedOptions ); + } + } + }); + + frame.setVisible(true); + } +}