//<applet code=ButtonApplet.class width=400 height=300></applet> import java.awt.*;import java.applet.*; public class ButtonApplet extends Applet { int x,y; Button Bt; public ButtonApplet()//加入按钮 { x=y=100; Bt=new Button("按我"); add("Center",Bt); } public void paint(Graphics g) { g.drawString("Faint",x,y); } public boolean action(Event ev,Object arg)//触发Applet,可以点击按钮,字符串换位置 { if(ev.target instanceof Button) { if(x>=200) x=0; else x+=20; if(y<=200) y=200; else y-=10; repaint(); } return true; } }
运行结果:
时间: 2024-11-14 18:42:35