编写一个Applet类
发布网友
发布时间:2023-07-18 15:27
我来回答
共1个回答
热心网友
时间:2024-12-03 05:05
/*<HTML>
<TITLE>画画</TITLE>
<BODY>
<APPLET CODE="t2010_6_28.class" CODEBASE="." WIDTH=400 HEIGHT=300></APPLET>
</BODY>
</HTML>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class t2010_6_28 extends Applet implements ActionListener{
Button b1=new Button("椭圆"),b2=new Button("矩形"),b3=new Button("清除");
public void init(){
add(b1);add(b2);add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Graphics g=getGraphics();
if(e.getSource()==b1){
g.setColor(Color.red);
g.drawOval(50,50,50,50);
}
if(e.getSource()==b2){
g.setColor(Color.blue);
g.drawRect(50,50,100,60);
}
if(e.getSource()==b3){
repaint();
}
}
}