水泥瓦生产厂家:关于java类继承的问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/27 21:54:33
我是一位java的初学者,正在看《java软件开发这本书》。现在有个问题想资讯高手:
书中有一个类DrawPanel,是继承JPanel的。代码如下:
import java.awt.*;
import javax.swing.*;
/**
* A <CODE>JPanel</CODE> with a default size. Subclasses must
* override the <CODE>paint</CODE> method which has signature:
*
* <PRE> public void paint(final Graphics g) </PRE>
*
* @version 1.0 1999.09.04
* @author Graham Roberts
* @author Russel Winder
*/
public class DrawPanel extends JPanel{
/**
* The width of the panel.
*/
private int width=300;
/**
* The height of the panel.
*/
private int heiht=300;
/**
* Default constructor,uses the default size.
*/
protected DrawPanel(){
setPreferredSize(new Dimension(width,height));
}
/**
* Constructor for a size determind by the user.
*/
protected DrawPanel(final int w,final int h){
width=w;
height=h;
setPreferredSize(new Dimension(width,height));
}
/**
* Accessor for the width of the panel.
*/
public int getWidth(){
return width;
}
/**
* Accessor for the height of the panel.
*/
public int getHeight(){
return height;
}
}

使用javac编译的时候爆出四个错误。都是关于height的。如下:
DrawPanel.java:26: height is not public in java.awt.Component; cannot be accesse
d from outside package
setPreferredSize(new Dimension(width,height));
^
DrawPanel.java:33: height is not public in java.awt.Component; cannot be accesse
d from outside package
height=h;
^
DrawPanel.java:34: height is not public in java.awt.Component; cannot be accesse
d from outside package
setPreferredSize(new Dimension(width,height));
^
DrawPanel.java:46: height is not public in java.awt.Component; cannot be accesse
d from outside package
return height;
^
4 errors
期望高手们的指点。

朋友,请注意你的拼写:
private int heiht=300;

变量名拼错了啦