Results 1 to 3 of 3

Thread: Need Help About IF and Time

  1. #1
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need Help About IF and Time

    This program is to Manage Labor Attendance List with Java using Microsoft Access application database but its not complete yet. So I need help to complete this program.

    Here is the link to download:

    http://www.kitaupload.com/download.p...avaProject.rar

    1. I need some help, There is some problem in my coding, My clock is not ticking.
    So I need Timer Coding to make the clock clock ticking.

    2. I want to set If After 8AM In the database "Terlambat +1"
    If after 9AM "Absent +1"

    This two condition is used for login button.

    3. Before 5PM show dialog "Working Time"

    Please Help Me..

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.sql.*;
    import java.util.*;
    import java.awt.event.*;
    import java.util.Date;
    
    class lblRenderer extends JLabel implements ListCellRenderer
    {
    		lblRenderer()
    		{
    			setBackground(Color.white);
    			this.setOpaque(true);
    		}
    		public Component getListCellRendererComponent(JList list, Object item,int 
    
    index,boolean focus,boolean isSelected)
    		{
    			setText(item.toString());
    			setBackground(focus?Color.blue:Color.yellow);
    			setForeground(focus?Color.white:Color.black);
    			return this;
    		}
    }
    
    
    public class Absen extends JFrame implements ActionListener{
    	public JLabel lblid, lblpass;
    	public JPasswordField pass;
    	public JTextField txtid, txtdate;
    	public JButton login, logout, clear, exit;
    	public Date waktu=new Date();
    	public Font f = new Font("monotype corsiva",Font.PLAIN,18);
    	public Color cl = new Color(0,255,0);
    	
    	public Absen(){
    		super("Apikasi Absen");
    		initobjek();
    		design();
    	}
    	
    	public void initobjek(){
    		setTitle("Absen Karyawan");
    		lblid	= new JLabel("ID 		 ");
    		lblpass = new JLabel("Password	 ");
    		txtdate = new JTextField(waktu.getHours() +":"+ 
    
    waktu.getMinutes()+":"+waktu.getSeconds()); //the clock is not ticking
    		txtdate.setEditable(false);
    		pass	= new JPasswordField(10);
    		txtid	= new JTextField(20);
    		login	= new JButton("Absen Masuk");
    		logout	= new JButton("Absen Pulang");
    		clear	= new JButton("Clear");
    		exit	= new JButton("Exit");
    		login.addActionListener(this);
    		logout.addActionListener(this);
    		clear.addActionListener(this);
    		exit.addActionListener(this);
    		design();
    	}
    	
    	public void design(){
    		Container c = getContentPane();
    		c.setLayout(null);
    		c.setBackground(Color.blue);
    		c.add(lblid);
    		c.add(lblpass);
    		c.add(txtdate);
    		c.add(pass);
    		c.add(txtid);
    		c.add(login);
    		c.add(logout);
    		c.add(clear);
    		c.add(exit);
    		
    		lblid.setBounds(20,20,80,30);
    		lblpass.setBounds(20,50,80,30);
    		txtdate.setBounds(150,250,60,30);
    		txtid.setBounds(90,20,120,30);
    		pass.setBounds(90,50,120,30);
    		login.setBounds	(new Rectangle(20,100,150,30));
    		logout.setBounds(new Rectangle(20,140,150,30));
    		clear.setBounds	(new Rectangle(200,100,120,30));
    		exit.setBounds	(new Rectangle(200,140,120,30));
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setSize(400,400);
    		setLocation(200,200);
    		show();
    	}
    	
    	private void clear(){
    		txtid.setText("");
    		pass.setText("");
    	}
    	
    	//this is not clear because the if is wrong
    	private void loggin(){
    		try
    		{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    			Connection con 
    
    =DriverManager.getConnection("jdbc:odbc:Driver=Microsoft Access Driver 
    
    (*.mdb);DBQ=Absen.mdb","","");
    			Statement stat = con.createStatement();
    			ResultSet data = stat.executeQuery("SELECT*FROM Absen WHERE 
    
    Nama='"+txtid.getText()+"'");
    			if(data.next())
    			{
    				if (txtdate>=(waktu.()))
    				{
    					Statement save = con.createStatement();
    					String query = "Update Absen set 
    
    Terlambat=Terlambat+1";
    					int jumlah = save.executeUpdate(query);
    	
    					if(jumlah==1)
    					JOptionPane.showMessageDialog(null,"Kamu 
    
    Terlambat");
    
    					save.close();
    				}
    			
    					
    				if (txtdate>=(waktu.setHours(9)+":"+waktu.setMinutes(0)))
    				{
    					Statement save1 = con.createStatement();
    					String query = "Update Absen set Absen=Absen+1";
    	
    					int jumlah = save1.executeUpdate(query);
    	
    					if(jumlah==1)
    					JOptionPane.showMessageDialog(null,"Kamu 
    
    Terhitung Absen");
    
    					save1.close();
    				}
    				else
    				JOptionPane.showMessageDialog(null,"Nilai yang di masukan 
    
    salah");
    				
    			}
    			stat.close();
    			con.close();
    		}
    		catch(Exception a){
    			System.out.println("Error! "+a);
    		}
    	}
    
    	//this is not clear			
    	public void actionPerformed(ActionEvent x){
    		if (x.getSource()==exit)
    			System.exit(0);
    			else if (x.getSource()==clear)
    				clear();
    				else if (x.getSource()==login)
    					//?
    	}
    	
    			
    		
    	public static void main(String args[]){
    		new Absen();
    	}
    }
    i have a database using microsoft access which have Nama, Password, Terlambat and Absen for the fields
    Last edited by parahui; 04-24-2008 at 04:17 AM. Reason: the link is dead i change 4 code

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    that link is dead...

    you can post the code here using [code][/code] tags

  3. #3
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help me plz

    ooo master boogyman help me T-T
    any one help me T-T

Bookmarks

Posting Permissions

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