1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| package Tp1.fr.unice.l3.formes;
public class editeurImages extends JFrame implements ActionListener{
JPanel zoneOutil = new JPanel();
JButton boutonR = new JButton("Rectangle");
JButton boutonE = new JButton("Ellipse");
JPanel zoneDessin = new JPanel();
public editeurImages(){
Dimension taille = new Dimension(120,30);
// Fenetre
this.setTitle("Editeur d'image");
this.setSize(500,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
// Dessin
boutonR.addActionListener(this);
boutonE.addActionListener(this);
zoneDessin.setBackground(Color.WHITE);
zoneDessin.setLayout(new BoxLayout(zoneDessin, BoxLayout.PAGE_AXIS));
// Boite à outils
boutonR.setMaximumSize(taille);
boutonE.setMaximumSize(taille);
zoneOutil.add(boutonR);
zoneOutil.add(boutonE);
zoneOutil.setLayout(new BoxLayout(zoneOutil, BoxLayout.PAGE_AXIS));
// Affichage
this.getContentPane().add(zoneDessin, BorderLayout.CENTER);
this.getContentPane().add(zoneOutil, BorderLayout.WEST);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == boutonR){
Point a = new Point(40,100);
Rectangle rect1 = new Rectangle(a, 80, 50);
zoneDessin.add(rect1);
System.out.println("Bouton rectangle !");
}else if(e.getSource() == boutonE){
Point b = new Point(0,0);
Ellipse ellipse = new Ellipse(b, 80, 50);
zoneDessin.add(ellipse);
System.out.println("Bouton ellipse !");
}
this.repaint();
}
public static void main(String[] args){
new editeurImages();
}
} |
Partager