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.

127 lines
4.0 KiB

  1. import javax.swing.*;
  2. import java.awt.BorderLayout;
  3. import java.awt.Color;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.KeyAdapter;
  7. import java.awt.event.KeyEvent;
  8. public class FitnessTest_M extends JFrame {
  9. JFrame frame = null;
  10. JPanel panel_1 = null;
  11. JButton button_1 = null;
  12. JTextField field_1 = null;
  13. JMenuItem menuItem_1 = null;
  14. JMenuBar menuBar = null;
  15. JMenu menu = null;
  16. JLabel height_label = null;
  17. JTextField height_tf = null;
  18. JLabel weight_label = null;
  19. JTextField weight_tf = null;
  20. JLabel height_ungueltig = null;
  21. JLabel weight_ungueltig = null;
  22. JButton bmi_rechnen = null;
  23. public FitnessTest_M() {
  24. frame = new JFrame("Fitness Test");
  25. frame.setLayout(null);
  26. frame.setSize(1920, 1080);
  27. // panel_1 = new JPanel(new BorderLayout());
  28. // frame.setContentPane(panel_1);
  29. menuBar = new JMenuBar();
  30. frame.setJMenuBar(menuBar);
  31. menu = new JMenu("Option");
  32. menuItem_1 = new JMenuItem("Exit");
  33. menuBar.add(menu);
  34. menu.add(menuItem_1);
  35. menuItem_1.addActionListener(new ActionListener() {
  36. public void actionPerformed(ActionEvent a) {
  37. if(a.getSource() == menuItem_1) {
  38. System.exit(0);
  39. }
  40. }
  41. });
  42. height_ungueltig = new JLabel();
  43. height_ungueltig.setForeground(Color.red);
  44. height_label = new JLabel("Geben sie hier ihre Koerpergroesse ein (in Meter)");
  45. height_label.setBounds(10, 10, 280, 30);
  46. //panel_1.add(height_label);
  47. height_tf = new JTextField(40);
  48. height_tf.setBounds(10, 40, 280, 30);
  49. height_tf.addKeyListener(new KeyAdapter() {
  50. @Override
  51. public void keyPressed(KeyEvent e) {
  52. try {
  53. float height = Float.parseFloat(height_tf.getText());
  54. height_ungueltig.setText("");
  55. } catch (NumberFormatException e1) {
  56. height_ungueltig.setText("Ungueltige Nummer");
  57. height_ungueltig.setBounds(10, 70, 280, 20);
  58. }
  59. }
  60. });
  61. // panel_1.add(height_tf);
  62. weight_ungueltig = new JLabel();
  63. weight_ungueltig.setForeground(Color.red);
  64. weight_label = new JLabel("Geben sie hier ihr Gewicht ein (in Kilogramm)");
  65. weight_label.setBounds(320, 10, 300, 30);
  66. // panel_1.add(weight_label);
  67. weight_tf = new JTextField(40);
  68. weight_tf.setBounds(320, 40, 300, 30);
  69. weight_tf.addKeyListener(new KeyAdapter() {
  70. @Override
  71. public void keyPressed(KeyEvent w) {
  72. try {
  73. float weight = Float.parseFloat(weight_tf.getText());
  74. weight_ungueltig.setText("");
  75. } catch (NumberFormatException w1) {
  76. weight_ungueltig.setText("Ungueltige Nummer");
  77. weight_ungueltig.setBounds(320, 70, 300, 20);
  78. }
  79. }
  80. });
  81. // panel_1.add(weight_tf);
  82. frame.add(height_label);
  83. frame.add(height_tf);
  84. frame.add(height_ungueltig);
  85. frame.add(weight_label);
  86. frame.add(weight_tf);
  87. frame.add(weight_ungueltig);
  88. bmi_rechnen = new JButton("BMI berechnen");
  89. bmi_rechnen.setBounds(200, 90, 200, 30);
  90. bmi_rechnen.addActionListener(new ActionListener() {
  91. public void actionPerformed(ActionEvent b) {
  92. if(b.getSource() == bmi_rechnen) {
  93. float height = Float.parseFloat(height_tf.getText());
  94. float weight = Float.parseFloat(weight_tf.getText());
  95. int bmi = (int) (weight / (height*height));
  96. System.out.println(bmi);
  97. }
  98. }
  99. });
  100. frame.add(bmi_rechnen);
  101. frame.setVisible(true);
  102. }
  103. public static void main(String[] args) {
  104. FitnessTest_M M = new FitnessTest_M();
  105. }
  106. }