I am working on a sample countdown timer application which opens up a countdown timer in a new child applet window on clicking the submit button.
My code:
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()));
;
}
}
}
here the countdown is starting on clikcing the submit button only in the parent window and is not goin to the child window (child window is coming just as a blank screen) How to get it done??