Skip to content

Instantly share code, notes, and snippets.

;*********************************************************************
; INITIALISATIONS *
;*********************************************************************
init
;exemple
clrf PORTA ; Sorties portA à 0
clrf PORTB ; sorties portB à 0
JPanel panneau=new JPanel () ;
panneau . setLayout (new BorderLayout () ) ;
GridLayout experimentLayout = new GridLayout (3 ,3) ;
compsToExperiment . setLayout ( experimentLayout ) ;
compsToExperiment.add(new JButton("1"));
compsToExperiment.add(new JButton("2"));
...
public class CouleurAction implements ActionListener{
private JLabel lblCouleur ;
public CouleurAction(JLabel lblCouleur){
this.lblCouleur=lblCouleur ;
}
@Override
public void actionPerformed(ActionEvent e) {
lblCouleur.setText( " Rouge " ) ;
}
}
public class FrmFenetre extends JFrame{
public frmFenetre (){
JPanel pnlPanneau=new JPanel () ;
this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
this.setContentPane ( pnlPanneau ) ;
this.setSize (300 ,200) ;
this.setTitle("Exemple 1");
JButton btnBoutonR=new JButton("Rouge") ;
JLabel lblCouleur=new JLabel () ;
btnBoutonR.addActionListener(new CouleurAction(lblCouleur)); <≠≠ (⇤)
public class CouleurAction implements ActionListener{
private JLabel lblCouleur ;
public CouleurAction(JLabel lblCouleur){
this.lblCouleur=lblCouleur ;
}
@Override
public void actionPerformed(ActionEvent e) {
JButton btnSource=(JButton)e.getSource(); <≠≠(⇤)
lblCouleur.setText ( btnSource.getText () ) ;
}
public class FrmFenetre extends JFrame{
public FrmFenetre (){
JPanel pnlPanneau=new JPanel () ;
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ) ;
this.setContentPane ( pnlPanneau ) ;
this.setSize (300 ,200) ;
this.setTitle("Exemple 2");
JButton btnBoutonR = new JButton("Rouge");
JButton btnBoutonV = new JButton("Vert");
JLabel lblcouleur = new JLabel();
public class CouleurAction implements ActionListener{
private JLabel lblCouleur ;
private JPanel pnlPanneau ;
public CouleurAction(JLabel lblCouleur ,JPanel pnlPanneau){
this.lblCouleur=lblCouleur ;
this.pnlPanneau=pnlPanneau ;
}
@Override
public void actionPerformed(ActionEvent e) {
JButton btnSource=(JButton)e.getSource();
public interface WindowListener
{
void windowOpened ( WindowEvent e ) ;
void windowClosing(WindowEvent e);
void windowClosed ( WindowEvent e ) ;
void windowIconified (WindowEvent e) ;
void windowDeiconified (WindowEvent e) ;
void windowActivated(WindowEvent e);
void windowDeactivated(WindowEvent e);
}
File f=new File("monProjet"+File.separatorChar+"fichier");
File f=new File ("monProjet" ," fichier ") ;