The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Originally posted by Torsten Schippel:
Hi Torsten,
Bellow are some codes that I did for a Login Page but the Login button and the Exit button ain't working.what am I suppose to do?And how do I call a data from a database?
// Java core packages
import java.awt.*;
import java.awt.event.*;
// Java extension packages
import javax.swing.*;
public class TestingLogin extends JFrame
{
private JTextField nameField;
private JPasswordField passwordField;
private JButton loginButton, exitButton;
private JLabel label1;
public TestingLogin()
{
super( "TestingLoginPage" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
Icon nyp = new ImageIcon( "nyp.gif" );
label1 = new JLabel("Student Feedback System", nyp,SwingConstants.LEFT );
// construct textfield with default sizing
nameField = new JTextField( 10 );
container.add( nameField );
// construct textfield with default text
passwordField = new JPasswordField( 10 );
container.add( passwordField );
// register event handlers
TextFieldHandler handler = new TextFieldHandler();
nameField.addActionListener( handler );
passwordField.addActionListener( handler );
// create login button
loginButton = new JButton( "Login" );
container.add( loginButton );
// create exit button
exitButton = new JButton( "Exit" );
container.add( exitButton );
// create an instance of inner class ButtonHandler
loginButton.addActionListener( handler );
exitButton.addActionListener( handler );
setSize( 350, 100 );
setVisible( true );
}
// execute application
public static void main( String args[] )
{
TestingLogin application = new TestingLogin();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
// private inner class for event handling
private class TextFieldHandler implements ActionListener
{
// process text field events
public void actionPerformed( ActionEvent event )
{
String string = "";
// user pressed Enter in JTextField nameField
if ( event.getSource() == nameField )
string = "nameField: " + event.getActionCommand();
// user pressed Enter in JTextField passwordField
else if ( event.getSource() == passwordField )
{
JPasswordField pwd =
( JPasswordField ) event.getSource();
string = "passwordField: " + new String( passwordField.getPassword() );
}
}
}
// inner class for button event handling
private class ButtonHandler implements ActionListener
{
// handle button event
public void actionPerformed( ActionEvent event )
{
JOptionPane.showMessageDialog( null,"You pressed: " + event.getActionCommand() );
}
}
}
Regards
Aqualyn
Originally posted by Torsten Schippel:
Hi Tim,
why do you think it is an applet. I think it's just a Java application (client/server).
Regards
Torsten
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |