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
|
import java.awt.BorderLayout;
import javax.swing.JFrame;
public class frame extends JFrame{
panneau pan;
frame()
{
super("Titre ####");
setBounds(20,20,800,600);
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
pan=new panneau();
add("Center",pan);
}
public static void main(String[] args) {
new frame();
}
}
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JPanel;
public class panneau extends Canvas{
int xx=10;int yy=10;
Image im=null;
panneau()
{
setSize(200,300);
setBackground(Color.WHITE);
}
public void paintComponent(Graphics g)
{
Graphics2D surface=(Graphics2D)g;
if (im==null)g=getGraphics();
else g=im.getGraphics();
if (g!=null){
g.fillRect(xx,yy,10,10);
}
g.dispose();
if(im!=null)
{
g=getGraphics();
if(g!=null && im!=null)
{
g.drawImage(im,0,0,this);
g.dispose();
}
}
else System.out.println("null");
surface.fillRect(xx,yy,10,10);
}
} |
Partager