Guest User

Untitled

a guest
Jan 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. public class p1{
  4. Frame f;
  5. TextField t1,t2,t3;
  6. Button btnplus;
  7. p1(){
  8. f=new Frame("Button Example");
  9.  
  10. t1=new TextField("");
  11. t1.setBounds(50,100, 200,30);
  12. t2=new TextField("");
  13. t2.setBounds(50,150, 200,30);
  14.  
  15. t3=new TextField("");
  16. t3.setBounds(50,200, 200,30);
  17.  
  18. f.add(t1); f.add(t2); f.add(t3);
  19. btnplus= new Button("+");
  20. btnplus.setBounds(50,250, 50,30);
  21. f.add(btnplus);
  22. f.setSize(400,400);
  23. f.setLayout(null);
  24. f.setVisible(true);
  25. f.addWindowListener( new WindowListener(){
  26. public void windowClosed(WindowEvent e)
  27. {
  28.  
  29. }
  30. public void windowDeactivated(WindowEvent e)
  31. {
  32. }
  33. public void windowActivated(WindowEvent e)
  34. {
  35. }
  36. public void windowClosing(WindowEvent e)
  37. {
  38. f.dispose();
  39. }
  40. public void windowDeiconified(WindowEvent e)
  41. {
  42. }
  43. public void windowIconified(WindowEvent e)
  44. {
  45. }
  46. public void windowOpened(WindowEvent e)
  47. {
  48. }
  49. });
  50.  
  51.  
  52. btnplus.addMouseListener(new MouseListener(){
  53. public void mouseClicked(MouseEvent e)
  54. {
  55. //t1.setText("agsdfgds");
  56. int a=0,b=0,ans=0;
  57. a= Integer.valueOf(t1.getText());
  58. b= Integer.valueOf(t2.getText());
  59. ans=a+b;
  60. t3.setText(String.valueOf(ans));
  61. }
  62. public void mouseEntered(MouseEvent e)
  63. {
  64.  
  65. }
  66. public void mouseExited(MouseEvent e)
  67. {
  68.  
  69. }
  70. public void mousePressed(MouseEvent e)
  71. {
  72.  
  73. }
  74. public void mouseReleased(MouseEvent e)
  75. {
  76.  
  77.  
  78. }
  79.  
  80. });
  81. }
  82.  
  83.  
  84.  
  85. public static void main(String args[])
  86. {
  87. new p1();
  88. }
  89.  
  90. }
Add Comment
Please, Sign In to add comment