Results 1 to 3 of 3
  1. #1
    Yids is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default Problems with Timer Constructor

    Hi there. I am a student at uni who is doing a a few java topics. I have been asked to create a gui which represents a microwave. I have set the interface and gotten the buttons to respond by using a listener. However I keep having trouble trying to initiate a timer. I get this error message:

    Symbol: Constructor Timer(int, microwave.Contents.ButtonListener)
    Location: Class java.util.Timer

    Here is my code.


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package microwave;


    import java.util.Timer;

    import javax.swing.border.Border;

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    /**
    *
    * @author The Borg Collective
    */
    public class Contents extends JPanel{


    Main man;

    private int microhead;
    private int DELAY = 20;

    JButton one;
    JButton two;
    JButton three;
    JButton four;
    JButton five;
    JButton six;
    JButton seven;
    JButton eight;
    JButton nine;
    JButton zero;
    JButton start;
    JButton stop;

    JPanel panel;
    JPanel microwaveFront;
    JPanel top;
    JPanel frame;

    JLabel label;

    Border blackline;

    Timer timer;

    public Contents(){
    microhead = 0;

    timer = new Timer(DELAY, new ButtonListener());

    ^^ Problem Line

    one = new JButton();
    one.setText("1");
    one.addActionListener (new ButtonListener());

    two = new JButton();
    two.setText("2");
    two.addActionListener (new ButtonListener());

    three = new JButton ();
    three.setText("3");
    three.addActionListener (new ButtonListener());

    four = new JButton ();
    four.setText("4");
    four.addActionListener (new ButtonListener());

    five = new JButton ();
    five.setText("5");
    five.addActionListener (new ButtonListener());

    six = new JButton ();
    six.setText("6");
    six.addActionListener (new ButtonListener());

    seven = new JButton ();
    seven.setText("7");
    seven.addActionListener (new ButtonListener());

    eight = new JButton ("8");
    eight.setText("8");
    eight.addActionListener (new ButtonListener());

    nine = new JButton ();
    nine.setText("9");
    nine.addActionListener (new ButtonListener());

    zero = new JButton ();
    zero.setText("0");
    zero.addActionListener (new ButtonListener());

    start = new JButton ();
    start.setText("Start");
    start.addActionListener (new ButtonListener());

    stop = new JButton ();
    stop.setText("Stop");
    stop.addActionListener (new ButtonListener());

    label = new JLabel();

    panel = new JPanel();

    microwaveFront = new JPanel();
    microwaveFront.setPreferredSize(new Dimension(500, 0));
    microwaveFront.setBackground(Color.gray);

    blackline = BorderFactory.createLineBorder(Color.black);
    microwaveFront.setBorder(blackline);

    label.setBorder(blackline);
    label.setPreferredSize(new Dimension(250,50));
    one.setPreferredSize(new Dimension(80,50));

    panel.setBounds(0, 0, 400, 200);

    setLayout(new BorderLayout());

    top = new JPanel();
    frame = new JPanel();
    frame.setPreferredSize(new Dimension(300, 0));

    GridLayout experimentLayout = new GridLayout(0,3);
    GridLayout experimentLayout2 = new GridLayout(0,2);


    panel.setLayout(experimentLayout);



    top.add(label);
    panel.add(one);
    panel.add(two);
    panel.add(three);
    panel.add(four);
    panel.add(five);
    panel.add(six);
    panel.add(seven);
    panel.add(eight);
    panel.add(nine);
    panel.add(start);
    panel.add(stop);

    add(microwaveFront, BorderLayout.WEST);
    frame.add(top, BorderLayout.NORTH);
    frame.add(panel, BorderLayout.SOUTH);

    add(frame, BorderLayout.EAST);


    }

    private class ButtonListener implements ActionListener{

    public void actionPerformed (ActionEvent event){



    if(event.getSource() != start && event.getSource() != stop){
    label.setText(label.getText() + event.getActionCommand().charAt(0));
    }
    else if(event.getSource() == start){

    label.setText("trst");


    }
    else{
    label.setText("stopping");
    }
    }
    }

    private class timerStarter implements ActionListener{
    public void actionPerformed (ActionEvent event){

    }
    }




    }


    I am using a netbeans IDE. Is there any reason I am getting this message. What do I seem to be missing?

  2. #2
    Yids is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    Also I am trying to get the timer to count down from a specified amount of seconds. In example, if the user presses the 1 and 0 buttons, the counter should count down from ten.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,271
    Blog Entries
    1
    Rep Power
    25

    Default

    Please don't force us to discuss this problem in multiple threads. Only ask this question once in one forum only. Locking this thread.

Similar Threads

  1. Stopping a Timer from Inside the timer
    By krishnan in forum Java Applets
    Replies: 2
    Last Post: 10-04-2010, 11:15 PM
  2. timr task and timer problems
    By jazzist in forum CLDC and MIDP
    Replies: 1
    Last Post: 10-01-2010, 06:36 AM
  3. Problems with Graphics and a Timer...
    By r0binho0d in forum Java Applets
    Replies: 5
    Last Post: 07-26-2008, 03:03 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:46 PM
  5. Replies: 1
    Last Post: 12-14-2007, 07:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •