Java Reference
In-Depth Information
7.
8.
public class
DrawingDisplayScrollPanel
extends
JPanel {
9.
10.
public
DrawingDisplayScrollPanel() {
11.
this
.setBackground(Color.white);
12.
this
.setPreferredSize(
new
Dimension(250,250));
13.
}
14.
15.
public void
paintComponent(Graphics g){
16.
super
.paintComponent(g);
17.
Color oldColor = g.getColor();
18.
g.setColor(Color.red);
19.
g.drawRect(0,0,249,249);
20.
g.drawString("Border of preferred size.",10,240);
21.
g.setColor(Color.blue);
22.
g.fillOval(300,150,20,20);
23.
g.drawString("This is outside the preferred size",260,180);
24.
g.setColor(oldColor);
25.
}
26.
}
Search WWH ::
Custom Search