import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class FinalProject extends JFrame implements ActionListener{
private String FirstName = "Jaypee";
private String LastName = "Pogi";
private JFrame jay = new JFrame();
private JLabel x = new JLabel("Username");
private JTextField jay1 = new JTextField(10);
private JLabel x1 = new JLabel("Password");
private JPasswordField jay2 = new JPasswordField(10);
private JButton jp = new JButton("Login");
private JButton jp1 = new JButton("Cancel");
private JPanel panel = new JPanel();
private Container con = getContentPane();
private JPanel jhay1 = new JPanel();
private JLabel Lq1 = new JLabel("1.10 x 20 = ?");
private JRadioButton x1a = new JRadioButton("A - 200");
private JRadioButton x2b = new JRadioButton("B - 300");
private JRadioButton x3c = new JRadioButton("C - 400");
private JRadioButton x4d = new JRadioButton("D - 500");
private JButton jhayp1 = new JButton("NEXT");
private JPanel jhay2 = new JPanel();
private JLabel Lq2 = new JLabel("2.What is the largest animal ever to live on Earth? ");
private JRadioButton x5a = new JRadioButton("A- giraffe");
private JRadioButton x6b = new JRadioButton("B- shark");
private JRadioButton x7c = new JRadioButton("C- blue whale");
private JRadioButton x8d = new JRadioButton("D- elepant");
private JButton jhayp11 = new JButton("BACK");
private JButton jhayp2 = new JButton("NEXT");
private JPanel jhay3 = new JPanel();
private JLabel Lq3 = new JLabel("3.Which of these animals shares its name with a luxury car?");
private JRadioButton x9a = new JRadioButton("A - leopard");
private JRadioButton x10b = new JRadioButton("B - jaguar ");
private JRadioButton x11c = new JRadioButton("C - lion");
private JRadioButton x12d = new JRadioButton("D - dog");
private JButton jhayp12 = new JButton("BACK");
private JButton btn3 = new JButton("NEXT");
private JPanel jhay4 = new JPanel();
private JLabel Lq4 = new JLabel("4.18 x 0 = ?");
private JRadioButton x13a = new JRadioButton("A - 18");
private JRadioButton x14b = new JRadioButton("B - 1");
private JRadioButton x15c = new JRadioButton("C - 0");
private JRadioButton x16d = new JRadioButton("D - 5");
private JButton jhayp13 = new JButton("BACK");
private JButton btn4 = new JButton("NEXT");
private JPanel jhay5 = new JPanel();
private JLabel Lq5 = new JLabel("5.How many eyes does a giraffe have? ");
private JRadioButton x17a = new JRadioButton("A - four");
private JRadioButton x18b = new JRadioButton("B - three");
private JRadioButton x19c = new JRadioButton("C - two");
private JRadioButton x20d = new JRadioButton("D - one");
private JButton jhayp14 = new JButton("BACK");
private JButton btn5 = new JButton("NEXT");
private JPanel jhay6 = new JPanel();
private JLabel Lq6 = new JLabel("6.What animal represents the year 2000 on the Chinese Calendar?");
private JRadioButton x21a = new JRadioButton("A - sheep");
private JRadioButton x22b = new JRadioButton("B - dragon");
private JRadioButton x23c = new JRadioButton("C- rat");
private JRadioButton x24d = new JRadioButton("D - dog");
private JButton jhayp15 = new JButton("BACK");
private JButton btn6 = new JButton("NEXT");
private JPanel jhay7 = new JPanel();
private JLabel Lq7 = new JLabel("7.What kind of animal is a peregrine?");
private JRadioButton x25a = new JRadioButton("A - fish");
private JRadioButton x26b = new JRadioButton("B - dog");
private JRadioButton x27c = new JRadioButton("C- bird");
private JRadioButton x28d = new JRadioButton("D - snake");
private JButton jhayp16 = new JButton("BACK");
private JButton btn7 = new JButton("NEXT");
private JPanel jhay8 = new JPanel();
private JLabel Lq8 = new JLabel("8. What does an animal produce when it lactates?");
private JRadioButton x29a = new JRadioButton("A - cheese");
private JRadioButton x30b = new JRadioButton("B - milk");
private JRadioButton x31c = new JRadioButton("C- juice");
private JRadioButton x32d = new JRadioButton("D - fruits");
private JButton jhayp17 = new JButton("BACK");
private JButton btn8 = new JButton("NEXT");
private JPanel jhay9 = new JPanel();
private JLabel Lq9 = new JLabel("9.Whats is he best bird in the word ? ");
private JRadioButton x33a = new JRadioButton("A - Chicken");
private JRadioButton x34b = new JRadioButton("B - Ostrich");
private JRadioButton x35c = new JRadioButton("C - Love bird");
private JRadioButton x36d = new JRadioButton("D - Eagle");
private JButton jhayp18 = new JButton("BACK");
private JButton btn9 = new JButton("NEXT");
private JPanel jhay10 = new JPanel();
private JLabel Lq0 = new JLabel("10.In baseball, how many ball make a walk?");
private JRadioButton x37a = new JRadioButton("A - one");
private JRadioButton x38b = new JRadioButton("B - two");
private JRadioButton x39c = new JRadioButton("C - three");
private JRadioButton x40d = new JRadioButton("D - four");
private JButton jhayp19 = new JButton("BACK");
private JButton btn0 = new JButton("RESULT");
private Color color=new Color(12,203,21);
public static void main(String[] args) {
FinalProject FP = new FinalProject();
}
public FinalProject() {
jay.setBounds(500,100,300,150);
jay.setLayout(new FlowLayout());
jay.setSize(350,150);
jay.setVisible(true);
jay.setTitle("FinalsProject");
jay.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.setSize(550,300);
panel.setLayout(new GridLayout(3,6));
panel.add(x);
panel.add(jay1);
panel.add(x1);
panel.add(jay2);
panel.add(jp);
panel.add(jp1);
ButtonGroup x2 = new ButtonGroup();
jhay1.setVisible(false);
jhay1.setLayout(new GridLayout(8,3));
jhay1.add(Lq1);
jhay1.add(x1a);
jhay1.add(x2b);
jhay1.add(x3c);
jhay1.add(x4d);
jhayp1.setBackground(color);
jhay1.add(jhayp1);
ButtonGroup x3 = new ButtonGroup();
jhay2.setVisible(false);
jhay2.setLayout(new GridLayout(8,3));
jhay2.add(Lq2);
jhay2.add(x5a);
jhay2.add(x6b);
jhay2.add(x7c);
jhay2.add(x8d);
jhayp2.setBackground(color);
jhayp11.setBackground(color);
jhay2.add(jhayp11);
jhay2.add(jhayp2);
ButtonGroup x4 = new ButtonGroup();
jhay3.setVisible(false);
jhay3.setLayout(new GridLayout(8,3));
jhay3.add(Lq3);
jhay3.add(x9a);
jhay3.add(x10b);
jhay3.add(x11c);
jhay3.add(x12d);
btn3.setBackground(color);
jhayp12.setBackground(color);
jhay3.add(jhayp12);
jhay3.add(btn3);
ButtonGroup x5 = new ButtonGroup();
jhay4.setVisible(false);
jhay4.setLayout(new GridLayout(8,3));
jhay4.add(Lq4);
jhay4.add(x13a);
jhay4.add(x14b);
jhay4.add(x15c);
jhay4.add(x16d);
btn4.setBackground(color);
jhayp13.setBackground(color);
jhay4.add(jhayp13);
jhay4.add(btn4);
ButtonGroup x6 = new ButtonGroup();
jhay5.setVisible(false);
jhay5.setLayout(new GridLayout(8,3));
jhay5.add(Lq5);
jhay5.add(x17a);
jhay5.add(x18b);
jhay5.add(x19c);
jhay5.add(x20d);
btn5.setBackground(color);
jhayp14.setBackground(color);
jhay5.add(jhayp14);
jhay5.add(btn5);
ButtonGroup x7 = new ButtonGroup();
jhay6.setVisible(false);
jhay6.setLayout(new GridLayout(8,3));
jhay6.add(Lq6);
jhay6.add(x21a);
jhay6.add(x22b);
jhay6.add(x23c);
jhay6.add(x24d);
btn6.setBackground(color);
jhayp15.setBackground(color);
jhay6.add(jhayp15);
jhay6.add(btn6);
ButtonGroup x8 = new ButtonGroup();
jhay7.setVisible(false);
jhay7.setLayout(new GridLayout(8,3));
jhay7.add(Lq7);
jhay7.add(x25a);
jhay7.add(x26b);
jhay7.add(x27c);
jhay7.add(x28d);
btn7.setBackground(color);
jhayp16.setBackground(color);
jhay7.add(jhayp16);
jhay7.add(btn7);
ButtonGroup x9 = new ButtonGroup();
jhay8.setVisible(false);
jhay8.setLayout(new GridLayout(8,3));
jhay8.add(Lq8);
jhay8.add(x29a);
jhay8.add(x30b);
jhay8.add(x31c);
jhay8.add(x32d);
btn8.setBackground(color);
jhayp17.setBackground(color);
jhay8.add(jhayp17);
jhay8.add(btn8);
ButtonGroup x10 = new ButtonGroup();
jhay9.setVisible(false);
jhay9.setLayout(new GridLayout(8,3));
jhay9.add(Lq9);
jhay9.add(x33a);
jhay9.add(x34b);
jhay9.add(x35c);
jhay9.add(x36d);
btn9.setBackground(color);
jhayp18.setBackground(color);
jhay9.add(jhayp18);
jhay9.add(btn9);
ButtonGroup x11 = new ButtonGroup();
jhay10.setVisible(false);
jhay10.setLayout(new GridLayout(8,3));
jhay10.add(Lq0);
jhay10.add(x37a);
jhay10.add(x38b);
jhay10.add(x39c);
jhay10.add(x40d);
btn0.setBackground(color);
jhayp19.setBackground(color);
jhay10.add(jhayp19);
jhay10.add(btn0);
jay1.addActionListener(this);
jay2.addActionListener(this);
jp.addActionListener(this);
jp1.addActionListener(this);
jhayp1.addActionListener(this);
jhayp11.addActionListener(this);
jhayp2.addActionListener(this);
jhayp12.addActionListener(this);
btn3.addActionListener(this);
jhayp13.addActionListener(this);
btn4.addActionListener(this);
jhayp14.addActionListener(this);
btn5.addActionListener(this);
jhayp15.addActionListener(this);
btn6.addActionListener(this);
jhayp16.addActionListener(this);
btn7.addActionListener(this);
jhayp17.addActionListener(this);
btn8.addActionListener(this);
jhayp18.addActionListener(this);
btn9.addActionListener(this);
jhayp19.addActionListener(this);
btn0.addActionListener(this);
x2.add(x1a);x2.add(x2b);x2.add(x3c);x2.add(x4d);
x3.add(x5a);x3.add(x6b);x3.add(x7c);x3.add(x8d);
x4.add(x9a);x4.add(x10b);x4.add(x11c);x4.add(x12d);
x5.add(x13a);x5.add(x14b);x5.add(x15c);x5.add(x16d);
x6.add(x17a);x6.add(x18b);x6.add(x19c);x6.add(x20d);
x7.add(x21a);x7.add(x22b);x7.add(x23c);x7.add(x24d);
x8.add(x25a);x8.add(x26b);x8.add(x27c);x8.add(x28d);
x9.add(x29a);x9.add(x30b);x9.add(x31c);x9.add(x32d);
x10.add(x33a);x10.add(x34b);x10.add(x35c);x10.add(x36d);
x11.add(x37a);x11.add(x38b);x11.add(x39c);x11.add(x40d);
con = jay.getContentPane();
con.add(panel);
con.add(jhay1);
con.add(jhay2);
con.add(jhay3);
con.add(jhay4);
con.add(jhay5);
con.add(jhay6);
con.add(jhay7);
con.add(jhay8);
con.add(jhay9);
con.add(jhay10);
jay.add(con);
}
public void actionPerformed(ActionEvent e) {
Object s = e.getSource();
jay.setLayout(new FlowLayout());
int score = 0;
int count = 0;
String txt1 = jay1.getText();
String txt2 =jay2.getText();
try{
if(s == jp1){
System.exit(0);
}
if(FirstName.equals(jay1.getText())){
if(LastName.equals(jay2.getText())){
if(s == jp){
jay.setSize(400,300);
JOptionPane.showMessageDialog(null, " Log In Complete");
panel.setVisible(false);
jhay1.setVisible(true);
}
}
}if(!FirstName.equals(jay1.getText()) && !LastName.equals(jay2.getText())){
jay.setSize(350,150);
JOptionPane.showMessageDialog(null, "Invalid Username and Password");
jay1.setText("");
jay2.setText("");
} else if(FirstName.equals(jay1.getText()) && !LastName.equals(jay2.getText())){
JOptionPane.showMessageDialog(null, "Incorrect Password");
jay.setSize(350,150);
jay2.setText("");
} else if(!FirstName.equals(jay1.getText()) && LastName.equals(jay2.getText())){
jay.setSize(350,150);
JOptionPane.showMessageDialog(null, "Incorrect Username");
jay1.setText("");
jay2.setText("");
}
} catch (Exception ex){
}
if(s==jp1){
jay.setSize(350,150);
jay1.setText("");
jay2.setText("");
}
if(x1a.isSelected()){
score++;
}
if(s == jhayp1){
try{
jhay1.setVisible(false);
jhay2.setVisible(true);
} catch (Exception ex){
}
}
if(x7c.isSelected()){
score++;
}
if(s == jhayp11){
try{
jhay1.setVisible(true);
jhay2.setVisible(false);
} catch (Exception ex){
}
}
if(s == jhayp2){
try{
jhay2.setVisible(false);
jhay3.setVisible(true);
} catch (Exception ex){
}
}
if(x10b.isSelected()){
score++;
}
if(s == jhayp12){
try{
jhay2.setVisible(true);
jhay3.setVisible(false);
} catch (Exception ex){
}
}
if(s == btn3){
try{
jhay3.setVisible(false);
jhay4.setVisible(true);
} catch (Exception ex){
}
}
if(x15c.isSelected()){
score++;
}
if(s == jhayp13){
try{
jhay3.setVisible(true);
jhay4.setVisible(false);
} catch (Exception ex){
}
}
if(s == btn4){
try{
jhay4.setVisible(false);
jhay5.setVisible(true);
} catch (Exception ex){
}
}
if(x19c.isSelected()){
score++;
}
if(s == jhayp14){
try{
jhay4.setVisible(true);
jhay5.setVisible(false);
} catch (Exception ex){
}
}
if(s == btn5){
try{
jhay5.setVisible(false);
jhay6.setVisible(true);
} catch (Exception ex){
}
}
if(x22b.isSelected()){
score++;
}
if(s == jhayp15){
try{
jhay5.setVisible(true);
jhay6.setVisible(false);
} catch (Exception ex){
}
}
if(s == btn6){
try{
jhay6.setVisible(false);
jhay7.setVisible(true);
} catch (Exception ex){
}
}
if(x27c.isSelected()){
score++;
}
if(s == jhayp16){
try{
jhay6.setVisible(true);
jhay7.setVisible(false);
} catch (Exception ex){
}
}
if(s == btn7){
try{
jhay7.setVisible(false);
jhay8.setVisible(true);
} catch (Exception ex){
}
}
if(x30b.isSelected()){
score++;
}
if(s == jhayp17){
try{
jhay7.setVisible(true);
jhay8.setVisible(false);
} catch (Exception ex){
}
}
if(s == btn8){
try{
jhay8.setVisible(false);
jhay9.setVisible(true);
} catch (Exception ex){
}
}
if(x34b.isSelected()){
score++;
}
if(s == jhayp18){
try{
jhay8.setVisible(true);
jhay9.setVisible(false);
} catch (Exception ex){
}
}
if(s == btn9){
try{
jhay9.setVisible(false);
jhay10.setVisible(true);
} catch (Exception ex){
}
}
if(x40d.isSelected()){
score++;
}
if(s == jhayp16){
try{
jhay9.setVisible(true);
} catch (Exception ex){
}
}
if(s == btn0){
try{
JLabel label1 = new JLabel(FirstName);
JLabel label2 = new JLabel(LastName);
JLabel label3 = new JLabel("Your score is " + score + "/10");
jhay10.setVisible(false);
jay.add(label1);
jay.add(label2);
jay.add(label3);
} catch (Exception ex){
}
}
}
}