Full width home advertisement

HTML

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.  
  7. package pkgApplet;
  8.  
  9. import java.applet.Applet;
  10. import java.awt.Button;
  11. import java.awt.GridLayout;
  12. import java.awt.Label;
  13. import java.awt.TextField;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16.  
  17. /**
  18.  *
  19.  * @author smit
  20.  */
  21. public class pr14 extends Applet implements ActionListener {
  22. Button b1,b2;
  23. TextField t1,t2,t3;
  24. Label l1,l2,l3;
  25.  
  26. /**
  27.   * Initialization method that will be called after the applet is loaded into
  28.   * the browser.
  29.   */
  30. public void init() {
  31. // TODO start asynchronous download of heavy resources
  32. b1=new Button("ADD");
  33. b2=new Button("SUB");
  34. l1=new Label("No1");
  35. l2=new Label("No2");
  36. l3=new Label("Ans");
  37. t1=new TextField();
  38. t2=new TextField();
  39. t3=new TextField();
  40. setLayout(new GridLayout(4,1));
  41.  
  42. add(l1); add(t1);
  43. add(l2); add(t2);
  44. add(b1); add(b2);
  45. add(l3); add(t3);
  46.  
  47.  
  48. b1.addActionListener(this);
  49. b2.addActionListener(this);
  50. }
  51.  
  52. public void actionPerformed(ActionEvent e){
  53. int n1,n2,ans;
  54. n1=Integer.parseInt(t1.getText());
  55. n2=Integer.parseInt(t2.getText());
  56. if(e.getSource()==b1){
  57. ans=n1+n2;
  58. t3.setText("addition is: "+ans);
  59. }
  60. if(e.getSource()==b2){
  61. ans=n1-n2;
  62. t3.setText("substraction is: "+ans);
  63. }
  64. }
  65. // TODO overwrite start(), stop() and destroy() methods
  66. }
  67.  

No comments:

Post a Comment

Bottom Ad [Post Page]