编译不过去????????

lncf 2002-08-02 10:58:05
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ImageTest
{
public static void main (String[] args)
{
ImageFrame frame = new ImageFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}

//创建一个带图象面板的框架
class ImageFrame extends JFrame
{
public ImageFrame()
{
setTitle("ImageTest");
setSize(WIDTH,HEIGHT);

//把面板加到框架上
ImagePanel panel = new ImagePanel();
Container contentPane = getContentPanel;
contentPane.add(panel);
}
public static final int WIDTH = 300;
public static final int HEIGHT = 200;
}
//显示图片的面板
class ImagePanel extends JPanel
{
image = Toolkit.getDefaultToolkit().getImage("b.jpg");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image,0);
try { tracker.waitForID (0); }
catch (InterruptedException exception) { }
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);

int imageWidth = image.getWidth(this);
int imageHeight = image.getHeight(this);

//
g.drawImage(image,0,0,null);

//
for (int i=0;i*imageWidth <= getWidth();i++)
for (int j=0;j*imageHeight <= getHeight();j++)
if (i+j>0)
g.copyArea(0,0,imageWidth,imageHeight,i*imageWidth,j*imageHeight);
}
private Image image;
}


这是《最新Java2核心技术(原理)》中的一个例子,例7-7的问题

编译不过去,请各位高手和大虾看一看,哪里出了毛病??


十分感谢!!!!!!!!!
...全文
28 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
钟伟海 2002-08-02
  • 打赏
  • 举报
回复
如果代码是拷贝过来的,你要注意经常出问题!
每句的前后带了空格的话就会出错!
这个例子我试过了,没问题的!
heifei 2002-08-02
  • 打赏
  • 举报
回复
我看了你的程序,全是不仔细的原因,比如
少敲一行,
少敲个‘}'号,
getContentPane()敲成getContentPanel,
等等
帮主,拜托,细心点!
cno 2002-08-02
  • 打赏
  • 举报
回复
我也试过了,是好的,没有什么差错。
你编译的时候不会提示什么地方出错吗?
自己看看就懂了!!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧