applet在showInputDialog之后变为空白

时间:2014-11-22 19:25:47

标签: java applet

我正在开发一个applet。我想通过输入对话框接收用户名。所以在init()中,我添加了以下代码。

String userName = JOptionPane.showInputDialog("Please enter your name"); 

当我启动applet时,通过applet viewer,输入对话框会按预期弹出。但在我填写名称后,applet变成空白。并且在调整小程序屏幕大小时会重新出现所有组件。

 public class test extends JApplet implements ActionListener{ 

  stage s = new stage(); //Object of the a class that extends JPanel
 public void init(){
   //Other initialisations here
    String userName = JOptionPane.showInputDialog("Please enter your name"); 
 }


  public void paint(Graphics g){
  s.repaint();
  //A separate paint code
}
 public void actionPerformed(ActionEvent ae){
     repaint();

}
}

这是整个代码的骨架。

我不确定骨架是否会有所帮助。实际的代码很长。 我抛弃了整个代码here,以防万一。

我不确定为什么会这样。没有InputDialog,applet工作正常。投入之后表现得很奇怪。有人可以帮忙。感谢。

0 个答案:

没有答案
相关问题