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.

152 lines
3.4 KiB

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