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
|
// import ...
public class menu
{
public static void main(String []args)
{
cadre fenetre = new cadre("Astéroïdes",150,150,1365,718);
}
}
class cadre extends JFrame
{
public cadre(String nom,int X,int Y,int H,int L)
super(nom);
setBounds(X,Y,H,L);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(new Panneau1());
setVisible(true);
setResizable(false);
}
}
class Panneau1 extends JPanel
{
private JButton jouer = new JButton("Jouer");
public Panneau1()
{
add(jouer);
jouer.addActionListener(new Ecouteur1());
}
class Ecouteur1 implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
jouerClick();
}
}
public void jouerClick()
{
this.removeAll();
this.add(new Panneau2());
this.invalidate();
this.validate();
this.repaint();
}
public void paintComponent(Graphics g)
{
Image FondEcran = getToolkit().getImage("image.jpg");
g.drawImage(FondEcran,0,0,1365,718,this);
}
}
class Panneau2 extends JPanel
{
// Ici, c'est un panneau complètement différent (Image et composants différents)
} |
Partager