0

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??

JavaLearner
  • 41
  • 1
  • 2
  • 6
  • 1) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). 2) Why code an applet? If it is due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). – Andrew Thompson Dec 09 '13 at 08:46
  • I am just learning applet thats why I have to do it in applets.. Are u having any idea regardin what change shall I make to this code for getting the required output?? – JavaLearner Dec 09 '13 at 09:54
  • Ignore AWT & learn Swing at least. – Andrew Thompson Dec 09 '13 at 10:06
  • `Frame.show` takes a boolean argument, but `doCountDown` returns void. It's compile error. – zakki Dec 10 '13 at 06:57

0 Answers0