Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. package awt;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. //import java.awt.event.WindowListener;
  5. public class AppliGridLayout extends Frame
  6. implements WindowListener
  7. {
  8.     public AppliGridLayout() {
  9.         super("AppliGridLayout");
  10.         this.setLayout(new GridLayout(3,2));
  11.         for (int i = 1; i < 7; i++)
  12.             this.add(new Button(Integer.toString(i)));
  13.         this.pack();
  14.         this.setVisible(true);
  15.         this.addWindowListener(this);
  16. }
  17. public static void main(String args[]) {
  18.         AppliGridLayout appli = new AppliGridLayout();
  19.     }
  20. public void windowClosing(WindowEvent e) {
  21. System.exit(0);
  22.  
  23.     }
  24. }
  25.  
  26. ___________________________________________________________
  27.  
  28. import java.awt.*;
  29. import java.awt.event.*;
  30. public class EssaiActionEvent2 extends Frame
  31. implements ActionListener {
  32.     private Button b1,b2;
  33.     public static void main(String args[])  {
  34.         EssaiActionEvent2 f= new EssaiActionEvent2();
  35. }
  36. public EssaiActionEvent2(){  
  37.     super("Utilisation d’un ActionEvent");
  38.     b1 = new Button("action1");
  39.     b2 = new Button("action2");
  40.     b1.addActionListener(this);
  41.     b2.addActionListener(this);
  42.     this.add(BorderLayout.CENTER,b1);
  43.     this.add(BorderLayout.SOUTH,b2);
  44.     this.pack();
  45.     this.setVisible(true);
  46. }
  47. public void actionPerformed( ActionEvent e ) {
  48.         if (e.getSource() == b1) setTitle("action1 cliqué");
  49.         if (e.getSource() == b2) setTitle("action2 cliqué");
  50.     }
  51. }
  52.  
  53.  
  54. _____________________________________________________________
  55.  
  56. package awt;
  57.  
  58. import java.awt.Button;
  59. import java.util.StringTokenizer;
  60.  
  61. public class MaCalculatrice extends Frame implements ActionListener {
  62.  
  63.     Button b1,b2;
  64.     Label l;
  65.     TextField tf;
  66.    
  67.     public MaCalculatrice() {
  68.         super("Calculatrice");
  69.         this.setLayout(new GridLayout(4,1));
  70.         l=new Label("operation");
  71.         tf = new TextField();
  72.         b1 = new Button("Calculer");
  73.         b2 = new Button("Effacer");
  74.         b1.addActionListener(this);
  75.         b2.addActionListener(this);
  76.         this.add(1);
  77.         this.add(tf)
  78.     }
  79. }
  80.  
  81.  
  82. public void actionPerformed(ActionEvent e) {
  83.     if (e.getSource() == b2)
  84.         tf.setText("");
  85.     else {
  86.         String ch = tf.getText();
  87.         String sa,sb;
  88.         if (ch.contains("+")) {
  89.             StringTokenizer st = new StringTokenizer(ch, "+");
  90.             sa=st.nextToken();
  91.             sb=st.nextToken();
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement