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 72
|
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Interface extends JFrame implements ActionListener{
private JPanel p1 = new JPanel();
private JPanel p2 = new JPanel();
private JButton B1 = new JButton("Afficher");
private JButton B2 = new JButton("Annuler");
JLabel label= new JLabel();
public Interface(){
this.setTitle("Afficher image");
this.setSize(800, 500);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p1.setLayout(new BorderLayout ( ) ) ;
p2.setLayout(new FlowLayout());
p1.add(p2, BorderLayout.SOUTH);
p2.add(B1);
p2.add(B2);
this.setContentPane(p1);
this.setVisible(true);
B1.addActionListener(new BoutonListener());
B2.addActionListener(new BoutonListener());
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
public class Picture extends JPanel {
public void paintComponent(Graphics g){
try {
Image img = ImageIO.read(new File("Image.jpg"));
g.drawImage(img, 200, 200, this);
} catch (IOException e) {
e.printStackTrace();
}
}
}
class BoutonListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == B1){
//????????????
}
else if (source == B2){
//????????????
}
}}}} |