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
|
/*
* MonPanel.java
*
*/
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class MonPanel extends JPanel{
/** Creates a new instance of MonPanel */
public MonPanel() {
// fixe la couleur de fond du panel
this.setBackground(Color.white);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g; //cast en Graphics2D
int centreX = this.getSize().width/2; // centre axe des x
int centreY = this.getSize().height/2; // centre axe des y
g2.setColor(Color.RED); // fixe la couleur courante en rouge
// dessine un point rouge au centre du panel
g2.drawLine(centreX,centreY,centreX,centreY);
}
} |