panel image et dessin
This commit is contained in:
parent
8592394ddf
commit
56c2d2851c
|
|
@ -0,0 +1,55 @@
|
||||||
|
package graphique;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
|
||||||
|
public class JPanelImage extends JPanel {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3641337531772753865L;
|
||||||
|
private String sNomImage;
|
||||||
|
private Image image=null;
|
||||||
|
|
||||||
|
|
||||||
|
public JPanelImage() {
|
||||||
|
super();
|
||||||
|
sNomImage=null;
|
||||||
|
}
|
||||||
|
public JPanelImage(String sNom) {
|
||||||
|
super();
|
||||||
|
sNomImage=sNom;
|
||||||
|
chargerImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(String sNom) {
|
||||||
|
sNomImage=sNom;
|
||||||
|
chargerImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void chargerImage(){
|
||||||
|
if(sNomImage!=null) {
|
||||||
|
String sNomFile=".\\images\\"+sNomImage;
|
||||||
|
try {
|
||||||
|
image = ImageIO.read(new File(sNomFile));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
image=null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
this.setBackground(Color.white);
|
||||||
|
if(image!=null) {
|
||||||
|
g.drawImage(image, 0, 0, this.getWidth(),this.getHeight(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,7 @@ import javax.swing.JButton;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import javax.swing.border.BevelBorder;
|
import javax.swing.border.BevelBorder;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
|
||||||
|
|
||||||
public class MaJFrame extends JFrame {
|
public class MaJFrame extends JFrame {
|
||||||
|
|
@ -47,31 +48,41 @@ public class MaJFrame extends JFrame {
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
*/
|
*/
|
||||||
public MaJFrame() {
|
public MaJFrame() {
|
||||||
|
setIconImage(Toolkit.getDefaultToolkit().getImage(MaJFrame.class.getResource("/image/zombie.png")));
|
||||||
|
setBackground(new Color(128, 0, 0));
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setBounds(100, 100, 450, 300);
|
setBounds(100, 100, 450, 300);
|
||||||
contentPane = new JPanel();
|
contentPane = new JPanel();
|
||||||
contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
|
contentPane.setBackground(new Color(128, 0, 0));
|
||||||
|
contentPane.setBorder(new EmptyBorder(2, 2, 2, 2));
|
||||||
|
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
contentPane.setLayout(new BorderLayout(0, 0));
|
contentPane.setLayout(new BorderLayout(0, 0));
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
|
panel.setBorder(null);
|
||||||
|
panel.setBackground(new Color(64, 0, 0));
|
||||||
contentPane.add(panel, "cell 10 10,grow");
|
contentPane.add(panel, "cell 10 10,grow");
|
||||||
contentPane.add(panel, BorderLayout.NORTH);
|
contentPane.add(panel, BorderLayout.NORTH);
|
||||||
|
|
||||||
JButton btnNewButton = new JButton("ah!");
|
JButton btnNewButton = new JButton("JOUER !");
|
||||||
panel.add(btnNewButton);
|
panel.add(btnNewButton);
|
||||||
|
|
||||||
panel_1 = new JPanelDessin();
|
panel_1 = new JPanelDessin();
|
||||||
panel_1.setBackground(new Color(240, 240, 240));
|
panel_1.setBackground(new Color(255, 128, 0));
|
||||||
panel_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
panel_1.setBorder(null);
|
||||||
contentPane.add(panel_1, BorderLayout.CENTER);
|
panel_1.setLayout(new GridLayout(11, 11, 0, 0));
|
||||||
panel_1.setLayout(new GridLayout(1, 0, 0, 0));
|
|
||||||
panel_1.setOpaque(false);
|
panel_1.setOpaque(false);
|
||||||
|
|
||||||
JPanelImage panel_2 = new JPanelImage("map1.png");
|
|
||||||
|
JPanelImage panel_2 = new JPanelImage();
|
||||||
|
panel_2.setImage("map1.png");
|
||||||
|
panel_2.setBorder(null);
|
||||||
|
panel_2.add(panel_1);
|
||||||
|
//JPanelImage panel_2 = new JPanelImage("map1.png");
|
||||||
contentPane.add(panel_2);
|
contentPane.add(panel_2);
|
||||||
panel_2.setLayout(new GridLayout(2, 1, 0, 0));
|
panel_2.setLayout(new GridLayout(1, 1, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue