我目前正在创建一个程序,我试图让JLabel在从#34;是"中清除之后进入JFrame。被压在JOptionPane上。目前,我还没能让它工作.ready = new JLabel("你准备好了吗?"); ready.setToolTipText("你准备好开始了吗?");
}
private class thehandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
String string = "";
Object[] options1 = {"Yes","No"};
if (event.getSource()==pname) {
string=String.format("You entered the name, %s, is this correct?", event.getActionCommand());
int n = JOptionPane.showOptionDialog(null, string, "Is this name correct?", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, null);
if (n == JOptionPane.YES_OPTION) {
getContentPane().removeAll();
revalidate();
repaint();
add(credits);
add(ready);
}`
为防止混淆,上面有更多代码,基本上在公共类窗口中声明私有JLabel就可以扩展JFrame。
答案 0 :(得分:2)
在完成对UI的更改(删除并添加)后,调用revalidate
和repaint