
1 30
Chapter 8: Developing
GUIs []
10
11
12
13
14 }
public void paintComponent (Graphics g) {
super, paintComponent (g) ;
g.drawString("Text to be drawn" , 20, getHeight()
}
);
PaintPanel
The constructor, PaintPanel, uses the javax, swing. 3Panel. setPreferredSize method to set the
size of the panel, in this case, 1 I0 pixels wide and 24 pixels high. The first statement in the
paintComponent method must be
super, paintComponent (g) ;
This causes the component to paint its background. The java. awt. Graphics. drawString method
is used to paint the text. Two useful methods in javax, swing. 3Component that can be used with
drawstring are ...