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
|
public class PanelEntrance extends JPanel
{
private ImageIcon img;
private Button solo = new Button("Solo Mode");
private Button multi = new Button("Multiplayer Mode");
private Button option = new Button("Option");
private Button help = new Button("Help");
private Button exit = new Button("Exit");
public PanelEntrance() {
this.setLayout(new GridBagLayout());
GridBagConstraints sol = new GridBagConstraints();
sol.gridx = 1; sol.gridy = 1; sol.insets = new Insets(150,0,20,0); sol.ipady = 10;
GridBagConstraints mul = new GridBagConstraints();
mul.gridx = 1; mul.gridy = 2; mul.insets = new Insets(0,0,20,0); mul.ipady = 10;
GridBagConstraints opt = new GridBagConstraints();
opt.gridx = 1; opt.gridy = 3; opt.insets = new Insets(0,0,20,0); opt.ipady = 10;
GridBagConstraints hel = new GridBagConstraints();
hel.gridx = 1; hel.gridy = 4; hel.insets = new Insets(0,0,20,0); hel.ipady = 10;
GridBagConstraints exi = new GridBagConstraints();
exi.gridx = 1; exi.gridy = 5; exi.insets = new Insets(0,0,20,0); exi.ipady = 10;
solo.addActionListener(new SoloButtonListener());
this.add(solo, sol);
this.add(multi,mul);
this.add(option,opt);
this.add(help,hel);
this.add(exit,exi);
}
public void paintComponent(Graphics g)
{
ImageIcon img = new ImageIcon("PanelBackground.gif");
Insets insets = getInsets();
img.paintIcon(this, g, insets.bottom, insets.left);
Font font = new Font("Courier", Font.BOLD, 20);
g.setFont(font);
g.drawString("Gremlings War", this.getWidth()/3+this.getWidth()/14, this.getHeight()/5);
}
public void setSolo(Button solo) {
this.solo = solo;
}
public Button getSolo() {
return solo;
}
class SoloButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
CardLayoutExample.changePanel("panelSolo");
}
}
} |
Partager