0

In my application, when I am clicking on the submit button then new applet window is opening fine but it is only showing the value entered in the textbox of parent window, the countdown is happening only in the parent window. I want countdown to happen in the child window once the submit is clicked (starting from the value entered in textbox). What I am doing wrong here?

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

        }

    } 
}
JavaLearner
  • 41
  • 1
  • 2
  • 6
  • 1) Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. 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 11 '13 at 05:53
  • .. 3) 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). 4) That code does `String` comparison incorrectly: change `tmp=="Submit"` to `tmp.equals("Submit")`. – Andrew Thompson Dec 11 '13 at 05:54

0 Answers0