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.

167 lines
5.1 KiB

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