Overblog
Suivre ce blog Administration + Créer mon blog
25 octobre 2022 2 25 /10 /octobre /2022 09:53
Pins Java

Pins Java

Partager cet article
Repost0
28 janvier 2009 3 28 /01 /janvier /2009 17:02

14.6 The Empty Statement

An empty statement does nothing.

 

  EmptyStatement: ;   

Execution of an empty statement always completes normally.


// Un extrait - comment le qualifieriez-vous ? - de la documentation Java...

 
Partager cet article
Repost0
13 janvier 2009 2 13 /01 /janvier /2009 16:25

 

public class Foo2 {

JFrame cadre;

JButton btn1;

JButton btn2;

JLabel lbl;

Container cadreCtnr;


void go() {

cadre = new JFrame();

cadre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

cadre.setSize(400, 300);


btn1 = new JButton("btn1");

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

lbl.setText("btn1 click !");

}

});


btn2 = new JButton("btn2");

btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

lbl.setText("btn1 click !");

}

});


lbl = new JLabel();


cadreCtnr = cadre.getContentPane();

cadreCtnr.setLayout(new BoxLayout(cadreCtnr, 1));

cadreCtnr.add(btn1);

cadreCtnr.add(btn2);

cadreCtnr.add(lbl);

cadre.setVisible(true);

}


}


// Les 2 classes internes sont ici devenues anonymes.

// ActionListener est une interface.

// Peut-être a-t-on déjà vu constructions plus claires, Mr James G. ;-))
// Tiens, où est passée l'indentation;-))

Partager cet article
Repost0
10 janvier 2009 6 10 /01 /janvier /2009 14:06

public class Foo {

    JFrame cadre;

    JButton btn1;

    JButton btn2;

    JLabel lbl;

    Container cadreCtnr;

 

    void go() {

        cadre = new JFrame();

        cadre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        cadre.setSize(400, 300);

 

        btn1 = new JButton("btn1");

        btn1.addActionListener(new Btn1Listener());

 

        btn2 = new JButton("btn2");

        btn2.addActionListener(new Btn2Listener());

 

        lbl = new JLabel();

 

        cadreCtnr = cadre.getContentPane();

        cadreCtnr.setLayout(new BoxLayout(cadreCtnr, 1));

        cadreCtnr.add(btn1);

        cadreCtnr.add(btn2);

        cadreCtnr.add(lbl);

        cadre.setVisible(true);

    }

 

    class Btn1Listener implements ActionListener {

        public void actionPerformed(ActionEvent event) {

            lbl.setText("btn1 click !");

        }

    }

 

    class Btn2Listener implements ActionListener {

        public void actionPerformed(ActionEvent event) {

            lbl.setText("btn2 click !");

        }

    }

 

}

// Une classe peut en cacher une autre...
// Ici, deux classes internes.

Partager cet article
Repost0
5 janvier 2009 1 05 /01 /janvier /2009 12:48

Catégorie Java = new Catégorie() ;-))


L'haddockumentation Sun

public class PetiteClasse {


}

// Classe un peu minimaliste !

 


* * * * * * * * * * * * * * * * * * *
 

 

 public class Une {


   int
x, y;

   String nom;

   public
Une(int x, int y, String nom) {

        this.x = x;

        this.y = y;

        this.nom = nom;

   }

 

   public String getNom() {

   return nom;

   }

 

   public void setNom(String nom) {

   this.nom = nom;

   }

 

   public int getX() {

   return x;

   }

 

   public void setX(int x) {

   this.x = x;

   }

 

   public int getY() {

   return y;

   }

 

   public void setY(int y) {

   this.y = y;

   }

}



// Apparaissent virgules, point, point-virgules...

Partager cet article
Repost0