求高手帮忙,把 JAVA applet小程序改写为应用程序,急求!!!
求高手帮忙,把JAVAapplet小程序改写为应用程序,急求!!!importjava.applet.Applet;importjava.awt.Graphics;cla...
求高手帮忙,把 JAVA applet小程序改写为应用程序,急求!!!import java.applet.Applet;
import java.awt.Graphics;
class Dogs
{
public String name,
public int weight;
public int height;
}
public void showDog(Graphics g,int x,int y)
{
g.drawString("Namc:"+name,x,y)
g.drawString("Weight:"+weight,x,y+20);
g.drawString("Height:" theight,x,y+40);
}
public class C4_2 extends Applet
{
public void paint(Graphics g).
{
Dogs dane;
dane= new Dogs();
Dogs setter=new Dogs();
dane.name="Gread Dane";
dane.weight=100;
dane.height=23;
setter.name="Irish Setter";
setter.weight=20;
setter.height=30;
dane.showDog(g,25,25);
setter.showDog(g,25.120);
}
} 展开
import java.awt.Graphics;
class Dogs
{
public String name,
public int weight;
public int height;
}
public void showDog(Graphics g,int x,int y)
{
g.drawString("Namc:"+name,x,y)
g.drawString("Weight:"+weight,x,y+20);
g.drawString("Height:" theight,x,y+40);
}
public class C4_2 extends Applet
{
public void paint(Graphics g).
{
Dogs dane;
dane= new Dogs();
Dogs setter=new Dogs();
dane.name="Gread Dane";
dane.weight=100;
dane.height=23;
setter.name="Irish Setter";
setter.weight=20;
setter.height=30;
dane.showDog(g,25,25);
setter.showDog(g,25.120);
}
} 展开
展开全部
你的Java applet程序我帮你改成Java应用程序了,你看看吧.(改动的地方见注释)
import java.awt.Graphics;
import javax.swing.JFrame;//这里把import java.applet.Applet;改成import javax.swing.JFrame;
class Dogs
{
public String name;//这里句尾逗号改成分号
public int weight;
public int height;
public void showDog(Graphics g,int x,int y)
{
g.drawString("Namc:"+name,x,y); //这里句尾加分号
g.drawString("Weight:"+weight,x,y+20);
g.drawString("Height:"+height,x,y+40); //这里"Height:" theight改成"Height:"+height
}
}//这里大括号移到这里
public class C4_2 extends JFrame //这里继承JFrame
{
C4_2(){ //这里加构造函数
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args)//这里加主函数
{
C4_2 c=new C4_2();
}
public void paint(Graphics g)//这里去掉末尾的英文句号(点.)
{
super.paint(g); //这里加一句因为重写paint方法所以需要调用原paint方法
Dogs dane;
dane= new Dogs();
Dogs setter=new Dogs();
dane.name="Gread Dane";
dane.weight=100;
dane.height=23;
setter.name="Irish Setter";
setter.weight=20;
setter.height=30;
dane.showDog(g,25,25);
setter.showDog(g,25,120);//这里把setter.showDog(g,25.120);改成setter.showDog(g,25,120);25后面的点改成逗号
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询