Monday, October 11, 2010

GUI classes really started! (excited :D)

Today I had the first class in GUI programming. I had this course begun before, but today was the real go. Previous classes were only theoretical and, for sure, boring! but GUIs' is just exciting. I'm so excited ^^

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 :)

4 comments:

  1. it's an example to show how login forms work.

    ReplyDelete
  2. okkk... i tried to compile the software ,, but it doesn't work ,, there are some errors ,, 2 errors i think ,, try to find them .. thanks


    this 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

    ReplyDelete
  3. save it as Login.java

    it works fine..

    ReplyDelete