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 73 74 75 76 77 78 79 80 81
| public class gameWindow extends JPanel implements ActionListener{
private JFrame gameWindow;
private JPanel gamePanel;
private JComponent labelIMG1, labelIMG2, labelIMG3, labelIMG4;
private ImageIcon imgExit;
private JButton btnQuit;
private String nameGameWindow;
private String level;
private CImage monImage;
public gameWindow(String p_Level){
//creation fenetre
level = p_Level;
nameGameWindow = "Fenetre de jeux";
gameWindow = new JFrame();
gameWindow.setTitle(nameGameWindow);
gameWindow.setSize(800, 800);
gameWindow.setLocationRelativeTo(null);
gameWindow.setResizable(false);
gameWindow.setAlwaysOnTop(true);
gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gameWindow.setLayout(null);
//creation du panel
gamePanel = new JPanel();
gamePanel.setBackground(Color.GRAY);
gamePanel.setLocation(800, 800);
gamePanel.setLayout(null);
btnQuit = new JButton();
btnQuit.setBounds(600, 600, 128, 128);
imgExit = new ImageIcon("img\\config\\exit128.png");
btnQuit.setIcon(imgExit);
gamePanel.add(btnQuit);
try {
monImage = new CImage("img\\levels\\"+level+"\\1.jpg");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//creation des labels a deplacer
labelIMG1 = new JLabel(new ImageIcon(monImage.getPart1()));
labelIMG1.setBounds(50, 50, 220, 220);
gamePanel.add(labelIMG1);
labelIMG2 = new JLabel(new ImageIcon(monImage.getPart2()));
labelIMG2.setBounds(200, 50, 220, 220);
gamePanel.add(labelIMG2);
try {
monImage = new CImage("img\\levels\\"+level+"\\2.jpg");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
labelIMG3 = new JLabel(new ImageIcon(monImage.getPart1()));
labelIMG3.setBounds(50, 300, 220, 220);
gamePanel.add(labelIMG3);
labelIMG4 = new JLabel(new ImageIcon(monImage.getPart2()));
labelIMG4.setBounds(200, 300, 220, 220);
gamePanel.add(labelIMG4);
btnQuit.addActionListener(this);
} |
Partager