// Final Test V. e) ii) // Jessie Xie // display my name in red when user first click the button, then display my name in larger font and blue when second time click button import java.applet.Applet; import java.awt.*; public class redblue extends Applet { private Button pushButton; private boolean first; private int red, green, blue; private int rd, gn, be; private String s = "Jessie Xie"; // string name private Font fred, fblue; public void init() { red = 255; green = 0; blue = 0; rd = 0; gn = 0; be = 255; fred = new Font( "TimesRoman", Font.BOLD, 14 ); // set font name style and size fblue = new Font( "TimesRoman", Font.BOLD, 20 ); pushButton = new Button( "Click here" ); // new button // add button add( pushButton ); first = true; // first time click } public void paint( Graphics g ) { if ( first == true ) // first time push button { g.setFont( fred ); // set font to fred g.setColor (new Color(red, green, blue)); // set new color g.drawString( s, 100, 150 ); // display string first = false; } else // second time push the button { g.setFont( fblue ); g.setColor (new Color(rd, gn, be)); g.drawString( s, 100, 150 ); // repaint(); } } // handle the button events public boolean action( Event e, Object o ) { // check to see if a button triggered the event if ( e.target instanceof Button ) { // check to see if pushButton was pressed. if ( e.target == pushButton ) repaint(); return true; // event was handled here } return true; } }