package joy; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class fun extends Applet { int x; boolean flag; boolean isStandalone = false; JToggleButton joy = new JToggleButton(); /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Construct the applet*/ public fun() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { joy.setText("joy"); joy.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { joy_actionPerformed(e); } }); this.setBackground(Color.lightGray); this.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(KeyEvent e) { } }); this.add(joy, null); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } void joy_actionPerformed(ActionEvent e) { if(x==0) flag=true; if(flag==true) x++; else x--; repaint(); if(x==6){ flag=false; x=0; } } public void update(Graphics g){ paint(g); g.clearRect(0,0,300,40); } public void paint(Graphics g){ switch(x){ case 0: g.clearRect(0,30,300,300); joy.setText("head"); break; case 1: g.drawArc(50,50,150,100,0,360); joy.setText("eye"); break; case 2: g.setColor(Color.black); g.fillOval(90,70,10,10); g.fillOval(150,70,10,10); joy.setText("nose"); break; case 3: int x[]={125,120,130}; int y[]={100,120,120}; g.setColor(Color.red); g.fillPolygon(x,y,3); joy.setText("mouth"); break; case 4: joy.setText("ear"); g.setColor(Color.yellow); g.drawLine(110,130,140,130); g.drawArc(110,110,30,20,180,180); break; case 5: g.drawOval(40,90,10,10); g.drawOval(200,90,10,10); joy.setText("clear"); break; } } }