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
40 changes: 40 additions & 0 deletions part-1/E1.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
44 changes: 44 additions & 0 deletions part-2/E2.java
Original file line number Diff line number Diff line change
@@ -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);

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