Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JTextField;
  7.  
  8.  
  9. class Kaloriak extends JFrame {
  10.  
  11. JLabel felMag;
  12. JLabel felSuly;
  13. JLabel felKor;
  14. JButton gomb;
  15. JTextField mag;
  16. JTextField suly;
  17. JTextField kor;
  18. JTextField kaloria;
  19.  
  20.  
  21.  
  22. Kaloriak() {
  23. setSize(250,400);
  24. setLocationRelativeTo(null);
  25. setResizable(false);
  26. felMag = new JLabel("Magassag(cm)");
  27. felSuly = new JLabel("Suly(kg)");
  28. felKor = new JLabel("Kor");
  29. mag = new JTextField();
  30. suly = new JTextField();
  31. kor = new JTextField();
  32. kaloria = new JTextField();
  33. gomb = new JButton("Kalkulalas");
  34.  
  35. felMag.setBounds(10, 10, 100, 15);
  36. felSuly.setBounds(10,50, 100, 15);
  37. felKor.setBounds(10,90,100,15);
  38. mag.setBounds(10,25,100,15);
  39. suly.setBounds(10,65,100,15);
  40. kor.setBounds(10, 105, 100, 15);
  41. kaloria.setBounds(65,250,100,15);
  42. gomb.setBounds(65, 265, 100, 15);
  43.  
  44. add(mag);
  45. add(suly);
  46. add(kor);
  47. add(kaloria);
  48. add(felMag);
  49. add(felSuly);
  50. add(felKor);
  51. add(gomb);
  52.  
  53. gomb.addActionListener(new gomb_Click());
  54. setLayout(null);
  55. setVisible(true);
  56. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57.  
  58.  
  59. }
  60.  
  61. class gomb_Click implements ActionListener
  62.  
  63. {
  64.  
  65. public void actionPerformed(ActionEvent e){
  66. String strmag = mag.getText();
  67. int intmag = Integer.parseInt(strmag);
  68. String strsuly = suly.getText();
  69. int intsuly = Integer.parseInt(strsuly);
  70. String strkor = kor.getText();
  71. int intkor = Integer.parseInt(strkor);
  72. int eredmeny = 10*intsuly+6*intmag-5*intkor;
  73. kaloria.setText(Integer.toString(eredmeny));
  74. }
  75. }
  76.  
  77. public static void main(String[] args) {
  78. new Kaloriak();
  79. }
  80.  
  81.  
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement