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
| public class test1 extends JFrame {
JButton b;
JFrame f;
public test1(){
super("voila");
setSize(1024,800);
setLayout(null);
b=new JButton("héhé");
b.setBounds(500,500,100,100);
add(b);
setVisible(true);
}
}
public class test2 extends test1{
Image im;
JFrame f;
public test2() {
super();
Toolkit tk = Toolkit.getDefaultToolkit();
im = tk.getImage("Sans titre.JPG");
}
public static void main(String[] args) {
new test2();
}
public void paint(Graphics g) {
super.paint(g);
Color c = g.getColor();
g.drawImage(im,0,0,this);
g.setColor(Color.RED);
g.fillRect(10,10,80,80);
g.setColor(Color.BLUE);
g.fillOval(150,50,80,80);
g.setColor(c);
repaint();}
} |
Partager