Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent e)
// Did somebody push our button?
if (e.getSource( ) == theButton)
changeColor( );
|
private synchronized void | changeColor()
// Change the index to the next color.
if (++colorIndex == someColors.length)
colorIndex = 0;
setForeground(currentColor( )); // Use the new color.
repaint( ); // Paint again so we can see the change.
|
private synchronized java.awt.Color | currentColor()
return someColors[colorIndex];
|
public static void | main(java.lang.String[] args)
JFrame f = new JFrame("HelloJava4");
// Make the application exit when the window is closed.
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent we) { System.exit(0); }
});
f.setSize(300, 300);
f.getContentPane( ).add(new HelloJava4("Hello, Java!"));
f.setVisible(true);
|
public void | mouseDragged(java.awt.event.MouseEvent e)
messageX = e.getX( );
messageY = e.getY( );
repaint( );
|
public void | mouseMoved(java.awt.event.MouseEvent e)
|
public void | paintComponent(java.awt.Graphics g)
g.setColor(blinkState ? getBackground() : currentColor( ));
g.drawString(theMessage, messageX, messageY);
|
public void | run()
try {
while(true) {
blinkState = !blinkState; // Toggle blinkState.
repaint( ); // Show the change.
Thread.sleep(500);
}
}
catch (InterruptedException ie) {}
|