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