Hi i am trying to make taxi meter which shows the current price.Rightnow I have to click startmeter afterevery 1 minute than it's update the new price but I want it to update automatically once the price change after 1 minute instead of me pressing startmeter everytime.thanks for your help.

import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.event.ActionListener;
import javax.swing.Timer; 
import java.awt.event.*;

public class taximeter extends JFrame{

    JButton start;
    JButton end;
    JLabel total;
    JPanel panel;
    Container pane;
    long star=-1;
    long sto=-1;

    public taximeter(){

     super("Taxi Meter");

      JButton start=new JButton("Start meter");
      JButton stop=new JButton("Stop meter");
        JLabel total=new JLabel("$0.00");


        panel=new JPanel();


        start.setBounds(40, 50, 120, 40);

        stop.setBounds(40, 125, 120, 40);

        total.setBounds(75, 5, 120, 40);

        Container pane=getContentPane();


        GregorianCalendar jc=new GregorianCalendar();
        int lj=jc.getTime().getHours();
        int tj=jc.get(Calendar.HOUR);
        int ne=jc.get(Calendar.MINUTE);
        int jx=jc.get(Calendar.SECOND);

        stop.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e){


                    total.setText("$ 5.00");




           start.addActionListener(new ActionListener()
                    public void actionPerformed(ActionEvent e){

                        int ld=jc.get(Calendar.MINUTE);
                        int mi=ne-ld;
                        int kd=mi*2;
                        int jm=kd+5;
                        int bc=jc.get(Calendar.HOUR);
                        int dc=(ld-ne)*5;


                    sto = System.currentTimeMillis() - star;
                    long lp = sto/(60*1000)% 60;
                    long ts=(lp*3)+3;

                    String lq=Long.toString(ts);







    public static void main(String[] args) {

  taximeter mw=new taximeter();
  mw.setSize(200, 200);


Re: need help in setting timer 80 80

Use a javax.swing.Timer to call a method that updates the info every 60,000 milliseconds. See the API doc for details

Re: need help in setting timer 80 80

also, for readability purposes, remove all those blank lines in your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.