不知道那错了,指点
程序代码:
import java.applet.*; import java.awt.*; import java.awt.event.*; class draw extends Canvas { int shape=0; public void paint(Graphics g) { super.paint(g); switch (shape) { case 1:g.drawRect(100,100,100,100);break; case 2:g.drawOval(50,5,50,50);break; } } public void img(int shape) { this.shape=shape; } } public class exp30 extends Applet implements ActionListener { Button rect=new Button("矩形"); Button oval=new Button("椭圆"); public draw dr=new draw(); public void init() { Panel p=new Panel(new FlowLayout()); p.add(rect);p.add(oval); this.setLayout(new BorderLayout()); this.add("North",p); this.add("Center",dr); rect.addActionListener(this); oval.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==rect) dr.img(1); else if(e.getSource()==oval) dr.img(2); } }
html
<html><applet height="400" width="400" code="exp30.class"></applet></html>
现在的问题是 在applet里面点击两个按钮根本没有任何显示,初步估计是
程序代码:
public void paint(Graphics g) { super.paint(g); switch (shape) { case 1:g.drawRect(100,100,100,100);break; case 2:g.drawOval(50,5,50,50);break; } }
这里有问题,但是在找不出问题所在,求帮助