日期:2014-05-20  浏览次数:20665 次

非常简单的java题目 !!帮帮忙~~!!
编写一个Applet程序:画图
要求:界面上有2个按钮,一个名称为“椭圆”,另一个为“矩形”,点击后分别画蓝色的椭圆和红色的矩形,图形大小和位置自己确定。

运行环境:JCreator
速度   在线等啊~~!!

------解决方案--------------------
真后悔走开了,还要啊????!!!!
哈哈,接点分吧
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Test extends Applet implements ActionListener
{
private Button bt1=new Button( "椭圆 "),
bt2=new Button( "矩形 ");

public void init()
{
add(bt1);
add(bt2);

bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt1)

picture1();
else if(e.getSource()==bt2)

picture2();

repaint();
}

boolean choose;

public void picture1()
{
choose=true;
}
public void picture2()
{
choose=false;
}
public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
int x=90,y=50,n,m,i;
double d;
if(choose)
{
g2.setColor(Color.blue);


g2.drawOval(x,y,50,30);


}
else
{
g2.setColor(Color.red);

g2.drawRect(x,y,35,30);


}
}
}

------解决方案--------------------
第二个:
import java.util.*;
class Rectangle
{
int length,width;
Rectangle()
{}
Rectangle(int a,int b)
{
length=a;
width=b;
}
public int round()
{
int round=(int)(length+width)*2;

return round;

}
public int mianji()
{
int mianji=length*width;

return mianji;
}
public String tostring(int i)
{
String str;
str=String.valueOf(i);

return str;
}

}
public class Test
{
public static void main(String args[])
{
Rectangle r1=new Rectangle(15,6);
System.out.println( "周长为: "+r1.round());
System.out.println( "面积是: "+r1.mianji());
System.out.println ( "周长转换成字符串: "+r1.tostring(r1.round()));
System.out.println ( "面积转换成字符串: "+r1.tostring(r1.mianji()));
}
}