Full width home advertisement

Java

Tech News

Ad

  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package pkgApplet;
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10.  
  11. /**
  12.  *
  13.  * @author DELL
  14.  */
  15. class MyDlg extends Dialog implements ActionListener {
  16.  
  17. Label l1, l2, l3, l4;
  18. Button Exit;
  19.  
  20. public MyDlg(Frame f, int Sum, int Sub, int Mul, int Div) {
  21. super(f);
  22. setLayout(new GridLayout(6, 1));
  23. l1 = new Label(null);
  24. l2 = new Label(null);
  25. l3 = new Label(null);
  26. l4 = new Label(null);
  27.  
  28. l1.setText("sum: " + Sum);
  29. l2.setText("Substrction: " + Sub);
  30. l3.setText("Multiplicaction: " + Mul);
  31. l4.setText("Dividion: " + Div);
  32.  
  33. Exit = new Button("Exit");
  34. Exit.addActionListener(this);
  35. add(l1);
  36. add(l2);
  37. add(l3);
  38. add(l4);
  39. add(Exit);
  40. setSize(150, 150);
  41. setVisible(true);
  42. Exit.addActionListener(this);
  43. addWindowListener(new WindowAdapter() {
  44. public void windowClosing(WindowEvent e) {
  45. dispose();
  46. }
  47. });
  48. }
  49.  
  50. public void actionPerformed(ActionEvent e) {
  51. if (e.getSource() == Exit) {
  52. dispose();
  53. }
  54. }
  55.  
  56. }
  57.  
  58. public class PR26 extends Frame implements ActionListener {
  59.  
  60. TextField t1, t2;
  61. Button b;
  62. Label l1, l2;
  63. int Sum, Sub, Div, Mul;
  64.  
  65. public PR26() {
  66. setLayout(new GridLayout(5, 1));
  67. l1 = new Label("Enter Number1: ");
  68. l2 = new Label("Enter Number2: ");
  69. b = new Button("Ans");
  70. t1 = new TextField();
  71. t2 = new TextField();
  72.  
  73. add(l1);
  74. add(t1);
  75. add(l2);
  76. add(t2);
  77. add(b);
  78.  
  79. b.addActionListener(this);
  80. setVisible(true);
  81. setSize(600, 600);
  82.  
  83. addWindowListener(new WindowAdapter() {
  84. public void windowClosing(WindowEvent e) {
  85. dispose();
  86. }
  87. });
  88. }
  89.  
  90. public void actionPerformed(ActionEvent e) {
  91. int tmp1, tmp2;
  92.  
  93. tmp1 = Integer.parseInt(t1.getText());
  94. tmp2 = Integer.parseInt(t2.getText());
  95. Sum = tmp1 + tmp2;
  96. Sub = tmp1 - tmp2;
  97. Mul = tmp1 * tmp2;
  98. Div = tmp1 / tmp2;
  99.  
  100. new MyDlg(this, Sum, Sub, Mul, Div);
  101. }
  102.  
  103. public static void main(String[] args) {
  104. PR26 ob = new PR26();
  105. }
  106. }

No comments:

Post a Comment

Bottom Ad [Post Page]