我有一个 JFrame,东西两个按钮,北标签,南标签和文本字段。和一个图像在中心。我想在中心 30 秒后调用另一个图像。但是每次我调用第二张图像时,北、南、东和西的组件都在消失。
这是我的代码。//JFrame 中的组件。
firstPicblur = new JPanel(new BorderLayout());
pictureblur01 = new ImageIcon("C:\\java pics\\papsi2.jpg");
pictureblurA = new JLabel(pictureblur01);
firstPicblur.add(pictureblurA,BorderLayout.CENTER);
//FirstPicture blurred B
firstPicblurB = new JPanel(new BorderLayout());
pictureblur02 = new ImageIcon("C:\\java pics\\papsi1.jpg");
pictureblurB = new JLabel(pictureblur02);
firstPicblurB.add(pictureblurB,BorderLayout.CENTER);
//Next0Prev buttons
Next0Prev = new JPanel(new BorderLayout());
Next = new JButton("NEXT");
Prev = new JButton("PREV");
//Next0Prev labels is constant at SOUTH
firstPicblurA = new JPanel(new BorderLayout());
clueNo1 = new JLabel("Picture Number 01");
TypeHere = new JTextField("Guess Who");
firstPicblurA.add(TypeHere, BorderLayout.CENTER);
firstPicblurA.add(clueNo1, BorderLayout.SOUTH);
Next0Prev.add(firstPicblur,BorderLayout.CENTER);
Next0Prev.add(Next,BorderLayout.EAST);
Next0Prev.add(Prev,BorderLayout.WEST);
Next0Prev.add(firstPicblurA,BorderLayout.SOUTH);
//其他组件
这是actionEvent
if(e.getSource() == continueButton){
add(Next0Prev);
Next0Prev.setVisible(true);
Next0Prev.repaint();
Next0Prev.revalidate();
loadingEffectBtn.setVisible(false);
Timer ta = new Timer(10000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
add(firstPicblurB);
firstPicblurB.setVisible(true);
Next0Prev.setVisible(true);
}
});
ta.start();
ta.setRepeats(true);
}
但是当我这样做时。第二张图片出现在中心,但 N、E、W、S 分量正在消失。