【发布时间】:2011-08-17 12:06:33
【问题描述】:
不知道为什么这不起作用我正在使用 netbeans 创建它我在 jcreator 中有类似的代码并且它可以工作。非常感谢任何帮助
public void BoardGUI(){
panel = new JPanel();
setIconImage(new ImageIcon("images/die.bmp").getImage());
Container cPane;
cPane = getContentPane();
cPane.setBackground(Color.red);
setTitle("ITT Game Of Life");
setDefaultCloseOperation(EXIT_ON_CLOSE);
panel.setOpaque(false); //the frame
setSize(800,650);
setLocation(500,100);
boardArea = new JTextArea(50,100) {
ImageIcon image = new ImageIcon( "/images/Board.jpg" );
@Override
public void paint( Graphics g ) {
g.drawImage( image.getImage(), 0, 0, this);
super.paint(g);
}
};
boardArea.setOpaque(false);
boardArea.setEditable(true);
boardArea.setBounds(100,50,200,200);
cPane.add(boardArea);
【问题讨论】:
-
你有什么错误吗?究竟是什么行不通?当我尝试它时,我可以看到图像作为文本区域的背景。
-
没有错误出现,只是当我运行它时,我根本没有让图像出现。我应该将图像放在类中还是在项目中其他位置的文件夹中。