The Artima Developer Community
Sponsored Link

Java Answers Forum
login problem

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Terrence

Posts: 2
Nickname: teritori
Registered: Jul, 2004

login problem Posted: Jul 5, 2004 3:12 AM
Reply to this message Reply
Advertisement
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.

PROBLEM STATEMENT
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
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);


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.setUndecorated(true);
timerframe.setSize(185, 19); //Sets the size of the JFrame
timerframe.getContentPane().add(label);
timerframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


frame.setUndecorated(true);

frame.setBackground(Color.white); //Set Framebackground
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().
setFullScreenWindow(frame); //Set Frame Size and position
frame.getContentPane().setLayout(new GridBagLayout()); //set new layout




// submit.addActionListener(this); //*NB Error Line





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");
System.exit(0);
}
});


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";
Class.forName(driverName);
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);


if(!connection.isClosed())
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()
{
timerframe.setVisible(true);
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.
try
{
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!");
}
timerframe.dispose();

}

}

Topic: SWT and OS features Previous Topic   Next Topic Topic: how to get executable file in netbeans ide 3.5?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use