Java Reference
In-Depth Information
Display 18.21
Using
drawString
(part 2 of 3)
37
JButton theButton =
new
JButton("The Button");
38
theButton.addActionListener(
this
);
39
buttonPanel.add(theButton, BorderLayout.CENTER);
40
add(buttonPanel, BorderLayout.SOUTH);
41
}
42
public void
paint(Graphics g)
43
{
44
super
.paint(g);
45
g.setFont(fontObject);
46
g.setColor(penColor);
47
g.drawString(theText, X_START, Y_START);
48
}
49
public void
actionPerformed(ActionEvent e)
50
{
51
penColor = Color.RED;
52
fontObject =
53
new
Font("Serif", Font.BOLD|Font.ITALIC, POINT_SIZE);
54
theText = "Thank you. I needed that.";
55
repaint();
56
}
57
}
R
ESULTING
GUI
(Start view)