// Nuppude demo import java.awt.*; import java.applet.*; /* <applet code="ButtonDemo" width=250 height=150> </applet> */ public class ButtonDemo extends Applet { String msg = ""; public void init() { Button yes = new Button("Ja"); Button no = new Button("Ei"); Button maybe = new Button("Võib-olla"); add(yes); add(no); add(maybe); } // Nuppude identifitseerimine nende märgendite järgi. public boolean action(Event evtObj, Object arg) { if(evtObj.target instanceof Button) { if(arg.equals("Ja")) msg = "Vajutasid Ja."; else if(arg.equals("Ei")) msg = "Vajutasid Ei."; else if(arg.equals("Võib-olla")) msg = "Vajutasid Võib-olla."; repaint(); return true; } return false; } public void paint(Graphics g) { g.drawString(msg, 6, 100); } }