package TicTacToe; import javax.swing.*; import javax.swing.border.Border; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Arrays; import java.util.Random; public class TicTacToe { private static JButton Easy, Medium, Hard; private static String StartGame = "X"; private static int xCount = 0; private static int oCount = 0; private static int buttonUsed [] = {0,0,0,0,0,0,0,0,0}; private static JButton t1,t2,t3,t4,t5,t6,t7,t8,t9; private static ImageIcon delete,circle,deletegrey,circlegrey; private static JLabel OScore, XScore, XLR, OLR,DLR; private static int drawScore = 0; private static int XLife = 3; private static int OLife = 3; private static int random; private static String difficulty; private static int contain; private static JFrame MainFrame, PlayFrame; public static void main(String[] args) { Color PaleWhite = Color.decode("#FDFDFD"); Border black = BorderFactory.createLineBorder(PaleWhite,1); MainFrame = new JFrame("TicTacToe"); JPanel MainPanel = new JPanel(null); JPanel ControlPanel = new JPanel(null); JPanel DifficultyPanel = new JPanel(null); JPanel PlayerAi = new JPanel(null); JLabel TicTacToeLogo = new JLabel(new ImageIcon("pictures\\Logo.png")); JButton PlayGame = new JButton("PLAY GAME"); JButton Exit = new JButton("EXIT"); Easy = new JButton("EASY"); Medium = new JButton("MEDIUM"); Hard = new JButton("HARD"); JButton Cancel = new JButton("CANCEL"); JButton AI = new JButton("AGAINST COMPUTER"); JButton TwoPlayer = new JButton("TWO PLAYER"); random = 1 + (int)(Math.random() *((3-1) + 1)); //Another One PlayFrame = new JFrame("TicTacToe"); JPanel PlayPanel = new JPanel(null); JPanel TicTacPanel = new JPanel(null); JLabel TicTacLabel = new JLabel(new ImageIcon("pictures\\Logo.png")); t1 = new JButton("
"); t2 = new JButton("
"); t3 = new JButton("
"); t4 = new JButton("
"); t5 = new JButton("
"); t6 = new JButton("
"); t7 = new JButton("
"); t8 = new JButton("
"); t9 = new JButton("
"); delete = new ImageIcon("pictures\\d.png"); circle = new ImageIcon("pictures\\c.png"); deletegrey = new ImageIcon("pictures\\dgrey.png"); circlegrey = new ImageIcon("pictures\\cgrey.png"); JLabel PlayerX = new JLabel("Player X"); JLabel PlayerO = new JLabel("Player O"); JLabel Score = new JLabel("Score"); JLabel LifeRemaining = new JLabel("Life Remaining"); JLabel draw = new JLabel("Draw Match"); XScore = new JLabel(); OScore = new JLabel(); XLR = new JLabel(String.valueOf(XLife)); OLR = new JLabel(String.valueOf(OLife)); DLR = new JLabel(); XScore.setHorizontalAlignment(SwingConstants.CENTER); OScore.setHorizontalAlignment(SwingConstants.CENTER); OLR.setHorizontalAlignment(SwingConstants.CENTER); XLR.setHorizontalAlignment(SwingConstants.CENTER); DLR.setHorizontalAlignment(SwingConstants.CENTER); //SetBounds //Panels // DLR.setBounds(125,510,50,50); draw.setBounds(15,510,80,50); Score.setBounds(15,500,80,50); OLR.setBounds(210,430,50,50); XLR.setBounds(125,430,50,50); OScore.setBounds(210,350,50,50); XScore.setBounds(125,350,50,50); PlayerX.setBounds(125,280,70,50); PlayerO.setBounds(205,280,70,50); Score.setBounds(15,350,80,50); LifeRemaining.setBounds(15,430,100,50); t1.setBounds(0,0,180,190); t2.setBounds(180,0,180,190); t3.setBounds(360,0,180,190); t4.setBounds(0,190,180,190); t5.setBounds(180,190,180,190); t6.setBounds(360,190,180,190); t7.setBounds(0,380,180,190); t8.setBounds(180,380,180,190); t9.setBounds(360,380,180,190); TicTacPanel.setBounds(300,50,540,570); TicTacLabel.setBounds(50,0,200,150); PlayPanel.setBounds(0,0,895,695); // MainPanel.setBounds(0,0,500,590); TicTacToeLogo.setBounds(147,10,200,150); ControlPanel.setBounds(73,150,350,350); DifficultyPanel.setBounds(73,150,350,350); PlayerAi.setBounds(73,150,350,350); //Buttons // // PlayGame.setBounds(75,90,200,50); Exit.setBounds(75,200,200,50); Easy.setBounds(75,40,200,50); Medium.setBounds(75,110,200,50); Hard.setBounds(75,180,200,50); Cancel.setBounds(75,270,200,50); AI.setBounds(75,90,200,50); TwoPlayer.setBounds(75,200,200,50); /*------------DESIGNS-----------------------------*/ //Panel // TicTacPanel.setOpaque(false); TicTacPanel.getBackground(); PlayPanel.setBackground(Color.decode("#1D1D1D")); // MainPanel.setBackground(Color.decode("#1D1D1D")); ControlPanel.setOpaque(false); ControlPanel.getBackground(); ControlPanel.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); DifficultyPanel.setOpaque(false); DifficultyPanel.getBackground(); DifficultyPanel.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); PlayerAi.setOpaque(false); PlayerAi.getBackground(); PlayerAi.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); //Buttons PlayGame.setOpaque(false); PlayGame.getBackground(); PlayGame.setContentAreaFilled(false); PlayGame.setForeground(PaleWhite); PlayGame.setFocusPainted(false); PlayGame.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); PlayGame.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); Exit.setOpaque(false); Exit.getBackground(); Exit.setContentAreaFilled(false); Exit.setForeground(PaleWhite); Exit.setFocusPainted(false); Exit.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); Exit.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); Easy.setOpaque(false); Easy.getBackground(); Easy.setContentAreaFilled(false); Easy.setForeground(PaleWhite); Easy.setFocusPainted(false); Easy.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); Easy.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); Medium.setOpaque(false); Medium.getBackground(); Medium.setContentAreaFilled(false); Medium.setForeground(PaleWhite); Medium.setFocusPainted(false); Medium.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); Medium.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); Hard.setOpaque(false); Hard.getBackground(); Hard.setContentAreaFilled(false); Hard.setForeground(PaleWhite); Hard.setFocusPainted(false); Hard.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); Hard.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); Cancel.setOpaque(false); Cancel.getBackground(); Cancel.setContentAreaFilled(false); Cancel.setForeground(PaleWhite); Cancel.setFocusPainted(false); Cancel.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); Cancel.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); AI.setOpaque(false); AI.getBackground(); AI.setContentAreaFilled(false); AI.setForeground(PaleWhite); AI.setFocusPainted(false); AI.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); AI.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); TwoPlayer.setOpaque(false); TwoPlayer.getBackground(); TwoPlayer.setContentAreaFilled(false); TwoPlayer.setForeground(PaleWhite); TwoPlayer.setFocusPainted(false); TwoPlayer.setBorder(BorderFactory.createLineBorder(PaleWhite,3,true)); TwoPlayer.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,12)); t1.setOpaque(false); t1.setBackground(MainPanel.getBackground()); t1.setContentAreaFilled(false); t1.setForeground(PaleWhite); t1.setFocusPainted(false); t1.setBorder(BorderFactory.createMatteBorder(0,0,3,3,PaleWhite)); t1.setIconTextGap(-30); t2.setOpaque(false); t2.setBackground(MainPanel.getBackground()); t2.setContentAreaFilled(false); t2.setForeground(PaleWhite); t2.setFocusPainted(false); t2.setBorder(BorderFactory.createMatteBorder(0,3,3,3,PaleWhite)); t2.setIconTextGap(-30); t3.setOpaque(false); t3.setBackground(MainPanel.getBackground()); t3.setContentAreaFilled(false); t3.setForeground(PaleWhite); t3.setFocusPainted(false); t3.setBorder(BorderFactory.createMatteBorder(0,3,3,0,PaleWhite)); t3.setIconTextGap(-30); t4.setOpaque(false); t4.setBackground(MainPanel.getBackground()); t4.setContentAreaFilled(false); t4.setForeground(PaleWhite); t4.setFocusPainted(false); t4.setBorder(BorderFactory.createMatteBorder(3,0,3,3,PaleWhite)); t4.setIconTextGap(-30); t5.setOpaque(false); t5.setBackground(MainPanel.getBackground()); t5.setContentAreaFilled(false); t5.setForeground(PaleWhite); t5.setFocusPainted(false); t5.setBorder(BorderFactory.createMatteBorder(3,3,3,3,PaleWhite)); t5.setIconTextGap(-30); t6.setOpaque(false); t6.setBackground(MainPanel.getBackground()); t6.setContentAreaFilled(false); t6.setForeground(PaleWhite); t6.setFocusPainted(false); t6.setBorder(BorderFactory.createMatteBorder(3,3,3,0,PaleWhite)); t6.setIconTextGap(-30); t7.setOpaque(false); t7.setBackground(MainPanel.getBackground()); t7.setContentAreaFilled(false); t7.setForeground(PaleWhite); t7.setFocusPainted(false); t7.setBorder(BorderFactory.createMatteBorder(3,0,0,3,PaleWhite)); t7.setIconTextGap(-30); t8.setOpaque(false); t8.setBackground(MainPanel.getBackground()); t8.setContentAreaFilled(false); t8.setForeground(PaleWhite); t8.setFocusPainted(false); t8.setBorder(BorderFactory.createMatteBorder(3,3,0,3,PaleWhite)); t8.setIconTextGap(-30); t9.setOpaque(false); t9.setBackground(MainPanel.getBackground()); t9.setContentAreaFilled(false); t9.setForeground(PaleWhite); t9.setFocusPainted(false); t9.setBorder(BorderFactory.createMatteBorder(3,3,0,0,PaleWhite)); t9.setIconTextGap(-30); LifeRemaining.setOpaque(false); LifeRemaining.setForeground(PaleWhite); LifeRemaining.setBackground(PlayPanel.getBackground()); LifeRemaining.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); PlayerX.setOpaque(false); PlayerX.setForeground(PaleWhite); PlayerX.setBackground(PlayPanel.getBackground()); PlayerX.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); PlayerO.setOpaque(false); PlayerO.setForeground(PaleWhite); PlayerO.setBackground(PlayPanel.getBackground()); PlayerO.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); Score.setOpaque(false); Score.setForeground(PaleWhite); Score.setBackground(PlayPanel.getBackground()); Score.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); XScore.setOpaque(false); XScore.setForeground(PaleWhite); XScore.setBackground(PlayPanel.getBackground()); XScore.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); OScore.setOpaque(false); OScore.setForeground(PaleWhite); OScore.setBackground(PlayPanel.getBackground()); OScore.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); XLR.setOpaque(false); XLR.setForeground(PaleWhite); XLR.setBackground(PlayPanel.getBackground()); XLR.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); OLR.setOpaque(false); OLR.setForeground(PaleWhite); OLR.setBackground(PlayPanel.getBackground()); OLR.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); draw.setOpaque(false); draw.setForeground(PaleWhite); draw.setBackground(PlayPanel.getBackground()); draw.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); DLR.setOpaque(false); DLR.setForeground(PaleWhite); DLR.setBackground(PlayPanel.getBackground()); DLR.setFont(new Font("Lato Bold",Font.TRUETYPE_FONT,15)); //ADD PlayPanel.add(draw); PlayPanel.add(DLR); PlayPanel.add(LifeRemaining); PlayPanel.add(Score); PlayPanel.add(PlayerO); PlayPanel.add(PlayerX); PlayPanel.add(XScore); PlayPanel.add(OScore); PlayPanel.add(XLR); PlayPanel.add(OLR); TicTacPanel.add(t1); TicTacPanel.add(t2); TicTacPanel.add(t3); TicTacPanel.add(t4); TicTacPanel.add(t5); TicTacPanel.add(t6); TicTacPanel.add(t7); TicTacPanel.add(t8); TicTacPanel.add(t9); PlayPanel.add(TicTacPanel); PlayPanel.add(TicTacLabel); PlayFrame.add(PlayPanel); // PlayerAi.add(TwoPlayer); PlayerAi.add(AI); DifficultyPanel.add(Cancel); DifficultyPanel.add(Easy); DifficultyPanel.add(Medium); DifficultyPanel.add(Hard); ControlPanel.add(Exit); ControlPanel.add(PlayGame); MainPanel.add(PlayerAi); MainPanel.add(DifficultyPanel); MainPanel.add(ControlPanel); MainPanel.add(TicTacToeLogo); MainFrame.add(MainPanel); // // // TicTacPanel.setVisible(true); PlayPanel.setVisible(true); // PlayerAi.setVisible(false); DifficultyPanel.setVisible(false); ControlPanel.setVisible(true); MainPanel.setVisible(true); /*-------------------------------ACTION LISTENERS----------------------------------------*/ PlayGame.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ControlPanel.setVisible(false); DifficultyPanel.setVisible(true); } }); Exit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); Cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ControlPanel.setVisible(true); DifficultyPanel.setVisible(false); } }); Easy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { difficulty = Easy.getText(); MainFrame.setVisible(false); PlayFrame.setVisible(true); } }); Medium.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { difficulty = Medium.getText(); MainFrame.setVisible(false); PlayFrame.setVisible(true); } }); Hard.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { difficulty = Hard.getText(); MainFrame.setVisible(false); PlayFrame.setVisible(true); } }); t1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[0] == 0){ t1.setText(StartGame); if (t1.getText().equals("X")){ t1.setIcon(delete); }else { t1.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t1.setForeground(MainPanel.getBackground()); buttonUsed [0] = 1; }else { t1.setForeground(MainPanel.getBackground()); buttonUsed [0] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[1] == 0){ t2.setText(StartGame); if (t2.getText().equals("X")){ t2.setIcon(delete); }else { t2.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t2.setForeground(MainPanel.getBackground()); buttonUsed[1] = 1; }else { t2.setForeground(MainPanel.getBackground()); buttonUsed[1] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[2] == 0){ t3.setText(StartGame); if (t3.getText().equals("X")){ t3.setIcon(delete); }else { t3.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t3.setForeground(MainPanel.getBackground()); buttonUsed[2] = 1; }else { t3.setForeground(MainPanel.getBackground()); buttonUsed[2] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[3] == 0){ t4.setText(StartGame); if (t4.getText().equals("X")){ t4.setIcon(delete); }else { t4.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t4.setForeground(MainPanel.getBackground()); buttonUsed [3] = 1; }else { t4.setForeground(MainPanel.getBackground()); buttonUsed [3] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[4] == 0){ t5.setText(StartGame); if (t5.getText().equals("X")){ t5.setIcon(delete); }else { t5.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t5.setForeground(MainPanel.getBackground()); buttonUsed[4] = 1; }else { t5.setForeground(MainPanel.getBackground()); buttonUsed[4] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t6.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[5] == 0){ t6.setText(StartGame); if (t6.getText().equals("X")){ t6.setIcon(delete); }else { t6.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t6.setForeground(MainPanel.getBackground()); buttonUsed[5] = 1; }else { t6.setForeground(MainPanel.getBackground()); buttonUsed[5] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t7.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[6] == 0) { t7.setText(StartGame); if (t7.getText().equals("X")){ t7.setIcon(delete); }else { t7.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t7.setForeground(MainPanel.getBackground()); buttonUsed[6] = 1; }else { t7.setForeground(MainPanel.getBackground()); buttonUsed[6] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t8.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed [7] == 0){ t8.setText(StartGame); if (t8.getText().equals("X")){ t8.setIcon(delete); }else { t8.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t8.setForeground(MainPanel.getBackground()); buttonUsed [7] = 1; }else { t8.setForeground(MainPanel.getBackground()); buttonUsed [7] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); t9.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (buttonUsed[8] == 0){ t9.setText(StartGame); if (t9.getText().equals("X")){ t9.setIcon(delete); }else { t9.setIcon(circle); } if (StartGame.equalsIgnoreCase("X")){ t9.setForeground(MainPanel.getBackground()); buttonUsed[8] = 1; }else { t9.setForeground(MainPanel.getBackground()); buttonUsed[8] = 1; } choosePlayer(); winningGame(); Winner(); }else { JOptionPane.showMessageDialog(null,"It have been used!","",JOptionPane.WARNING_MESSAGE); } } }); // if (XLife == 0 ){ JOptionPane.showMessageDialog(null,"Game Over! , Player O Win!"); } if (OLife == 0 ){ JOptionPane.showMessageDialog(null,"Game Over! , Player X Win!"); } PlayFrame.setSize(900,700); PlayFrame.setLocationRelativeTo(null); PlayFrame.setResizable(false); PlayFrame.setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE); PlayFrame.setLayout(null); PlayFrame.setVisible(false); MainFrame.setSize(500,600); MainFrame.setLocationRelativeTo(null); MainFrame.setResizable(false); MainFrame.setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE); MainFrame.setLayout(null); MainFrame.setVisible(true); } private static void questions(){ xPlay(); oPlay(); } private static void Winner(){ if (xCount == 12){ PlayFrame.setVisible(false); PlayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JOptionPane.showMessageDialog(null,"Player X is the Winner! "); } if (oCount == 12){ PlayFrame.setVisible(false); PlayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JOptionPane.showMessageDialog(null,"Player O is the Winner! "); } } private static void xPlay(){ if (xCount == 3){ if (difficulty.equalsIgnoreCase("Easy")){ xEasyQuestions(); }else if (difficulty.equalsIgnoreCase("Medium")){ xMediumQuestions(); }else { xHardQuestions(); } } if (xCount == 6){ if (difficulty.equalsIgnoreCase("Easy")){ xEasyQuestions(); }else if (difficulty.equalsIgnoreCase("Medium")){ xMediumQuestions(); }else { xHardQuestions(); } } if (xCount == 9){ if (difficulty.equalsIgnoreCase("Easy")){ xEasyQuestions(); }else if (difficulty.equalsIgnoreCase("Medium")){ xMediumQuestions(); }else { xHardQuestions(); } } if (Integer.parseInt(XLR.getText()) == 0){ PlayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JOptionPane.showMessageDialog(null,"Game Over! Player O WIN! "); } } private static void oPlay(){ if (oCount == 3){ if (difficulty.equalsIgnoreCase("Easy")){ oEasyQuestions(); }else if (difficulty.equalsIgnoreCase("Medium")){ oMediumQuestions(); }else { oHardQuestions(); } } if (oCount == 6){ if (difficulty.equalsIgnoreCase("Easy")){ oEasyQuestions(); }else if (difficulty.equalsIgnoreCase("Medium")){ oMediumQuestions(); }else { oHardQuestions(); } } if (oCount == 9){ if (difficulty.equalsIgnoreCase("Easy")) { oEasyQuestions(); }else if (difficulty.equalsIgnoreCase("Medium")){ oMediumQuestions(); }else { oHardQuestions(); } } if (Integer.parseInt(OLR.getText()) == 0){ PlayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JOptionPane.showMessageDialog(null,"Game Over! Player X WIN! "); } } private static void xEasyQuestions(){ String[] options = {"OK"}; switch (random){ case 1: JPanel panel = new JPanel(); JLabel lbl = new JLabel("1 + 1 = "); JTextField txt = new JTextField(10); panel.add(lbl); panel.add(txt); int selectedOption = JOptionPane.showOptionDialog(null, panel, "Question No. 1: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if(selectedOption == 0) { if (Integer.parseInt(txt.getText()) == 2){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else{ XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 2: JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel("(5 + 5) / 2 = "); JTextField txt2 = new JTextField(10); panel2.add(lbl2); panel2.add(txt2); int selectedOption2 = JOptionPane.showOptionDialog(null, panel2, "Question No. 2: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption2 == 0){ if (Integer.parseInt(txt2.getText()) == 5){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 3: JPanel panel3 = new JPanel(); JLabel lbl3 = new JLabel("2 + 5 = "); JTextField txt3 = new JTextField(10); panel3.add(lbl3); panel3.add(txt3); int selectedOption3 = JOptionPane.showOptionDialog(null, panel3, "Question No. 3: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption3 == 0){ if (Integer.parseInt(txt3.getText()) == 7){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 4: JPanel panel4 = new JPanel(); JLabel lbl4 = new JLabel("10 + (50 * 5) - 6 = "); JTextField txt4 = new JTextField(10); panel4.add(lbl4); panel4.add(txt4); int selectedOption4 = JOptionPane.showOptionDialog(null, panel4, "Question No. 4: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption4 == 0){ if (Integer.parseInt(txt4.getText()) == 254){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 5: JPanel panel5 = new JPanel(); JLabel lbl5 = new JLabel("100 * 5 + 10 = "); JTextField txt5 = new JTextField(10); panel5.add(lbl5); panel5.add(txt5); int selectedOption5 = JOptionPane.showOptionDialog(null, panel5, "Question No. 5: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption5 == 0){ if (Integer.parseInt(txt5.getText()) == 510){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 6: JPanel panel6 = new JPanel(); JLabel lbl6 = new JLabel("75 + 55 + 68 = "); JTextField txt6 = new JTextField(10); panel6.add(lbl6); panel6.add(txt6); int selectedOption6 = JOptionPane.showOptionDialog(null, panel6, "Question No. 6: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption6 == 0){ if (Integer.parseInt(txt6.getText()) == 198){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 7: JPanel panel7 = new JPanel(); JLabel lbl7 = new JLabel("1500 + 700 + (-300) = "); JTextField txt7 = new JTextField(10); panel7.add(lbl7); panel7.add(txt7); int selectedOption7 = JOptionPane.showOptionDialog(null, panel7, "Question No. 7: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption7 == 0){ if (Integer.parseInt(txt7.getText()) == 1900){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 8: JPanel panel8 = new JPanel(); JLabel lbl8 = new JLabel("900 + 800 + 500 = "); JTextField txt8 = new JTextField(10); panel8.add(lbl8); panel8.add(txt8); int selectedOption8 = JOptionPane.showOptionDialog(null, panel8, "Question No. 8: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption8 == 0){ if (Integer.parseInt(txt8.getText()) == 2200){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 9: JPanel panel9 = new JPanel(); JLabel lbl9 = new JLabel("-1 - 1 + 1 - 1 + 1 = "); JTextField txt9 = new JTextField(10); panel9.add(lbl9); panel9.add(txt9); int selectedOption9 = JOptionPane.showOptionDialog(null, panel9, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption9 == 0){ if (Integer.parseInt(txt9.getText()) == -1){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 10: JPanel panel10 = new JPanel(); JLabel lbl10 = new JLabel("800 + 700 ="); JTextField txt10 = new JTextField(10); panel10.add(lbl10); panel10.add(txt10); int selectedOption10 = JOptionPane.showOptionDialog(null, panel10, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption10 == 0){ if (Integer.parseInt(txt10.getText()) == 1500){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 11: JPanel panel11 = new JPanel(); JLabel lbl11 = new JLabel("1900 * 700 / 5 = "); JTextField txt11 = new JTextField(10); panel11.add(lbl11); panel11.add(txt11); int selectedOption11 = JOptionPane.showOptionDialog(null, panel11, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption11 == 0){ if (Integer.parseInt(txt11.getText()) == 266000){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 12: JPanel panel12 = new JPanel(); JLabel lbl12 = new JLabel("580 + 780 = "); JTextField txt12 = new JTextField(10); panel12.add(lbl12); panel12.add(txt12); int selectedOption12 = JOptionPane.showOptionDialog(null, panel12, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption12 == 0){ if (Integer.parseInt(txt12.getText()) == 1360){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 13: JPanel panel13 = new JPanel(); JLabel lbl13 = new JLabel("500 - (-9) = "); JTextField txt13 = new JTextField(10); panel13.add(lbl13); panel13.add(txt13); int selectedOption13 = JOptionPane.showOptionDialog(null, panel13, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption13 == 0){ if (Integer.parseInt(txt13.getText()) == 509){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; } } private static void oEasyQuestions(){ String[] options = {"OK"}; switch (random){ case 1: JPanel panel = new JPanel(); JLabel lbl = new JLabel("1 + 1 = "); JTextField txt = new JTextField(10); panel.add(lbl); panel.add(txt); int selectedOption = JOptionPane.showOptionDialog(null, panel, "Question No. 1: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if(selectedOption == 0) { if (Integer.parseInt(txt.getText()) == 2){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else{ OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 2: JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel("(5 + 5) / 2 = "); JTextField txt2 = new JTextField(10); panel2.add(lbl2); panel2.add(txt2); int selectedOption2 = JOptionPane.showOptionDialog(null, panel2, "Question No. 2: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption2 == 0){ if (Integer.parseInt(txt2.getText()) == 5){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 3: JPanel panel3 = new JPanel(); JLabel lbl3 = new JLabel("-1 - 1 = "); JTextField txt3 = new JTextField(10); panel3.add(lbl3); panel3.add(txt3); int selectedOption3 = JOptionPane.showOptionDialog(null, panel3, "Question No. 3: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption3 == 0){ if (Integer.parseInt(txt3.getText()) == -2){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 4: JPanel panel4 = new JPanel(); JLabel lbl4 = new JLabel("10 + (50 * 5) - 6 = "); JTextField txt4 = new JTextField(10); panel4.add(lbl4); panel4.add(txt4); int selectedOption4 = JOptionPane.showOptionDialog(null, panel4, "Question No. 4: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption4 == 0){ if (Integer.parseInt(txt4.getText()) == 254){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 5: JPanel panel5 = new JPanel(); JLabel lbl5 = new JLabel("100 * 5 + 10 = "); JTextField txt5 = new JTextField(10); panel5.add(lbl5); panel5.add(txt5); int selectedOption5 = JOptionPane.showOptionDialog(null, panel5, "Question No. 5: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption5 == 0){ if (Integer.parseInt(txt5.getText()) == 510){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 6: JPanel panel6 = new JPanel(); JLabel lbl6 = new JLabel("75 + 55 + 68 = "); JTextField txt6 = new JTextField(10); panel6.add(lbl6); panel6.add(txt6); int selectedOption6 = JOptionPane.showOptionDialog(null, panel6, "Question No. 6: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption6 == 0){ if (Integer.parseInt(txt6.getText()) == 198){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 7: JPanel panel7 = new JPanel(); JLabel lbl7 = new JLabel("1500 + 700 + (-300) = "); JTextField txt7 = new JTextField(10); panel7.add(lbl7); panel7.add(txt7); int selectedOption7 = JOptionPane.showOptionDialog(null, panel7, "Question No. 7: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption7 == 0){ if (Integer.parseInt(txt7.getText()) == 1900){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 8: JPanel panel8 = new JPanel(); JLabel lbl8 = new JLabel("900 + 800 + 500 = "); JTextField txt8 = new JTextField(10); panel8.add(lbl8); panel8.add(txt8); int selectedOption8 = JOptionPane.showOptionDialog(null, panel8, "Question No. 8: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption8 == 0){ if (Integer.parseInt(txt8.getText()) == 2200){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 9: JPanel panel9 = new JPanel(); JLabel lbl9 = new JLabel("-1 - 1 + 1 - 1 + 1 = "); JTextField txt9 = new JTextField(10); panel9.add(lbl9); panel9.add(txt9); int selectedOption9 = JOptionPane.showOptionDialog(null, panel9, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption9 == 0){ if (Integer.parseInt(txt9.getText()) == -1){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 10: JPanel panel10 = new JPanel(); JLabel lbl10 = new JLabel("800 + 700 ="); JTextField txt10 = new JTextField(10); panel10.add(lbl10); panel10.add(txt10); int selectedOption10 = JOptionPane.showOptionDialog(null, panel10, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption10 == 0){ if (Integer.parseInt(txt10.getText()) == 1500){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 11: JPanel panel11 = new JPanel(); JLabel lbl11 = new JLabel("1900 * 700 / 5 = "); JTextField txt11 = new JTextField(10); panel11.add(lbl11); panel11.add(txt11); int selectedOption11 = JOptionPane.showOptionDialog(null, panel11, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption11 == 0){ if (Integer.parseInt(txt11.getText()) == 266000){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 12: JPanel panel12 = new JPanel(); JLabel lbl12 = new JLabel("580 + 780 = "); JTextField txt12 = new JTextField(10); panel12.add(lbl12); panel12.add(txt12); int selectedOption12 = JOptionPane.showOptionDialog(null, panel12, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption12 == 0){ if (Integer.parseInt(txt12.getText()) == 1360){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 13: JPanel panel13 = new JPanel(); JLabel lbl13 = new JLabel("500 - (-9) = "); JTextField txt13 = new JTextField(10); panel13.add(lbl13); panel13.add(txt13); int selectedOption13 = JOptionPane.showOptionDialog(null, panel13, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption13 == 0){ if (Integer.parseInt(txt13.getText()) == 509){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; } } private static void xMediumQuestions(){ String[] options = {"OK"}; switch (random){ case 1: JPanel panel = new JPanel(); JLabel lbl = new JLabel("10 - 2(3) = "); JTextField txt = new JTextField(10); panel.add(lbl); panel.add(txt); int selectedOption = JOptionPane.showOptionDialog(null, panel, "Question No. 1: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if(selectedOption == 0) { if (Integer.parseInt(txt.getText()) == 4){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else{ XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 2: JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel("-2^3 ="); JTextField txt2 = new JTextField(10); panel2.add(lbl2); panel2.add(txt2); int selectedOption2 = JOptionPane.showOptionDialog(null, panel2, "Question No. 2: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption2 == 0){ if (Integer.parseInt(txt2.getText()) == -8){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 3: JPanel panel3 = new JPanel(); JLabel lbl3 = new JLabel("6 - 3^2 = "); JTextField txt3 = new JTextField(10); panel3.add(lbl3); panel3.add(txt3); int selectedOption3 = JOptionPane.showOptionDialog(null, panel3, "Question No. 3: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption3 == 0){ if (Integer.parseInt(txt3.getText()) == -3){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 4: JPanel panel4 = new JPanel(); JLabel lbl4 = new JLabel("105 รท 7 - 25 = "); JTextField txt4 = new JTextField(10); panel4.add(lbl4); panel4.add(txt4); int selectedOption4 = JOptionPane.showOptionDialog(null, panel4, "Question No. 4: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption4 == 0){ if (Integer.parseInt(txt4.getText()) == -10){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 5: JPanel panel5 = new JPanel(); JLabel lbl5 = new JLabel("496 รท 2 + (-20)^2 = "); JTextField txt5 = new JTextField(10); panel5.add(lbl5); panel5.add(txt5); int selectedOption5 = JOptionPane.showOptionDialog(null, panel5, "Question No. 5: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption5 == 0){ if (Integer.parseInt(txt5.getText()) == 648){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 6: JPanel panel6 = new JPanel(); JLabel lbl6 = new JLabel("1,560 รท 5 + 50 - (-2) = "); JTextField txt6 = new JTextField(10); panel6.add(lbl6); panel6.add(txt6); int selectedOption6 = JOptionPane.showOptionDialog(null, panel6, "Question No. 6: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption6 == 0){ if (Integer.parseInt(txt6.getText()) == 1617){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 7: JPanel panel7 = new JPanel(); JLabel lbl7 = new JLabel("765 รท 9^2 + 20 = "); JTextField txt7 = new JTextField(10); panel7.add(lbl7); panel7.add(txt7); int selectedOption7 = JOptionPane.showOptionDialog(null, panel7, "Question No. 7: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption7 == 0){ if (Integer.parseInt(txt7.getText()) == 866){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 8: JPanel panel8 = new JPanel(); JLabel lbl8 = new JLabel("1000 + 10000 - 10^4 = "); JTextField txt8 = new JTextField(10); panel8.add(lbl8); panel8.add(txt8); int selectedOption8 = JOptionPane.showOptionDialog(null, panel8, "Question No. 8: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption8 == 0){ if (Integer.parseInt(txt8.getText()) == 10){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 9: JPanel panel9 = new JPanel(); JLabel lbl9 = new JLabel("2,550 รท 25 + 50 = "); JTextField txt9 = new JTextField(10); panel9.add(lbl9); panel9.add(txt9); int selectedOption9 = JOptionPane.showOptionDialog(null, panel9, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption9 == 0){ if (Integer.parseInt(txt9.getText()) == 152){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 10: JPanel panel10 = new JPanel(); JLabel lbl10 = new JLabel("456 + 958 + (-1000) ="); JTextField txt10 = new JTextField(10); panel10.add(lbl10); panel10.add(txt10); int selectedOption10 = JOptionPane.showOptionDialog(null, panel10, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption10 == 0){ if (Integer.parseInt(txt10.getText()) == 414){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 11: JPanel panel11 = new JPanel(); JLabel lbl11 = new JLabel("73 + 67 + 5800 + 7500 = "); JTextField txt11 = new JTextField(10); panel11.add(lbl11); panel11.add(txt11); int selectedOption11 = JOptionPane.showOptionDialog(null, panel11, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption11 == 0){ if (Integer.parseInt(txt11.getText()) == 13440){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 12: JPanel panel12 = new JPanel(); JLabel lbl12 = new JLabel("88 + 89 * 50 = "); JTextField txt12 = new JTextField(10); panel12.add(lbl12); panel12.add(txt12); int selectedOption12 = JOptionPane.showOptionDialog(null, panel12, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption12 == 0){ if (Integer.parseInt(txt12.getText()) == 4538){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 13: JPanel panel13 = new JPanel(); JLabel lbl13 = new JLabel("1800 + 1200 + 75 = "); JTextField txt13 = new JTextField(10); panel13.add(lbl13); panel13.add(txt13); int selectedOption13 = JOptionPane.showOptionDialog(null, panel13, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption13 == 0){ if (Integer.parseInt(txt13.getText()) == 3075){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; } } private static void oMediumQuestions(){ String[] options = {"OK"}; switch (random){ case 1: JPanel panel = new JPanel(); JLabel lbl = new JLabel("10 - 2(3) = "); JTextField txt = new JTextField(10); panel.add(lbl); panel.add(txt); int selectedOption = JOptionPane.showOptionDialog(null, panel, "Question No. 1: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if(selectedOption == 0) { if (Integer.parseInt(txt.getText()) == 4){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else{ OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 2: JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel("-2^3 ="); JTextField txt2 = new JTextField(10); panel2.add(lbl2); panel2.add(txt2); int selectedOption2 = JOptionPane.showOptionDialog(null, panel2, "Question No. 2: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption2 == 0){ if (Integer.parseInt(txt2.getText()) == -8){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 3: JPanel panel3 = new JPanel(); JLabel lbl3 = new JLabel("6 - 3^2 = "); JTextField txt3 = new JTextField(10); panel3.add(lbl3); panel3.add(txt3); int selectedOption3 = JOptionPane.showOptionDialog(null, panel3, "Question No. 3: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption3 == 0){ if (Integer.parseInt(txt3.getText()) == -3){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 4: JPanel panel4 = new JPanel(); JLabel lbl4 = new JLabel("105 / 7 - 25 = "); JTextField txt4 = new JTextField(10); panel4.add(lbl4); panel4.add(txt4); int selectedOption4 = JOptionPane.showOptionDialog(null, panel4, "Question No. 4: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption4 == 0){ if (Integer.parseInt(txt4.getText()) == -10){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 5: JPanel panel5 = new JPanel(); JLabel lbl5 = new JLabel("496 / 2 + (-20)^2 = "); JTextField txt5 = new JTextField(10); panel5.add(lbl5); panel5.add(txt5); int selectedOption5 = JOptionPane.showOptionDialog(null, panel5, "Question No. 5: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption5 == 0){ if (Integer.parseInt(txt5.getText()) == 648){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 6: JPanel panel6 = new JPanel(); JLabel lbl6 = new JLabel("1560 / 5 + 50 - (-2) = "); JTextField txt6 = new JTextField(10); panel6.add(lbl6); panel6.add(txt6); int selectedOption6 = JOptionPane.showOptionDialog(null, panel6, "Question No. 6: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption6 == 0){ if (Integer.parseInt(txt6.getText()) == 1617){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 7: JPanel panel7 = new JPanel(); JLabel lbl7 = new JLabel("765 / 9^2 + 20 = "); JTextField txt7 = new JTextField(10); panel7.add(lbl7); panel7.add(txt7); int selectedOption7 = JOptionPane.showOptionDialog(null, panel7, "Question No. 7: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption7 == 0){ if (Integer.parseInt(txt7.getText()) == 866){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 8: JPanel panel8 = new JPanel(); JLabel lbl8 = new JLabel("1000 + 10000 - 10^4 = "); JTextField txt8 = new JTextField(10); panel8.add(lbl8); panel8.add(txt8); int selectedOption8 = JOptionPane.showOptionDialog(null, panel8, "Question No. 8: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption8 == 0){ if (Integer.parseInt(txt8.getText()) == 10){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 9: JPanel panel9 = new JPanel(); JLabel lbl9 = new JLabel("2550 / 25 + 50 = "); JTextField txt9 = new JTextField(10); panel9.add(lbl9); panel9.add(txt9); int selectedOption9 = JOptionPane.showOptionDialog(null, panel9, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption9 == 0){ if (Integer.parseInt(txt9.getText()) == 152){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 10: JPanel panel10 = new JPanel(); JLabel lbl10 = new JLabel("456 + 958 + (-1000) ="); JTextField txt10 = new JTextField(10); panel10.add(lbl10); panel10.add(txt10); int selectedOption10 = JOptionPane.showOptionDialog(null, panel10, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption10 == 0){ if (Integer.parseInt(txt10.getText()) == 414){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 11: JPanel panel11 = new JPanel(); JLabel lbl11 = new JLabel("73 + 67 + 5800 + 7500 = "); JTextField txt11 = new JTextField(10); panel11.add(lbl11); panel11.add(txt11); int selectedOption11 = JOptionPane.showOptionDialog(null, panel11, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption11 == 0){ if (Integer.parseInt(txt11.getText()) == 13440){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 12: JPanel panel12 = new JPanel(); JLabel lbl12 = new JLabel("88 + 89 * 50 = "); JTextField txt12 = new JTextField(10); panel12.add(lbl12); panel12.add(txt12); int selectedOption12 = JOptionPane.showOptionDialog(null, panel12, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption12 == 0){ if (Integer.parseInt(txt12.getText()) == 4538){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 13: JPanel panel13 = new JPanel(); JLabel lbl13 = new JLabel("1800 + 1200 + 75 = "); JTextField txt13 = new JTextField(10); panel13.add(lbl13); panel13.add(txt13); int selectedOption13 = JOptionPane.showOptionDialog(null, panel13, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption13 == 0){ if (Integer.parseInt(txt13.getText()) == 3075){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; } } private static void xHardQuestions(){ String[] options = {"OK"}; switch (random){ case 1: JPanel panel = new JPanel(); JLabel lbl = new JLabel("5 + (-24) + 3 square root(64) = "); JTextField txt = new JTextField(10); panel.add(lbl); panel.add(txt); int selectedOption = JOptionPane.showOptionDialog(null, panel, "Question No. 1: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if(selectedOption == 0) { if (Integer.parseInt(txt.getText()) == 5){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else{ XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 2: JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel("52 / 5 + 89 - 3 square root(6)^2 = "); JTextField txt2 = new JTextField(10); panel2.add(lbl2); panel2.add(txt2); int selectedOption2 = JOptionPane.showOptionDialog(null, panel2, "Question No. 2: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption2 == 0){ if (Double.parseDouble(txt2.getText()) == 81.40){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 3: JPanel panel3 = new JPanel(); JLabel lbl3 = new JLabel("4^5 * 6 + 89 + square root(6)^5 = "); JTextField txt3 = new JTextField(10); panel3.add(lbl3); panel3.add(txt3); int selectedOption3 = JOptionPane.showOptionDialog(null, panel3, "Question No. 3: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption3 == 0){ if (Double.parseDouble(txt3.getText()) == 157.21){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 4: JPanel panel4 = new JPanel(); JLabel lbl4 = new JLabel("75(89^2 + 56^2) = "); JTextField txt4 = new JTextField(10); panel4.add(lbl4); panel4.add(txt4); int selectedOption4 = JOptionPane.showOptionDialog(null, panel4, "Question No. 4: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption4 == 0){ if (Double.parseDouble(txt4.getText()) == 829275){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 5: JPanel panel5 = new JPanel(); JLabel lbl5 = new JLabel("3^4 / 68 / 59 = "); JTextField txt5 = new JTextField(10); panel5.add(lbl5); panel5.add(txt5); int selectedOption5 = JOptionPane.showOptionDialog(null, panel5, "Question No. 5: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption5 == 0){ if (Double.parseDouble(txt5.getText()) == 0.02){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 6: JPanel panel6 = new JPanel(); JLabel lbl6 = new JLabel("cos(56) + 64 = "); JTextField txt6 = new JTextField(10); panel6.add(lbl6); panel6.add(txt6); int selectedOption6 = JOptionPane.showOptionDialog(null, panel6, "Question No. 6: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption6 == 0){ if (Double.parseDouble(txt6.getText()) == 64.55){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 7: JPanel panel7 = new JPanel(); JLabel lbl7 = new JLabel("sin(89)^2 = "); JTextField txt7 = new JTextField(10); panel7.add(lbl7); panel7.add(txt7); int selectedOption7 = JOptionPane.showOptionDialog(null, panel7, "Question No. 7: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption7 == 0){ if (Double.parseDouble(txt7.getText()) == 0.99){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 8: JPanel panel8 = new JPanel(); JLabel lbl8 = new JLabel("tan(89) + sin(89) = "); JTextField txt8 = new JTextField(10); panel8.add(lbl8); panel8.add(txt8); int selectedOption8 = JOptionPane.showOptionDialog(null, panel8, "Question No. 8: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption8 == 0){ if (Double.parseDouble(txt8.getText()) == 58.28){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 9: JPanel panel9 = new JPanel(); JLabel lbl9 = new JLabel("8 square root(68)^2 + 5 = "); JTextField txt9 = new JTextField(10); panel9.add(lbl9); panel9.add(txt9); int selectedOption9 = JOptionPane.showOptionDialog(null, panel9, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption9 == 0){ if (Double.parseDouble(txt9.getText()) == 243.28){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 10: JPanel panel10 = new JPanel(); JLabel lbl10 = new JLabel("sin(89) + 6 square root(5)^2 = "); JTextField txt10 = new JTextField(10); panel10.add(lbl10); panel10.add(txt10); int selectedOption10 = JOptionPane.showOptionDialog(null, panel10, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption10 == 0){ if (Double.parseDouble(txt10.getText()) == 30.99){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 11: JPanel panel11 = new JPanel(); JLabel lbl11 = new JLabel("56^2 + 56^2 / 69 = "); JTextField txt11 = new JTextField(10); panel11.add(lbl11); panel11.add(txt11); int selectedOption11 = JOptionPane.showOptionDialog(null, panel11, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption11 == 0){ if (Double.parseDouble(txt11.getText()) == 3181.44){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 12: JPanel panel12 = new JPanel(); JLabel lbl12 = new JLabel("89 + tan(65) = "); JTextField txt12 = new JTextField(10); panel12.add(lbl12); panel12.add(txt12); int selectedOption12 = JOptionPane.showOptionDialog(null, panel12, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption12 == 0){ if (Double.parseDouble(txt12.getText()) == 91.14){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; case 13: JPanel panel13 = new JPanel(); JLabel lbl13 = new JLabel("56 + 79^2 + 69^3 = "); JTextField txt13 = new JTextField(10); panel13.add(lbl13); panel13.add(txt13); int selectedOption13 = JOptionPane.showOptionDialog(null, panel13, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption13 == 0){ if (Integer.parseInt(txt13.getText()) == 334806){ XScore.setText(String.valueOf(xCount+=1)); if (Integer.parseInt(XLR.getText()) == 5){ XLR.setText(String.valueOf(XLife = 5)); }else { XLR.setText(String.valueOf(XLife+=1)); } random++; }else { XScore.setText(String.valueOf(xCount-=1)); XLR.setText(String.valueOf(XLife-=1)); random++; } } break; } } private static void oHardQuestions(){ String[] options = {"OK"}; switch (random){ case 1: JPanel panel = new JPanel(); JLabel lbl = new JLabel("5 + (-24) + 3 square root(64) = "); JTextField txt = new JTextField(10); panel.add(lbl); panel.add(txt); int selectedOption = JOptionPane.showOptionDialog(null, panel, "Question No. 1: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if(selectedOption == 0) { if (Integer.parseInt(txt.getText()) == 5){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else{ OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 2: JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel("52 / 5 + 89 - 3 square root(6)^2 = "); JTextField txt2 = new JTextField(10); panel2.add(lbl2); panel2.add(txt2); int selectedOption2 = JOptionPane.showOptionDialog(null, panel2, "Question No. 2: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption2 == 0){ if (Double.parseDouble(txt2.getText()) == 81.40){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 3: JPanel panel3 = new JPanel(); JLabel lbl3 = new JLabel("4^5 * 6 + 89 + square root(6)^5 = "); JTextField txt3 = new JTextField(10); panel3.add(lbl3); panel3.add(txt3); int selectedOption3 = JOptionPane.showOptionDialog(null, panel3, "Question No. 3: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption3 == 0){ if (Double.parseDouble(txt3.getText()) == 157.21){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 4: JPanel panel4 = new JPanel(); JLabel lbl4 = new JLabel("75(89^2 + 56^2) = "); JTextField txt4 = new JTextField(10); panel4.add(lbl4); panel4.add(txt4); int selectedOption4 = JOptionPane.showOptionDialog(null, panel4, "Question No. 4: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption4 == 0){ if (Integer.parseInt(txt4.getText()) == 829275){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 5: JPanel panel5 = new JPanel(); JLabel lbl5 = new JLabel("3^4 / 68 / 59 = "); JTextField txt5 = new JTextField(10); panel5.add(lbl5); panel5.add(txt5); int selectedOption5 = JOptionPane.showOptionDialog(null, panel5, "Question No. 5: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption5 == 0){ if (Double.parseDouble(txt5.getText()) == 0.02){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 6: JPanel panel6 = new JPanel(); JLabel lbl6 = new JLabel("cos(56) + 64 = "); JTextField txt6 = new JTextField(10); panel6.add(lbl6); panel6.add(txt6); int selectedOption6 = JOptionPane.showOptionDialog(null, panel6, "Question No. 6: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption6 == 0){ if (Double.parseDouble(txt6.getText()) == 64.55){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 7: JPanel panel7 = new JPanel(); JLabel lbl7 = new JLabel("sin(89)^2 = "); JTextField txt7 = new JTextField(10); panel7.add(lbl7); panel7.add(txt7); int selectedOption7 = JOptionPane.showOptionDialog(null, panel7, "Question No. 7: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption7 == 0){ if (Double.parseDouble(txt7.getText()) == 0.99){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 8: JPanel panel8 = new JPanel(); JLabel lbl8 = new JLabel("tan(89) + sin(89) = "); JTextField txt8 = new JTextField(10); panel8.add(lbl8); panel8.add(txt8); int selectedOption8 = JOptionPane.showOptionDialog(null, panel8, "Question No. 8: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption8 == 0){ if (Double.parseDouble(txt8.getText()) == 58.28){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 9: JPanel panel9 = new JPanel(); JLabel lbl9 = new JLabel("8 square root(68)^2 + 5 ="); JTextField txt9 = new JTextField(10); panel9.add(lbl9); panel9.add(txt9); int selectedOption9 = JOptionPane.showOptionDialog(null, panel9, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption9 == 0){ if (Double.parseDouble(txt9.getText()) == 243.28){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 10: JPanel panel10 = new JPanel(); JLabel lbl10 = new JLabel("sin(89) + 6 square root(5)^2 = "); JTextField txt10 = new JTextField(10); panel10.add(lbl10); panel10.add(txt10); int selectedOption10 = JOptionPane.showOptionDialog(null, panel10, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption10 == 0){ if (Double.parseDouble(txt10.getText()) == 30.99){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 11: JPanel panel11 = new JPanel(); JLabel lbl11 = new JLabel("56^2 + 56^2 / 69 = "); JTextField txt11 = new JTextField(10); panel11.add(lbl11); panel11.add(txt11); int selectedOption11 = JOptionPane.showOptionDialog(null, panel11, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption11 == 0){ if (Double.parseDouble(txt11.getText()) == 3181.44){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 12: JPanel panel12 = new JPanel(); JLabel lbl12 = new JLabel("89 + tan(65) = "); JTextField txt12 = new JTextField(10); panel12.add(lbl12); panel12.add(txt12); int selectedOption12 = JOptionPane.showOptionDialog(null, panel12, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption12 == 0){ if (Double.parseDouble(txt12.getText()) == 91.14){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; case 13: JPanel panel13 = new JPanel(); JLabel lbl13 = new JLabel("56 + 79^2 + 69^3 = "); JTextField txt13 = new JTextField(10); panel13.add(lbl13); panel13.add(txt13); int selectedOption13 = JOptionPane.showOptionDialog(null, panel13, "Question No. 9: ", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options , options[0]); if (selectedOption13 == 0){ if (Integer.parseInt(txt13.getText()) == 334806){ OScore.setText(String.valueOf(oCount+=1)); if (Integer.parseInt(OLR.getText()) == 5){ OLR.setText(String.valueOf(OLife = 5)); }else { OLR.setText(String.valueOf(OLife+=1)); } random++; }else { OScore.setText(String.valueOf(oCount-=1)); OLR.setText(String.valueOf(OLife-=1)); random++; } } break; } } private static void choosePlayer(){ if (StartGame.equalsIgnoreCase("X")){ StartGame = "O"; }else { StartGame = "X"; } } private static void winningGame(){ String b1 = t1.getText(); String b2 = t2.getText(); String b3 = t3.getText(); String b4 = t4.getText(); String b5 = t5.getText(); String b6 = t6.getText(); String b7 = t7.getText(); String b8 = t8.getText(); String b9 = t9.getText(); //HORIZONTAL if (b1.equals("X") && b2.equals("X") && b3.equals("X")){ t1.setIcon(deletegrey); t2.setIcon(deletegrey); t3.setIcon(deletegrey); xCount++; gameScore(); JOptionPane.showMessageDialog(null,"PLAYER X WIN","TIC TAC TOE WINNER!", JOptionPane.INFORMATION_MESSAGE); t1.setText(""); t1.setIcon(null); t2.setText(""); t2.setIcon(null); t3.setText(""); t3.setIcon(null); t4.setText(""); t4.setIcon(null); t5.setText(""); t5.setIcon(null); t6.setText(""); t6.setIcon(null); t7.setText(""); t7.setIcon(null); t8.setText(""); t8.setIcon(null); t9.setText(""); t9.setIcon(null); StartGame = "X"; for (int i = 0; i