定位/显示JLayeredPane

时间:2017-10-13 13:05:25

标签: java swing

我有包含JLayeredPane的Panel,其中包含两个JPanel,每个JPLnel都有两个JLabel。

Panel panel2 = new Panel();
JLayeredPane westP = new JLayeredPane();
westP.setLayout(null);
westP.setPreferredSize(new Dimension(100,400));
westP.setBackground(Color.blue);

JPanel layerOne = new JPanel();
jl1 = new JLabel("player1: ");
layerOne.add(jl1);
layerOne.setBounds(5, 100, 50, 50);
jl1Add = new JLabel("");
layerOne.add(jl1Add);               
westP.add(layerOne,0, 0);

类似于另一个JPanel,除了

westP.add(LayerTwo,0,1);

以后:

panel2.setLayout(new BorderLayout());
panel2.add(westP);
add(panel2, BorderLayout.WEST);

稍后当我测试它时,我会在GUI上显示lbl1,lbl1Add,lbl2而不是lbl2Add?

if (activeColour==RED)
{
   timesPlayedRed++;                  
   jl1Add.setText("");
   jl1Add.setText(String.valueOf((timesPlayedRed)));
   activeColour=YELLOW;
}
else
{
timesPlayedYellow++;
jl2Add.setText("");
jl2Add.setText(String.valueOf((timesPlayedYellow)));
activeColour=RED;
}

我只是在试用java和netbeans。

0 个答案:

没有答案