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.

158 lines
5.3 KiB

  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.WindowAdapter;
  6. import java.awt.event.WindowEvent;
  7. import java.util.Date;
  8. import java.util.Random;
  9. public class Tage_D extends JFrame {
  10. Icon icon1,icon2,icon3;
  11. JLabel bild1,bild2,bild3;
  12. JFrame fr = null;
  13. JPanel Panele = null;
  14. JTextField j1 = null;
  15. JTextField j2 = null;
  16. JTextField j3 = null;
  17. JTextField j4 = null;
  18. JMenuItem menuItem1 = null;
  19. JMenuItem menuItem2 = null;
  20. JMenuItem menuItem3 = null;
  21. JMenuBar bar =null;
  22. JMenu mF= null;
  23. JMenu mH = null;
  24. JMenu mI = null;
  25. public Tage_D() {
  26. fr = new JFrame("Coutinius Integration SS 2019");
  27. fr.setSize(1920,1080);
  28. fr.setFont(new Font("Helvetica", Font.PLAIN, 12));
  29. fr.setLayout(new FlowLayout());
  30. Panele = new JPanel();
  31. fr.setContentPane(Panele);
  32. bar = new JMenuBar();
  33. fr.setJMenuBar(bar);
  34. mF = new JMenu("File");
  35. mH = new JMenu("Help");
  36. mI = new JMenu("Info");
  37. bar.add(mF);
  38. bar.add(mH);
  39. bar.add(mI);
  40. menuItem1 = new JMenuItem("Hauptprogramm"); mF.add(menuItem1);
  41. menuItem2 = new JMenuItem("Exit"); mF.add(menuItem2);
  42. menuItem3 = new JMenuItem("Über"); mI.add(menuItem3);
  43. menuItem1.addActionListener(new ActionListener() {
  44. public void actionPerformed(ActionEvent ie) {
  45. try {
  46. JOptionPane.showMessageDialog(fr, "Wir wechseln zum Hauptprogramm");
  47. Main mn = new Main();
  48. fr.setVisible((false));
  49. Panele.setVisible(false);
  50. mn.fr.setVisible(true);
  51. //System.exit(0);
  52. }catch (Exception ex) {
  53. JOptionPane.showMessageDialog(null, "Fehler");
  54. }
  55. }
  56. });
  57. menuItem2.addActionListener(new ActionListener() {
  58. public void actionPerformed(ActionEvent ie) {
  59. try {
  60. System.exit(-1);
  61. }catch (Exception ex) {
  62. JOptionPane.showMessageDialog(null, "Fehler");
  63. }
  64. }
  65. });
  66. menuItem3.addActionListener(new ActionListener() {
  67. public void actionPerformed(ActionEvent ie) {
  68. try {
  69. JOptionPane.showMessageDialog(fr, "Tools entwickelt für CI 2019 Copyright by DEM Consulting");
  70. }catch (Exception ex) {
  71. JOptionPane.showMessageDialog(null, "Fehler");
  72. }
  73. }
  74. });
  75. this.fr.addWindowListener(new WindowAdapter() {
  76. public void windowClosing(WindowEvent e) {
  77. System.exit(-1);
  78. }
  79. });
  80. Date datum=new Date();
  81. int year=datum.getYear() + 1900;
  82. j1 = new JTextField("Tools von Daniel Hauch",10); j1.setEditable(false); j1.setSize(450,30); ; bar.add(j1);
  83. j2 = new JTextField("Geben Sie hier jeweils nach Auswahl: Geburtsjahr, Hohchzeitsjahr, aktuelles Jahr ein! Bsp. 1969",50); j2.setEditable(false); Panele.add(j2); j2.setSize(450,30); Panele.add(j2);
  84. j3 = new JTextField("1969",10); j3.setEditable(true); Panele.add(j2); j3.setSize(450,30); Panele.add(j3);
  85. ButtonGroup buttonGroup = new ButtonGroup();
  86. JButton szeit= new JButton("Sterbezeitpunkt Erfahren");
  87. szeit.setBounds(100, 170, 100, 20);
  88. buttonGroup.add(szeit); Panele.add(szeit);
  89. szeit.addActionListener(new ActionListener() {
  90. public void actionPerformed(ActionEvent ie) {
  91. int ergebnis, zufall, zahl, i;
  92. zahl = Integer.parseInt(j3.getText());
  93. zufall= gibZufall(zahl);
  94. while(zufall<=year){
  95. // System.out.println(zufall);
  96. zufall = gibZufall(zahl);
  97. }
  98. String resultat = new String("Sie werden im Jahre "+zufall+" möglicherweise sterben!");
  99. j4.setText(resultat);
  100. }
  101. });
  102. JButton htag = new JButton("Silber-Gold-Diamant ausrechnen");
  103. htag.setBounds(250, 170, 100, 20);
  104. buttonGroup.add(htag); Panele.add(htag);
  105. htag.addActionListener(new ActionListener() {
  106. public void actionPerformed(ActionEvent ie) {
  107. int diamant, gold, silber, zufall, zahl, i;
  108. zahl = Integer.parseInt(j3.getText());
  109. diamant=zahl+60;
  110. gold=zahl+50;
  111. silber=zahl+25;
  112. String resultat = new String("Sie werden im Jahr "+silber+" Ihre Silberhochzeit, im Jahr "+gold+" Ihre Goldene Hochzeit und im Jahr "+diamant+" Diamanten Hochzeit feiern.");
  113. j4.setText(resultat);
  114. }
  115. });
  116. j4 = new JTextField("Hier erfahren Sie Ergebnisse aus Ihrer Auswahl",98); Panele.add(j4);
  117. fr.setVisible(true);
  118. fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  119. }
  120. //Methode gibt eine ganze Zahl (int) zurück
  121. public static int gibZufall (int zahl) {
  122. Random randomGenerator = new Random();
  123. int randomInt = randomGenerator.nextInt(115) + 1;
  124. int zufall = zahl + randomInt;
  125. return zufall;
  126. }
  127. }