0 Replies - 118 Views - Last Post: 03 October 2012 - 07:16 AM Rate Topic: -----

#1 mhaiynepot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-October 12

error in getting current time in clock for computation

Posted 03 October 2012 - 07:16 AM

Hi I can't seem to get the right time for the computation of the salary ,when I try to get the time it's stuck wid the time when you ran the program and it doesn't update not like the clock that I have displayed
import java.util.*;
import java.util.Date; 	
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit.*;
public class Payroll2
extends JFrame implements ItemListener,ActionListener
{
	


SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String str = sdf.format(new Date());


 class Clock extends Thread {

        JLabel labelToUpdate;

         

        Clock(JLabel label) {

            labelToUpdate = label;

        }

        public void run() {

            Date date = new Date();

            for(;;)/> {

                date.setTime(System.currentTimeMillis());

                labelToUpdate.setText(date.toString());

                labelToUpdate.repaint();

                try {

                    Thread.sleep(1000);
                }

                catch(Exception e) {
                	}
            }
        }
 }
       
String input;
 int x;
String[]idnum={"311","232","565","432"};
  String[]name1={"Hulk","Ironman","Captain America","Thor"};
    int[]rates={5,2,4,1};
    String[]position={"pres","sec","janitor","basurero",};


	String a,b,c,d,e,f,g,h,i,j,k,l,m,n,o;

	int x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;////attendace


int Day1,Day2,Day3,Day4,Day5,Day6,Day7,Day8,Day9,Day10,Day11,Day12,Day13,Day14,Day15;

///////



JLabel question=new JLabel("Good day!Press Finish if the information below ");
JLabel question2=new JLabel("is not yours.Press proceed otherwise");
Font bigFont=new Font("Arial",Font.BOLD,12);
JTextArea answer=new JTextArea();

 JButton pressMe=new JButton("Proceed");
JLabel greet2=new JLabel();
JLabel greet3=new JLabel();
///////////////
final int BASE_SALARY=0;
final int SSS=50;
final int PHIL=50;  ////values for insurance deductions
final int PAGIBIG=50;
final int rate = 25;
//////////////////////
int totalPrice =BASE_SALARY;
JLabel days=new JLabel("                             Check what days you have attended");
JCheckBox firstBox=new JCheckBox
("1st day",false);
JCheckBox secondBox=new JCheckBox
("2nd day",false);
JCheckBox thirdBox=new JCheckBox
("3rd day",false);
JCheckBox fourthBox=new JCheckBox
("4th day",false);
JCheckBox fifthBox=new JCheckBox
("5th day",false);
JCheckBox sixthBox=new JCheckBox
("6th day",false);
JCheckBox seventhtBox=new JCheckBox
("7th day",false);
JCheckBox eightBox=new JCheckBox
("8th day",false);
JCheckBox ninthBox=new JCheckBox
("9th day",false);
JCheckBox tenthBox=new JCheckBox  ////////the checkboxes
("10th day",false);
JCheckBox eleventhBox=new JCheckBox
("11th day",false);
JCheckBox twelfthBox=new JCheckBox
("12th day",false);
JCheckBox thirthBox=new JCheckBox
("13th day",false);
JCheckBox forthBox=new JCheckBox
("14th day",false);
JCheckBox fiftenBox=new JCheckBox
("15th day",false);
//////////////////////////

JCheckBox PhilBox=new JCheckBox
("PhilHealth tax will have a deduction of Php 100",false);
JCheckBox sssBox=new JCheckBox   ////////insurances
("SSS tax will have a deduction of Php 150",false);
JCheckBox pagibigBox=new JCheckBox
("Pag-ibig tax will have a deduction of Php 100" ,false);
////////////////////////////////////////
JLabel greet=new JLabel("Greetings ");

JLabel sal=new JLabel("                       Your total salary is Php ");
JTextField totPrice=new JTextField(10);

JLabel optionExplainLabel2=new JLabel("                            Please check the organizations you've joined");
JButton exitBox=new JButton("Finish");

JTextField empinfo=new JTextField(25);
JTextField answer1=new JTextField(35);

public Payroll2()
{
 
		super("Payroll System!");
JLabel label = new JLabel();

        getContentPane().add(label);

        Thread t = new Clock(label);

        t.start();
        
setBackground(new Color(5,13,87));

    String input=JOptionPane.showInputDialog(null,"enter idnum");

    for(x=0; x<idnum.length;x++)
    {
    if(input.equals(idnum[x])){
    
    	answer.setText("Employee's name:  "+name1[x]+"\nEmployee's rate:   "+rates[x]+"\nEmployee's position:   "+position[x]);
        answer1.setText(name1[x]);
    }
   

   }



    




	setLayout(new FlowLayout());

	setBounds(390,200,100,1500);

answer.setPreferredSize(new Dimension(300,100));
question.setFont(bigFont);
greet2.setFont(bigFont);
greet3.setFont(bigFont);
add(question);
add(question2);
add(answer);

add(pressMe);
pressMe.setHorizontalTextPosition(AbstractButton.CENTER);
    greet2.setVerticalTextPosition( SwingConstants.CENTER);
greet2.setAlignmentX(50);
add(greet2);
add(greet3);
pressMe.addActionListener(this);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


	add(days);
	///////////////////////
	add(firstBox);
	add(secondBox);
	add(thirdBox);
	add(fourthBox);
	add(fifthBox);
	add(sixthBox);
	add(seventhtBox);
	add(eightBox);
	add(ninthBox);
	add(tenthBox);
	add(eleventhBox);
	add(twelfthBox);
	add(thirthBox);
	add(forthBox);
	add(fiftenBox);

	//////////////////////////

	add(optionExplainLabel2);
	add(PhilBox);
	add(sssBox);
	add(pagibigBox);
	add(greet);

	add(sal);
	add(totPrice);
	add(empinfo);
	add(exitBox);
	totPrice.setText(" "+totalPrice);
	firstBox.addItemListener(this);
	secondBox.addItemListener(this);
	thirdBox.addItemListener(this);
	fourthBox.addItemListener(this);
	fifthBox.addItemListener(this);
	sixthBox.addItemListener(this);
	seventhtBox.addItemListener(this);
	eightBox.addItemListener(this);
	ninthBox.addItemListener(this);
	tenthBox.addItemListener(this);
	eleventhBox.addItemListener(this);
	twelfthBox.addItemListener(this);
	thirthBox.addItemListener(this);
	forthBox.addItemListener(this);
	fiftenBox.addItemListener(this);
	sssBox.addItemListener(this);
	pagibigBox.addItemListener(this);
	PhilBox.addItemListener(this);
		exitBox.addActionListener(this);
    pressMe.setPreferredSize(new Dimension(250, 20));
    	firstBox.setPreferredSize(new Dimension(95, 20));
  
  	//////////////

}	


   
public  void actionPerformed(ActionEvent e)
{

String name=answer1.getText();
String gg="Hello, "+name+"  Please proceed if you wish to ";
String hh="know your salary \nif not clic Finish to exit ";
greet2.setText(gg);
greet3.setText(hh);

Object src = e.getSource();
 if (src == exitBox) {
 	
      System.exit(0);
    }
}

public void itemStateChanged(ItemEvent event)
{

  Object source=event.getSource();
  int select=event.getStateChange();

  if(source==sssBox)
  	if(select==ItemEvent.SELECTED)


  		totalPrice-=SSS;


  		else
  			totalPrice+=SSS;

  				if(select==ItemEvent.SELECTED)
  					totalPrice-=PAGIBIG;
  					else
  				totalPrice+=PAGIBIG;
  					totPrice.setText(" "+ totalPrice);

	if(select==ItemEvent.SELECTED)
  							totalPrice-=PHIL;
  							else
  								totalPrice+=PHIL;
  								totPrice.setText(" "+ totalPrice);




				
	if(source==firstBox)
				if(select==ItemEvent.SELECTED)
  					{
						try
						{
						
							int attend1=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend1==JOptionPane.YES_OPTION)                   
								
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);/////i need to get the hours here
                        
							}
							if(attend1==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
								
							}
							
						int attend11=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend11==JOptionPane.YES_OPTION)
								
								
							{
                        JOptionPane.showMessageDialog(null, " Time out at "+str);
                         firstBox.setEnabled(false);
                        
							}
							if(attend11==JOptionPane.NO_OPTION)
							{
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
                        
							}
					
						
						}

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==secondBox)
				if(select==ItemEvent.SELECTED)
  					{
						try
						{

  						int attend2=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend2==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend2==JOptionPane.NO_OPTION)
							{
							setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend22=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend22==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                         secondBox.setEnabled(false);
                        
							}
							if(attend22==JOptionPane.NO_OPTION)
							
                        
                        setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==thirdBox)
			if(select==ItemEvent.SELECTED)

  					{
						try
						{

  						int attend3=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend3==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend3==JOptionPane.NO_OPTION)
							{
							setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend33=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend33==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                       thirdBox.setEnabled(false);
							}
							if(attend33==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==fourthBox)
					if(select==ItemEvent.SELECTED)
  					{
						try
							{

  						int attend4=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend4==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend4==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend44=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend44==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                        
							}
							if(attend44==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							
						catch(NumberFormatException mistake)
						{
						System.out.println();
						}

  					}
						if(source==fifthBox)
	if(select==ItemEvent.SELECTED)

  					{
						try
						{

  						int attend5=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend5==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend5==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend55=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend55==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                        
							}
							if(attend55==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==sixthBox)
	if(select==ItemEvent.SELECTED)
  					{
						try
						{

  						int attend6=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend6==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend6==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend66=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend66==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                        
							}
							if(attend66==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}

  					}
						if(source==seventhtBox)
	if(select==ItemEvent.SELECTED)

  					{
						try
							{

  						int attend7=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend7==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend7==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend77=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend77==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                        
							}
							if(attend77==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==eightBox)
	if(select==ItemEvent.SELECTED)
  					{
						try
						{

  						int attend8=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend8==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend8==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend88=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend88==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                        
							}
							if(attend88==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}
  					}

						if(source==ninthBox)
if(select==ItemEvent.SELECTED)

  					{
						try
							{

  						int attend9=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend9==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend9==JOptionPane.NO_OPTION)
							{
									setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend99=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend99==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                        
							}
							if(attend99==JOptionPane.NO_OPTION)
							
                        
                        		setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==tenthBox)
if(select==ItemEvent.SELECTED)
  					{
						try
						{

  						int attend10=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend10==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend10==JOptionPane.NO_OPTION)
							{
									setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend1010=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend1010==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
                        
							}
							if(attend1010==JOptionPane.NO_OPTION)
							
                        
                        		setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}

  					}
						if(source==eleventhBox)
	if(select==ItemEvent.SELECTED)

  					{
						try
							{

  						int attend11th=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend11th==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend11th==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend11ths=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend11ths==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time out at "+str);
                        
                        
							}
							if(attend11ths==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}
							

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==twelfthBox)
	if(select==ItemEvent.SELECTED)
  					{
						try
						{

  						int attend12=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend12==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend12==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend1212=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend1212==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time out at "+str);
                        
                        
							}
							if(attend1212==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}

  					if(source==thirthBox)

  			if(select==ItemEvent.SELECTED)

  					{
						try
							{

  						int attend13=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend13==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend13==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend1313=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend1313==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time out at "+str);
                        
                        
							}
							if(attend1313==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}


  					if(source==forthBox)
if(select==ItemEvent.SELECTED)
  					{
						try
						{

  						int attend14=JOptionPane.showConfirmDialog(null,"Would you like to time in?");
							if(attend14==JOptionPane.YES_OPTION)
							{
							
                        JOptionPane.showMessageDialog(null, " Time in at "+str);
                        
							}
							if(attend14==JOptionPane.NO_OPTION)
							{
								setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
							}
						int attend1414=JOptionPane.showConfirmDialog(null,"Would you like to time out?");
							if(attend1414==JOptionPane.YES_OPTION)
							{
                        JOptionPane.showMessageDialog(null, " Time out at "+str);
                        
                        
							}
							if(attend1414==JOptionPane.NO_OPTION)
							
                        
                        	setDefaultCloseOperation(JOptionPane.CLOSED_OPTION);
						}

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}


  					}
  					if(source==fiftenBox)

  			if(select==ItemEvent.SELECTED)

  					{
						try
						{

  						o = JOptionPane.showInputDialog(null,"How many hours of work?");
						x15 = Integer.parseInt(o);
						Day15 = x15 * rate;
						totalPrice = totalPrice + Day15;
						totPrice.setText(" " + totalPrice);
						 fiftenBox.setEnabled(false);
						}

						catch(NumberFormatException mistake)
						{
						System.out.println();
						}

 return;
  					}

}



  		public static void main(String[]arguments)
  		{


  			Payroll2 aFrame= new Payroll2();


     


                                 //create window
  			final int WIDTH=440;
  			final int HEIGHT=500;
  			aFrame.setSize(WIDTH,HEIGHT);
  			aFrame.setVisible(true);




    }
     

    
}


This post has been edited by macosxnerd101: 03 October 2012 - 07:21 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Page 1 of 1