week_8java
week_8java
*;
import java.awt.*;
import java.awt.event.*;
public QuizForm() {
frame = new JFrame("Quiz Form");
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(option1Radio);
panel.add(option2Radio);
panel.add(option3Radio);
panel.add(checkBox1);
panel.add(checkBox2);
panel.add(checkBox3);
// Submit button
submitButton = new JButton("Submit");
submitButton.addActionListener(new SubmitButtonListener());
panel.add(submitButton);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
output:
2.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
output:
3.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public GoogleAccountRegistration() {
super("Create Google Account");
setSize(400, 450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(10, 2));
setLocationRelativeTo(null);
// Buttons
createAccountButton = new JButton("Create Account");
createAccountButton.addActionListener(this);
resetButton = new JButton("Reset");
resetButton.addActionListener(this);
cancelButton = new JButton(" Cancel");
cancelButton.addActionListener(this);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == createAccountButton) {
// Validate input fields
if (validateFields()) {
// Create account logic here
JOptionPane.showMessageDialog(this, "Account created
successfully!");
}
} else if (e.getSource() == resetButton) {
// Reset fields
resetFields();
} else if (e.getSource() == cancelButton) {
// Close the window
dispose();
}
}
// Validate username
if (usernameField.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(this, "Username is required!");
return false;
}
// Validate password
if (passwordField.getPassword().length == 0) {
JOptionPane.showMessageDialog(this, "Password is required!");
return false;
}
// Validate birthdate
if (dayField.getText().trim().isEmpty() ||
yearField.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(this, "Birthdate is required!");
return false;
}
// Validate gender
if (genderField.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(this, "Gender is required!");
return false;
}
return true;
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public QuizForm() {
frame = new JFrame("Quiz Form");
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(option1Radio);
panel.add(option2Radio);
panel.add(option3Radio);
panel.add(option4Radio);
panel.add(checkBox1);
panel.add(checkBox2);
panel.add(checkBox3);
panel.add(checkBox4);
panel.add(checkBox5);
// Question 3: Text field
JLabel question3Label = new JLabel("What is the name of the famous
French painter?");
panel.add(question3Label);
// Submit button
submitButton = new JButton("Submit");
submitButton.addActionListener(new SubmitButtonListener());
panel.add(submitButton);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}