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
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test extends JFrame{
public Test() {
super("test");
this.setLayout(new BorderLayout());
JPanel panel = new JPanel() {
public void paintComponent(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(0, 0, 1600, 1200);
}
};
add(panel);
JPanel panelbis = new JPanel() {
public void paintComponent(Graphics g) {
g.setColor(Color.RED);
g.fillRect(0, 0, 1600, 1200);
}
};
add(panelbis,BorderLayout.NORTH);
setPreferredSize(new Dimension(640,480));
panel.setLayout(new FlowLayout());
JButton button1 = new JButton("toto") {
public void paintComponent(Graphics g) {
g.setColor(Color.RED);
g.fillRect(10, 10, 50, 60);
}
};
button1.setPreferredSize(new Dimension(70,80));
button1.setFocusable(false);
button1.setBorderPainted(false);
panel.add(button1);
JButton button2 = new JButton("toto") {
public void paintComponent(Graphics g) {
g.setColor(Color.YELLOW);
g.fillRect(10, 10, 50, 60);
}
};
button2.setPreferredSize(new Dimension(70,80));
button2.setFocusable(false);
button2.setBorderPainted(false);
panel.add(button2);
pack();
}
/**
* @param args
*/
public static void main(String[] args) {
(new Test()).setVisible(true);
}
} |
Partager