当前位置: 技术问答>java相关
一个APPLET的问题.
来源: 互联网 发布时间:2015-03-12
本文导语: 关于一个普通的APPLET程序的问题. D:myclasstest06.java import java.awt.*; import java.applet.*; import myPackage.myhome.*; import myPackage.myhome.cyclinder; import myPackage.myhome.Wcyclinder; public class test06 extends Applet { public void paint(Graphics g) ...
关于一个普通的APPLET程序的问题.
D:myclasstest06.java
import java.awt.*;
import java.applet.*;
import myPackage.myhome.*;
import myPackage.myhome.cyclinder;
import myPackage.myhome.Wcyclinder;
public class test06 extends Applet
{
public void paint(Graphics g)
{
double x,y;
cyclinder cyc01=new cyclinder(5,10);
x=cyc01.area();
y=cyc01.volume();
g.drawString("area is "+x,100,20);
g.drawString("volume is "+y,100,100);
x=cyc01.weight(7.0);
g.drawString("weight is "+x,100,140);
Wcyclinder cyc11=new Wcyclinder(5.1,10.3,101.26);
x=cyc11.volume();
g.drawString("Wcyclinder's volume is "+x,100,160);
y=cyc11.weight;
g.drawString("Wcyclinder's weight is "+y,100,180);
g.drawString("PI ="+cyc11.PI,100,200);
}
}
D:myclass myPackagemyhome cyclinder.java
package myPackage.myhome;
public class cyclinder{
double radius;
double high;
final double PI=3.14159265359;
public cyclinder(double r,double h){
radius=r;
high=h;
}
public double area(){
double x;
x=2*PI*radius*radius;
x+=2*PI*radius*high;
return x;
}
public double volume(){
return PI*radius*radius*high;
}
public double weight(double hw){
return this.volume()*hw;
}
}
D:myclass myPackagemyhome Wcyclinder.java
import myPackage.myhome.cyclinder;
public class Wcyclinder extends cyclinder
{
public double PI=88;
double weight;
public Wcyclinder(double r,double h,double w){
super(r,h);
weight=w;
//member Variable how cover ,i see ,but
//Method cover how did you do?
}
}
为什么编译的时候还回出错呢?
能看懂日文吗?
test06.java:5: myPackage.myhome の myPackage.myhome.Wcyclinder は public ではあ
りません。パッケージ外からはアクセスできません。
import myPackage.myhome.Wcyclinder;
^
エラー 1 個
大概的意思是, myPackage.myhome.Wcyclinder不是公开的.PATH以外的访问不能.`
D:myclasstest06.java
import java.awt.*;
import java.applet.*;
import myPackage.myhome.*;
import myPackage.myhome.cyclinder;
import myPackage.myhome.Wcyclinder;
public class test06 extends Applet
{
public void paint(Graphics g)
{
double x,y;
cyclinder cyc01=new cyclinder(5,10);
x=cyc01.area();
y=cyc01.volume();
g.drawString("area is "+x,100,20);
g.drawString("volume is "+y,100,100);
x=cyc01.weight(7.0);
g.drawString("weight is "+x,100,140);
Wcyclinder cyc11=new Wcyclinder(5.1,10.3,101.26);
x=cyc11.volume();
g.drawString("Wcyclinder's volume is "+x,100,160);
y=cyc11.weight;
g.drawString("Wcyclinder's weight is "+y,100,180);
g.drawString("PI ="+cyc11.PI,100,200);
}
}
D:myclass myPackagemyhome cyclinder.java
package myPackage.myhome;
public class cyclinder{
double radius;
double high;
final double PI=3.14159265359;
public cyclinder(double r,double h){
radius=r;
high=h;
}
public double area(){
double x;
x=2*PI*radius*radius;
x+=2*PI*radius*high;
return x;
}
public double volume(){
return PI*radius*radius*high;
}
public double weight(double hw){
return this.volume()*hw;
}
}
D:myclass myPackagemyhome Wcyclinder.java
import myPackage.myhome.cyclinder;
public class Wcyclinder extends cyclinder
{
public double PI=88;
double weight;
public Wcyclinder(double r,double h,double w){
super(r,h);
weight=w;
//member Variable how cover ,i see ,but
//Method cover how did you do?
}
}
为什么编译的时候还回出错呢?
能看懂日文吗?
test06.java:5: myPackage.myhome の myPackage.myhome.Wcyclinder は public ではあ
りません。パッケージ外からはアクセスできません。
import myPackage.myhome.Wcyclinder;
^
エラー 1 個
大概的意思是, myPackage.myhome.Wcyclinder不是公开的.PATH以外的访问不能.`
|
把public class Wcyclinder extends cyclinder
前面的import myPackage.myhome.cyclinder;
改为package myPackage.myhome;
前面的import myPackage.myhome.cyclinder;
改为package myPackage.myhome;