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.0 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(500,500);
  32. fr.setFont(new Font("Helvetica", Font.PLAIN, 12));
  33. fr.setLayout(new FlowLayout());
  34. Panele = new JPanel();
  35. fr.setContentPane(Panele);
  36. Date datum=new Date();
  37. int year=datum.getYear() + 1900;
  38. bar = new JMenuBar();
  39. fr.setJMenuBar(bar);
  40. mF = new JMenu("File");
  41. mH = new JMenu("Help");
  42. mI = new JMenu("Info");
  43. bar.add(mF);
  44. bar.add(mH);
  45. bar.add(mI);
  46. menuItem1 = new JMenuItem("Exit"); mF.add(menuItem1);
  47. menuItem2 = new JMenuItem("Über"); mI.add(menuItem2);
  48. menuItem2.addActionListener(new ActionListener() {
  49. public void actionPerformed(ActionEvent ie) {
  50. try {
  51. JOptionPane.showMessageDialog(fr, "Tools entwickelt für CI 2019 Copyright by DEM Consulting");
  52. }catch (Exception ex) {
  53. JOptionPane.showMessageDialog(null, "Fehler");
  54. }
  55. }
  56. });
  57. this.fr.addWindowListener(new WindowAdapter() {
  58. public void windowClosing(WindowEvent e) {
  59. System.exit(-1);
  60. }
  61. });
  62. fr.setContentPane(Panele);
  63. /*
  64. icon1 = new ImageIcon(getClass().getResource("bild1.jpg")); bild1 = new JLabel(icon1); fr.add(icon1);
  65. icon2 = new ImageIcon(getClass().getResource("bild2.jpg")); bild2 = new JLabel(icon2); fr.add(icon2);
  66. icon3 = new ImageIcon(getClass().getResource("bild3.gif")); bild3 = new JLabel(icon3); fr.add(icon3);
  67. */
  68. j1 = new JTextField("Tools von Daniel Hauch"); j1.setEditable(false); j1.setSize(450,30); ; Panele.add(j1);
  69. j2 = new JTextField("Geben Sie hier jeweils nach Auswahl: Geburtsjahr, Hohchzeitsjahr, aktuelles Jahr ein!"); j2.setEditable(false); Panele.add(j2); j2.setSize(450,30); Panele.add(j2);
  70. j3 = new JTextField("Bsp. 1966"); j3.setEditable(true); Panele.add(j2); j3.setSize(450,30); Panele.add(j3);
  71. j4 = new JTextField("Hier erfahren Sie Ergebnisse aus Ihrer Auswahl"); Panele.add(j4);
  72. ButtonGroup buttonGroup = new ButtonGroup();
  73. JButton szeit= new JButton("Sterbezeitpunkt Erfahren");
  74. szeit.setBounds(100, 170, 100, 20);
  75. buttonGroup.add(szeit); Panele.add(szeit);
  76. szeit.addActionListener(new ActionListener() {
  77. public void actionPerformed(ActionEvent ie) {
  78. Random randomGenerator = new Random();
  79. int randomInt = randomGenerator.nextInt(50) + 1;
  80. int zahl = Integer.parseInt(j3.getText());
  81. int zufall = zahl + randomInt;
  82. if(zufall<=year){
  83. zufall = zahl + randomInt;
  84. String resultat = new String("Sie werden in "+zufall+" Jahren möglicherweise sterben!");
  85. j4.setText(resultat);
  86. }else{
  87. String resultat = new String("Sie werden in "+zufall+" Jahren möglicherweise sterben!");
  88. j4.setText(resultat);
  89. }
  90. }
  91. });
  92. JButton gtag = new JButton("zufälliges Alter ausrechnen");
  93. gtag.setBounds(250, 170, 100, 20);
  94. buttonGroup.add(gtag); Panele.add(gtag);
  95. gtag.addActionListener(new ActionListener() {
  96. public void actionPerformed(ActionEvent ie) {
  97. Random randomGenerator = new Random();
  98. int randomInt = randomGenerator.nextInt(50) + 1;
  99. int zahl = Integer.parseInt(j3.getText());
  100. int zufall = zahl + randomInt;
  101. if(zufall<=year){
  102. String resultat = new String("Sie werden in "+zufall+" Jahren möglicherweise sterben!");
  103. j4.setText(resultat);
  104. }else{
  105. String resultat = new String("Test in "+zufall+" Jahren möglicherweise sterben!");
  106. j4.setText(resultat);
  107. }
  108. }
  109. });
  110. final JTextField text1 = new JTextField("");
  111. text1.setBounds(100, 200, 300, 20);
  112. Panele.add(text1);
  113. fr.setVisible(true);
  114. fr.setAlwaysOnTop(true);
  115. fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  116. }
  117. }