JAVA Swings
JAVA Swings
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public MathTest() {
frame = new JFrame("ProgressBar");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1000, 500);
frame.add(panel);
frame.setVisible(true);
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.regex.Pattern;
public TestPage() {
frame = new JFrame("Math Test Application");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(0, 2, 10, 10));
frame.setPreferredSize(new Dimension(800, 800)); // Increased
the window size
// Create components
nameField = new JTextField();
phoneField = new JTextField();
aboutYouTextArea = new JTextArea(10, 20);
JScrollPane aboutYouScrollPane = new
JScrollPane(aboutYouTextArea);
ageSlider = new JSlider(18, 30);
ageLabel = new JLabel("Age: " + ageSlider.getValue());
hobbiesCheckboxes = new JCheckBox[hobbies.length];
// Add Question 1
frame.add(new JLabel("Q1. What is the value of Pi?"));
frame.add(q1TextField);
// Add Question 2
frame.add(new JLabel("Q2. The perimeter of a cube is:"));
frame.add(q2Option1RadioButton);
frame.add(new JLabel(""));
frame.add(q2Option2RadioButton);
// Add Question 3
frame.add(new JLabel("Q3. How many lines can be drawn through
two points?"));
frame.add(q3ComboBox);
// Add Question 4
frame.add(new JLabel("Q4. A triangle with two sides equal is
known as:"));
frame.add(q4Option1CheckBox);
frame.add(new JLabel(""));
frame.add(q4Option2CheckBox);
frame.add(new JLabel(""));
frame.add(q4Option3CheckBox);
// Add Question 5
frame.add(new JLabel("Q5. How many digits are in 1000?"));
JPanel q5OptionsPanel = new JPanel();
q5OptionsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
q5Option2Button = new JButton("2");
q5Option4Button = new JButton("4");
q5Option3Button = new JButton("3");
q5OptionsPanel.add(q5Option2Button);
q5OptionsPanel.add(q5Option4Button);
q5OptionsPanel.add(q5Option3Button);
frame.add(q5OptionsPanel);
if (!Pattern.matches("\\d{1,10}", phone)) {
JOptionPane.showMessageDialog(frame, "Invalid phone number.
Only numbers not exceeding 10 digits allowed.");
return false;
}
userCongruent = q4Option3CheckBox.isSelected();
// Calculate the score
score = 0;
if (userPiValue.equals(correctPiValue)) {
score++;
}
if (userCubePerimeter.equals(correctCubePerimeter)) {
score++;
}
if (userLines.equals(correctLines)) {
score++;
}