import java.awt. *; public class Hwa4 extends java.applet.Applet implements Runnable { private Button mybutton; private boolean onbutton = false; private Font newfont; private int inc = 1; public int xsize, ysize, ycoord = 0; // determine size of applet, create buttons and fonts public void init () { xsize = this.size ().width; ysize = this.size ().height; mybutton = new Button ("Press Me"); newfont = new Font ("TimesRoman", Font.ITALIC, 30); add (mybutton); } // paint method handles drawing public void paint (Graphics g) { // always draw yellow box g.setColor (Color.yellow); g.fillRect (50, 50, xsize - 100, ysize - 100); // if button is on draw text also if (onbutton) { g.setFont (newfont); g.setColor (Color.red); g.drawString ("Hello ", xsize / 2 - 60, ysize / 2 + ycoord); g.drawString ("World!", xsize / 2, ysize / 2 - ycoord); } } // this method handles user interaction via the button public boolean action (Event evt, Object arg) { if (evt.target instanceof Button) if ("Press Me".equals ((String) arg)) { onbutton = !onbutton; repaint (); return true; } return false; } // override update so as not to redraw background - helps flicker public void update (Graphics g) { paint (g); } // this method contains code to set up looping text public void run () { // code needs to be plugged in here } }