java - simple timer, starting from 0 to whatever number -


i trying make simple timer, starting 0 whatever number.i want interrup timer when press button. i've done far, i'n not interested button part yet.when run, don't displayed.

import java.util.arraylist;  import javax.swing.*;  import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener;     /*lista clienti care asteapta avem timer->creaza action event care il tratam in action performed--crestem timpul simu;larii cu 1 in action performed,apoi parcurgem lista de clienti care ast si verificam care clienti au timpul de arival = timpul simulatrii --fiecare client e distribuit la una din cozi-for pt fiecare client. gasim coada cu timpul min de asteptare si il adaugam acolo--tot in action performed daca timpul de servire ajun l;a 0  clientul e scos din coada  */ public class magazin extends jframe{     //protected arraylist<clienti> arrayclienti = new arraylist<clienti>();       public magazin(){      }     class event implements actionlistener{         public void actionperformed(actionevent e) {             // todo auto-generated method stub             int count = 0;             count++;                 timeclass tc=new timeclass(count);                 timer timer= new timer(1000,tc);                 timer.start();             //system.out.println(count+"sec:");         }      }     class timeclass implements actionlistener{     int counter;         public timeclass(int counter){             this.counter=counter;                    }         public void actionperformed(actionevent tc) {             counter++;             system.out.println("sec:"+counter);         }     } } 

in main class have this:

public class main {      public static void main(string args[]) {           new magazin();       } 

you need create , display top-level window visible, means since you're using jframe, somewhere in code you'll need main method, , somewhere in code called, you'll need:

magazin magazin = new magazin(); // create jframe magazin.setvisible(true);  // display it. 

i don't see main method anywhere or setting jframe visible. you've got other problems well, first step you'll need creating visible gui.

some other issues:

  • you've got arraylist of something, clienti, never used.
  • you've got no component, such jlabel, displaying time.
  • your timer's actionlistener creates new jframe -- why want that?
  • your magazin class has actionperformed method -- why? it's not acting actionlistener , not implement actionlistener.

you want study swing tutorials better understand how use these tools. can find links swing tutorials , other swing resources here: swing info


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -