Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions part-1/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.example;

import java.awt.event.ActionEvent;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
new MyFrame();

}


}

51 changes: 51 additions & 0 deletions part-1/MyFrame.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
5 changes: 5 additions & 0 deletions part-2/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
new MyFrame();
}
}
40 changes: 40 additions & 0 deletions part-2/MyFrame.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
5 changes: 5 additions & 0 deletions part-3/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
new Myframe().setVisible(true);
}
}
48 changes: 48 additions & 0 deletions part-3/Myframe.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
8 changes: 8 additions & 0 deletions part-4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import javax.swing.*;

public class Main {
public static void main(String[] args) {
new RegistrationFormApp().setVisible(true);

}
}
111 changes: 111 additions & 0 deletions part-4/RegistrationFormApp.java
Original file line number Diff line number Diff line change
@@ -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);


}

}