Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package awt;
- import java.awt.*;
- import java.awt.event.*;
- //import java.awt.event.WindowListener;
- public class AppliGridLayout extends Frame
- implements WindowListener
- {
- public AppliGridLayout() {
- super("AppliGridLayout");
- this.setLayout(new GridLayout(3,2));
- for (int i = 1; i < 7; i++)
- this.add(new Button(Integer.toString(i)));
- this.pack();
- this.setVisible(true);
- this.addWindowListener(this);
- }
- public static void main(String args[]) {
- AppliGridLayout appli = new AppliGridLayout();
- }
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- }
- ___________________________________________________________
- import java.awt.*;
- import java.awt.event.*;
- public class EssaiActionEvent2 extends Frame
- implements ActionListener {
- private Button b1,b2;
- public static void main(String args[]) {
- EssaiActionEvent2 f= new EssaiActionEvent2();
- }
- public EssaiActionEvent2(){
- super("Utilisation d’un ActionEvent");
- b1 = new Button("action1");
- b2 = new Button("action2");
- b1.addActionListener(this);
- b2.addActionListener(this);
- this.add(BorderLayout.CENTER,b1);
- this.add(BorderLayout.SOUTH,b2);
- this.pack();
- this.setVisible(true);
- }
- public void actionPerformed( ActionEvent e ) {
- if (e.getSource() == b1) setTitle("action1 cliqué");
- if (e.getSource() == b2) setTitle("action2 cliqué");
- }
- }
- _____________________________________________________________
- package awt;
- import java.awt.Button;
- import java.util.StringTokenizer;
- public class MaCalculatrice extends Frame implements ActionListener {
- Button b1,b2;
- Label l;
- TextField tf;
- public MaCalculatrice() {
- super("Calculatrice");
- this.setLayout(new GridLayout(4,1));
- l=new Label("operation");
- tf = new TextField();
- b1 = new Button("Calculer");
- b2 = new Button("Effacer");
- b1.addActionListener(this);
- b2.addActionListener(this);
- this.add(1);
- this.add(tf)
- }
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == b2)
- tf.setText("");
- else {
- String ch = tf.getText();
- String sa,sb;
- if (ch.contains("+")) {
- StringTokenizer st = new StringTokenizer(ch, "+");
- sa=st.nextToken();
- sb=st.nextToken();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement