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
| public class FenetreEssai extends JPanel{
private Image image;
public FenetreEssai(){
this.setBackground(Color.blue);
this.setSize(200,600);
try
{
this.image = ImageIO.read(new File("ecran.png"));
}
catch (IOException e)
{
this.image = null;
System.out.println("Fichier invalide!!!");
}
}
public void paintComponent(Graphics g){
//Dessine la poignee du levier
g.setColor(Color.black);
g.fillRect(20, 20, 50, 100);
g.drawImage(this.image, 0, 0, null);
}
public static void main(String args[]){
JFrame fen = new JFrame();
fen.setLocationRelativeTo(null);
fen.getContentPane().setPreferredSize(new Dimension(974,600));
fen.getContentPane().setLayout(null);
FenetreEssai pan = new FenetreEssai();
LeverView lev = new LeverView();
fen.getContentPane().add(pan);
pan.setLocation(0,0);
fen.getContentPane().add(lev);
lev.setBackground(Color.red);
lev.setLocation(775,0);
fen.pack();
fen.setVisible(true);
fen.setResizable(false);
fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} |
Partager