所以我试图制作一个简单的 PacMan 克隆,我已经到了添加图像等的阶段。我有两个图像(到目前为止),它们是:
和,trackball.png 和border.png。
所以我运行下面的代码new oicMan();
,这就是我得到
的: 控制台输出:
.
.
.
Placing image border on coordinate (225,250)
Placing image border on coordinate (225,275)
Placing image border on coordinate (225,300)
Placing image border on coordinate (225,325)
Placing image border on coordinate (225,350)
Placing image border on coordinate (225,375)
Placing image border on coordinate (225,400)
Placing image border on coordinate (225,425)
Placing image border on coordinate (225,450)
Placing image border on coordinate (225,475)
所以它似乎停在 x=225。谁能告诉我为什么?for
我设置图像的循环有问题吗?谢谢(主要是,请告诉我为什么它没有完全绘画。)
import javax.swing.*;
import java.awt.*;
public class oicMan extends JFrame
{
Container container;
/*
####################
# ## #
# ## ############# #
# ## ############# #
# ## # #
# ## # ##### ##### #
# ## ##### ##### #
# ## # ##### ##### #
# # #
####################
*/
String arena[][] =
{
{"#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"},
{"#"," ","#","#"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ","#"},
{"#"," ","#","#"," ","#","#","#","#","#","#","#","#","#","#","#","#","#"," ","#"},
{"#"," ","#","#"," ","#","#","#","#","#","#","#","#","#","#","#","#","#"," ","#"},
{"#"," ","#","#"," ","#"," "," "," "," "," "," "," "," "," "," "," "," "," ","#"},
{"#"," ","#","#"," ","#"," ","#","#","#","#","#"," ","#","#","#","#","#"," ","#"},
{"#"," ","#","#"," "," "," ","#","#","#","#","#"," ","#","#","#","#","#"," ","#"},
{"#"," ","#","#"," ","#"," ","#","#","#","#","#"," ","#","#","#","#","#"," ","#"},
{"#"," "," "," "," ","#"," "," "," "," "," "," "," "," "," "," "," "," "," ","#"},
{"#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"},
};
public oicMan()
{
super("oicMan");
setSize(500, 250);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
container = getContentPane();
container.setLayout(null);
container.setBackground(Color.black);
for(int i = 0; i < arena.length; i++)
{
for(int j = 0; j < arena[0].length; j++)
{
JLabel label = null;
if(arena[ i][ j].equals("#"))
{
label = new JLabel(new ImageIcon("border.png"));
label.setName("border");
}
else
{
label = new JLabel(new ImageIcon("trackball.png"));
label.setName("track");
}
container.add(label);
label.setBounds(i*25,j*25,25,25);
System.out.println("Placing image "+label.getName()+" on coordinate ("+i*25+","+j*25+")");
}
}
repaint();
container.validate();
setContentPane(container);
}
}