DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: login problem

  1. #1
    Join Date
    Jul 2004

    login problem

    Hi everyone.I'm basically new to java but with the help of this forum i hope to get better.I'm currently busy with a user login interface project(see code below) and I'm a bit stuck now and i need help.

    When the login button(submit) is clicked i want the program to connect to a db(which i have already acomplished),and after authentication i want it to dispose the full screen frame,set timerframe visible and launch the count down timer.when the counter reaches zero,the timerframe must dispose and the the full screen frame set visible.
    I also want to block out any special keys (e.g ctrl-alt-del , alt F4 ,alt Esc etc)
    i'm using the j2sdk1.4.2_04 version.

    P.s Feel free to alter or add anything to the existing code.
    coments will be appreciated

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*; //Header files used
    import java.lang.ClassNotFoundException;
    import java.text.NumberFormat;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    import java.sql.*;
    import javax.swing.*;
    public class real implements Runnable 
    	JFrame timerframe;
    	JFrame frame;
    	JLabel label;
    		public real(JFrame timerframe, JLabel label, JFrame frame)
    		this.timerframe = timerframe;
    		this.label = label;
    		this.frame = frame;
    		//Entry class
    	public static void main(String args[]) 
    		JFrame timerframe = new JFrame();		 	//Create a new JFrame      called timerframe;
    		JTextField username = new JTextField(10);  		//Create a JTextField called username
    		JFrame frame = new JFrame("Login"); 	//Create a new JFrame called frame;
    		JPasswordField password = new JPasswordField(8); 	//Create new JPasswordField - password;
    		JLabel label = new JLabel(); 				//Create a JLabel called label
    		JLabel labname = new JLabel( "Enter User Name: "); 	//Create a JLabel called labname
    		JLabel labpass = new JLabel( "Enter Password: " ); 	//Create a JLabel called labpass
    		JLabel emptyLabel1 = new JLabel("                  ");  //Create an Empty Label number 1
    		JLabel emptyLabel2 = new JLabel("                  ");  //Create an Empty Label number 2
    		JButton submit = new JButton("Login"); 			//Created a JButton called submit
    		JButton exit = new JButton("Exit"); 			//Created a JButton called exit
    		label.setBackground(Color.WHITE); 			//Sets the background to white
    		label.setForeground(Color.BLACK); 			//Sets the foreground to black
    		username.setFont(new Font("Serif", Font.BOLD, 18)); 	//Set the username font type
    		password.setFont(new Font("Serif", Font.BOLD, 24)); 	//Set the password font type
    		timerframe.setSize(185, 19); 				//Sets the size of the JFrame
    		frame.setBackground(Color.white); 			//Set Framebackground
    		setFullScreenWindow(frame);				//Set Frame Size and position               
    		frame.getContentPane().setLayout(new GridBagLayout());  //set new layout
    		exit.addActionListener(new ActionListener() 
    		{ 							//This will set the action when the button is pressed on
    			public void actionPerformed(ActionEvent ae)
    			{ 						//This would be the method that has to be overridden
    				System.out.println("The Exit button was pushed");
    		submit.addActionListener(new ActionListener()
    							//This will set the action when the button is pressed on
    			public void actionPerformed(ActionEvent ae)
    			{ 						//This would be the method that has to be overridden
    			        Connection connection = null;
    				try { 					//This should connect to a database
    					String driverName = "org.gjt.mm.mysql.Driver";
    					String serverName = "SEAL";
    					String mydatabase = "TEST";						//Database connection
    					String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
    					String username = "BATTMAN";
    					String password = "SPIDERMAN";
    					connection = DriverManager.getConnection(url, username, password);
            				System.out.println("Successfully connected to MySQL server using TCP/IP...");
    				    } catch (ClassNotFoundException e)
    					    System.out.println("Error : "+e);
    				        } catch (SQLException ex)
    					       System.out.println("Error : "+ex);
    		GridBagConstraints gbc = new GridBagConstraints(); 	//Setting a GridBagConstraints object
    		gbc.gridy = 0; 						//set y position
    		gbc.gridx = 0; 						//set x position
    		frame.getContentPane().add(labname, gbc); 		//Add JLabel "Username" To JFrame
    		gbc.gridx = 1; 						//set x position
    		frame.getContentPane().add(username, gbc); 		//Add JTextField "Username" To JFrame
    		gbc.gridx = 2;						//set x position
    		gbc.gridx = 0; 
    		gbc.gridy = 1; 						//set y position
    		frame.getContentPane().add(emptyLabel1, gbc); 		//Add JLabel "Password" To JFrame
    		gbc.gridx = 0; 						//set x position
    		gbc.gridy = 2;
    		frame.getContentPane().add(labpass, gbc); 		//Add JTextField Box "password" to JFrame
    		gbc.gridx = 1; 						//set y position
    		frame.getContentPane().add(password, gbc); 		//Add empty label for space
    		gbc.gridx = 0; 						//set x position
    		gbc.gridy = 3; 						//set y position
    		frame.getContentPane().add(emptyLabel2, gbc); 		//Add empty label for space
    		gbc.gridy = 4; 						//set y position
    		gbc.gridx = 1; 						//set x position
    		frame.getContentPane().add(submit, gbc); 		//Add a submit JButton to the JFrame
    		gbc.gridy = 5; 						//set y position
    		frame.getContentPane().add(exit, gbc); 			//Add an exit JButton to the JFrame
    		frame.setVisible(true); 				//setting the frame to display
    		new real(timerframe, label, frame).run(); 		//This will create a timerframe, and start it running.
    	public void run() 
    		int x;
    		for(x=60; x>0; --x) 
    		{		 					//Changed the value to 2 minutes (was 60)
    		    label.setText("Min(s) remaining: " +x ); 		//This will set the text of the JLabel.
    			       Thread.sleep(60000); 			//This will sleep for a minute
    			  } catch(InterruptedException ie) 
    				   System.out.println("Error has occured: "+ie);
    			        System.out.println("One minute has passed!");

  2. #2
    Join Date
    Feb 2004
    would you please edit your post so that it is not 3 screens wide.. i find it very difficult to read. (try making the font arial narrow, or setting the size to 1, if you arent prepared to edit your code so that no line is more than 100 characters long
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.