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