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.

164 lines
3.5 KiB

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