在我的应用程序中,当我点击提交按钮时,新的小程序窗口打开正常,但它只显示在父窗口的文本框中输入的值,倒计时仅在父窗口中发生。单击提交后,我希望在子窗口中进行倒计时(从文本框中输入的值开始)。我在这做错了什么?
package com.tcs.applet;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.Timer;
import java.util.TimerTask;
//import javax.swing.JButton;
public class MyApplet extends Applet implements ActionListener {
static int interval;
static Timer timer;
TextField inputLine = new TextField(15);
private Button button = new Button("Submit");
Label tmpLbl = new Label();
public MyApplet() {
button.addActionListener(this);
add(inputLine);
add(button);
add(tmpLbl);
// button.addActionListener(ActionListener act);
// / doCountDown("10");
}
private String doCountDown(String secInput){
int delay = 1000;
int period = 1000;
timer = new Timer();
interval = Integer.parseInt(secInput);
// System.out.println(secs);
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
// System.out.println(setInterval());
int tmpTimer=setInterval();
tmpLbl.setText(Integer.toString(tmpTimer));
}
}, delay, period);
return secInput;
}
private static final int setInterval() {
if (interval == 1)
timer.cancel();
return --interval;
}
// setup all the context...
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Button source = (Button)e.getSource();
String tmp=e.getActionCommand();
if (tmp=="Submit"){
Frame frame = new Frame();
frame.setSize(1000, 300);
Label jname=new Label(doCountDown(inputLine.getText()));
frame.add(jname);
int tmpTimer=setInterval();
frame.show();
}
}
}