算了,帮你写一下吧
[CODE]/*
* Draw.java
*
* Created on 2007-6-28, 17:37:06
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
/**
*
* @author hadeslee
*/
public class Draw extends JApplet implements ActionListener{
private JButton jb1,jb2;
private int what;
public static final int OVAL=1;
public static final int RECT=2;
public Draw() {
}
public void init(){
jb1=new JButton("栯圆");
jb2=new JButton("矩形");
JPanel jp=new JPanel();
jp.add(jb1);
jp.add(jb2);
this.getContentPane().add(jp,BorderLayout.SOUTH);
jb1.addActionListener(this);
jb2.addActionListener(this);
}
public void paint(Graphics g){
super.paint(g);
switch(what){
case OVAL:
g.drawOval(50,50, 100,60);
break;
case RECT:
g.drawRect(50, 50, 100, 60);
break;
}
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==jb1){
what=OVAL;
repaint();
}else if(ae.getSource()==jb2){
what=RECT;
repaint();
}
}
}[/CODE]
可惜不是你,陪我到最后