Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication45;
  7.  
  8. /**
  9. *
  10. * @author ZERO_POINT
  11. */
  12.  
  13. import javax.swing.*;
  14.  
  15. import java.awt.event.*;
  16.  
  17.  
  18.  
  19. public class quiz2 extends JFrame
  20.  
  21. {
  22.  
  23. private JButton anwser1;
  24.  
  25. private JButton anwser2;
  26.  
  27. private JButton anwser3;
  28. private JButton anwser4;
  29. private JPanel panel;
  30.  
  31. private JLabel messageLabel;
  32.  
  33. private JLabel messageLabel2;
  34.  
  35. private final int WINDOW_WIDTH = 300;
  36.  
  37. private final int WINDOW_HEIGHT = 120;
  38.  
  39. int c = 0;
  40.  
  41.  
  42.  
  43. public quiz2()
  44.  
  45. {
  46.  
  47. setTitle("Event Object Demonstration");
  48.  
  49.  
  50.  
  51. setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  52.  
  53.  
  54.  
  55. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56.  
  57.  
  58.  
  59. messageLabel = new JLabel("What program language is this written in");
  60.  
  61.  
  62.  
  63. anwser1 = new JButton("C++");
  64.  
  65. anwser2 = new JButton("Java");
  66.  
  67. anwser3 = new JButton("Unix");
  68.  
  69. anwser4 = new JButton("Pearl");
  70.  
  71.  
  72.  
  73.  
  74. anwser1.addActionListener(new ButtonListener());
  75.  
  76. anwser2.addActionListener(new ButtonListener());
  77.  
  78. anwser3.addActionListener(new ButtonListener());
  79.  
  80. anwser4.addActionListener(new ButtonListener());
  81.  
  82.  
  83.  
  84. panel = new JPanel();
  85.  
  86. panel.add(messageLabel);
  87.  
  88. panel.add(anwser1);
  89.  
  90. panel.add(anwser2);
  91.  
  92. panel.add(anwser3);
  93.  
  94. panel.add(anwser4);
  95.  
  96.  
  97.  
  98. add(panel);
  99.  
  100.  
  101. setVisible(true);
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. setTitle("Event Object Demonstration");
  110.  
  111.  
  112.  
  113. setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  114.  
  115.  
  116.  
  117. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  118.  
  119.  
  120.  
  121. messageLabel = new JLabel("What is 2 + 3");
  122.  
  123.  
  124.  
  125. anwser1 = new JButton("5");
  126.  
  127. anwser2 = new JButton("19");
  128.  
  129. anwser3 = new JButton("1");
  130.  
  131. anwser4 = new JButton("6");
  132.  
  133.  
  134.  
  135.  
  136.  
  137. anwser1.addActionListener(new ButtonListener());
  138.  
  139. anwser2.addActionListener(new ButtonListener());
  140.  
  141. anwser3.addActionListener(new ButtonListener());
  142.  
  143. anwser4.addActionListener(new ButtonListener());
  144.  
  145.  
  146.  
  147. panel = new JPanel();
  148.  
  149. panel.add(messageLabel);
  150.  
  151. panel.add(anwser1);
  152.  
  153. panel.add(anwser2);
  154.  
  155. panel.add(anwser3);
  156.  
  157. panel.add(anwser4);
  158.  
  159.  
  160.  
  161. add(panel);
  162.  
  163.  
  164.  
  165. setVisible(true);
  166.  
  167. }
  168.  
  169.  
  170.  
  171.  
  172.  
  173. private class ButtonListener implements ActionListener
  174.  
  175. {
  176.  
  177. public void actionPerformed(ActionEvent e)
  178.  
  179. {
  180.  
  181.  
  182.  
  183. String actionCommand = e.getActionCommand();
  184.  
  185.  
  186.  
  187. if (actionCommand.equals("C++"))
  188.  
  189. {
  190.  
  191. JOptionPane.showMessageDialog(null, "Wrong");
  192.  
  193.  
  194.  
  195. }
  196.  
  197. else if (actionCommand.equals("Java"))
  198.  
  199. {
  200.  
  201. JOptionPane.showMessageDialog(null, "Correct");
  202.  
  203. c++;
  204.  
  205.  
  206.  
  207. }
  208.  
  209. else if (actionCommand.equals("Unix"))
  210.  
  211. {
  212.  
  213. JOptionPane.showMessageDialog(null, "Wrong");
  214.  
  215.  
  216.  
  217. }
  218.  
  219. else if (actionCommand.equals("Pearl"))
  220.  
  221. {
  222.  
  223. JOptionPane.showMessageDialog(null, "Wrong");
  224.  
  225. }
  226.  
  227.  
  228.  
  229.  
  230.  
  231. JOptionPane.showMessageDialog(null, c + "Correct out of 1" + 100 * c/1 + "%" );
  232.  
  233. JOptionPane.showMessageDialog(null, 100 * c/1 + "%");
  234.  
  235.  
  236.  
  237. }
  238.  
  239.  
  240.  
  241. }
  242.  
  243.  
  244.  
  245. public static void main(String[] args)
  246.  
  247. {
  248.  
  249. quiz2 eow = new quiz2();
  250.  
  251.  
  252.  
  253. }
  254.  
  255.  
  256.  
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement