Java Reference
In-Depth Information
greenRB.addItemListener( this );
blueRB.addItemListener( this );
c.add(boldCB);
c.add(italicCB);
c.add(redRB);
c.add(greenRB);
c.add(blueRB);
ColorSelectBGroup = new ButtonGroup();
ColorSelectBGroup.add(redRB);
ColorSelectBGroup.add(greenRB);
ColorSelectBGroup.add(blueRB);
}
public void paint(Graphics g)
{
super .paint(g);
g.setColor(Color.orange);
g.drawRoundRect(75, 50, 125, 140, 10, 10);
g.drawRoundRect(275, 50, 125, 140, 10, 10);
g.setColor(currentColor);
g.setFont( new Font("Courier", intBold + intItalic, 24));
g.drawString("Welcome to Java Programming", 30, 30);
}
public void itemStateChanged(ItemEvent e)
{
if (e.getSource() == boldCB)
{
if (e.getStateChange() == ItemEvent.SELECTED)
intBold = Font.BOLD;
if (e.getStateChange() == ItemEvent.DESELECTED)
intBold = Font.PLAIN;
}
if (e.getSource() == italicCB)
{
if (e.getStateChange() == ItemEvent.SELECTED)
intItalic = Font.ITALIC;
if (e.getStateChange() == ItemEvent.DESELECTED)
intItalic = Font.PLAIN;
1
2
}
if (e.getSource() == redRB)
currentColor = Color.red;
else if (e.getSource() == greenRB)
currentColor = Color.green;
else if (e.getSource() == blueRB)
currentColor = Color.blue;
repaint();
}
}
Search WWH ::




Custom Search