This was the first program we had:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login extends JFrame {
private JLabel uid,pwd;
private JTextField tuid;
private JPasswordField tpwd;
private JButton bok;
public Login() {
super ("Windows Login");
Container container = getContentPane();
container.setLayout(new FlowLayout() );
uid = new JLabel ("User ID");
container.add(uid);
tuid = new JTextField(10);
container.add(tuid);
pwd = new JLabel ("Password");
container.add(pwd);
tpwd = new JPasswordField(10);
container.add(tpwd);
bok = new JButton ("Login");
container.add(bok);
ButtonHandler handler=new ButtonHandler();
bok.addActionListener(handler);
setSize(400,100);
setVisible(true);
}
public static void main (String args [] ) {
Login application=new Login();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class ButtonHandler implements ActionListener{
public void actionPerformed (ActionEvent event){
String msg;
if ( (tuid.getText().equals("admin") ) && (tpwd.getText().equals("hct") ) )
{
msg="Login Successful";
}
else
{
msg="Login Failed";
}
JOptionPane.showMessageDialog(null,msg);
}
}
It's not too long as some students looked at it, it's just the way it is! <-- anyone get the point?? no problem.
I'm looking forward for further classes, I think they're gonna be more and more exciting, can't wait XD.
Mr. Anand is a good teacher. I like the way he teaches. Hope I could him teaching me next semester@@
Anyway, see you later :)
what's this program for??
ReplyDeleteit's an example to show how login forms work.
ReplyDeleteokkk... i tried to compile the software ,, but it doesn't work ,, there are some errors ,, 2 errors i think ,, try to find them .. thanks
ReplyDeletethis is the error i got
ahmed@ahmed-laptop:~/Desktop/javacompiler/softwares$ javac liberty\ GUI.java
liberty GUI.java:5: class Login is public, should be declared in a file named Login.java
public class Login extends JFrame {
^
Note: liberty GUI.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
save it as Login.java
ReplyDeleteit works fine..