そこで、簡単なパックマンのクローンを作成しようとして、画像などを追加する段階になりました。これまでのところ、trackball.pngとborder.pngの
2つの画像があります。
だから私は以下のコードを実行します、そしてこれは私が得るものです:
そしてコンソール出力: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);
}
}