CI 2019 von Daniel, Eugen und Michael
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.1 KiB

  1. import javax.swing.*;
  2. import javax.swing.JFrame;
  3. import javax.swing.JPanel;
  4. import java.util.Random;
  5. import javax.swing.JOptionPane;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. public class Quiz extends JFrame {
  9. JFrame fr = null;
  10. JPanel contentPane = null;
  11. JButton button1 = null;
  12. JTextField j1 = null;
  13. JLabel label1 = null;
  14. JLabel label2 = null;
  15. JLabel label3 = null;
  16. JLabel frage1 = null;
  17. JLabel frage1antworten = null;
  18. JMenuItem menuItem1 = null;
  19. JMenuItem menuItem2 = null;
  20. JMenuBar bar =null;
  21. JMenu mF= null;
  22. JMenu mH = null;
  23. int button1warsovielmalgedrückt = 0;
  24. public Quiz() {
  25. this.fr = new JFrame("GUI");
  26. this.fr.setSize(430, 630);
  27. this.contentPane = new JPanel();
  28. this.fr.setContentPane(this.contentPane);
  29. this.bar = new JMenuBar();
  30. this.fr.setJMenuBar(bar);
  31. this.mF = new JMenu("File");
  32. this.mH = new JMenu("Help");
  33. this.bar.add(mF);
  34. this.bar.add(mH);
  35. this.menuItem1 = new JMenuItem("Exit");
  36. this.mF.add(menuItem1);
  37. this.menuItem1.addActionListener(new CloseListener());
  38. this.menuItem2 = new JMenuItem("Info");
  39. this.mH.add(menuItem2);
  40. this.menuItem2.addActionListener(new CloseListener3());
  41. this.label1 = new JLabel("Herzlich willkommen zu unserem Quiz!");
  42. this.contentPane.add(label1);
  43. this.label2 = new JLabel("Beantworten Sie uns 5 kurze Fragen und gewinnen Sie 10000 Euro!");
  44. this.contentPane.add(label2);
  45. this.frage1 = new JLabel("Frage 1 lautet: Was gehört nicht zum Test Driven Developement?");
  46. this.contentPane.add(frage1);
  47. this.frage1antworten = new JLabel("A : Refactoring B : Transformation C : Clean Code D : Neuer Test ");
  48. this.contentPane.add(frage1antworten);
  49. this.label3 = new JLabel("Antwort:");
  50. this.contentPane.add(label3);
  51. this.j1 = new JTextField("", 20);
  52. this.contentPane.add(j1);
  53. this.j1.setSize(250,30);;
  54. this.button1 = new JButton("Prüfen");
  55. this.contentPane.add(button1);
  56. this.button1.addActionListener(new CloseListener2());
  57. this.fr.setVisible(true);
  58. }
  59. public static void main(String[] args) {
  60. Quiz g = new Quiz();
  61. }
  62. private class CloseListener implements ActionListener{
  63. @Override
  64. public void actionPerformed(ActionEvent e) {
  65. System.exit(0);
  66. }
  67. }
  68. public class CloseListener2 implements ActionListener{
  69. @Override
  70. public void actionPerformed(ActionEvent a) {
  71. button1warsovielmalgedrückt++;
  72. if(j1.getText().startsWith("C") || j1.getText().startsWith("c") ) {
  73. System.out.println("ja");
  74. j1.setText("Richtig ! Gewinn 1000 Euro");
  75. button1warsovielmalgedrückt++;
  76. }else{
  77. System.out.println("nein");
  78. j1.setText("Falsch geantwortet! ");
  79. }
  80. }
  81. }
  82. public class CloseListener3 implements ActionListener{
  83. @Override
  84. public void actionPerformed(ActionEvent a) {
  85. System.out.println("Hier sollen Sie Info bekommen");
  86. }
  87. }
  88. }