在新的applet窗口中获取所需的输出

时间:2013-12-09 08:43:02

标签: java applet

我正在制作一个样本倒计时器应用程序,它会在点击提交按钮时在新的子applet窗口中打开一个倒数计时器。

我的代码:

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 void 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);

}

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();
        System.out.println("Submit event"); 
        System.out.println(inputLine.getText());
        frame.show(doCountDown(inputLine.getText()));
        ;

    }



} 

}

这里倒计时开始只在父窗口中提交按钮而不是进入子窗口(子窗口就像一个空白屏幕一样)如何完成它?

0 个答案:

没有答案