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
| public class grille extends JPanel{
JButton test;
public grille(){
Graphics g = this.getGraphics();
setSize(400,400);
setVisible(true);
setBackground(Color.yellow);
//repaint();
System.out.println(getHeight());
test =new JButton("inser img");
.....
}
public void paintComponent(Graphics g){
int i;
super.paintComponent(g);
g.setColor(Color.red);
for(i=0;i<10;i++)
{
g.drawLine(40*i,0,40*i,400);
g.drawLine(0,40*i,400,40*i);
}
g.setColor(Color.BLUE);
g.fillRect(10,10,25,25);
}
public static void main(String[] args){
JFrame frame =new JFrame();
JPanel pan =new grille();
frame.getContentPane().add(pan);
frame.setTitle("Micosimulation");
frame.setSize(400,400);
//frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} |
Partager