JAVA
this is the example code which is my class HomeWork.
package gui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.Border;
public class Log extends JFrame{
public static void main(String args[]){
JLabel user=new JLabel();
user.setText("UserName:");
user.setBounds(10, 10, 80, 25);
final JTextField txtuser =new JTextField();
txtuser.setBounds(85, 10, 200, 25);
// Label
JLabel pwd=new JLabel();
pwd.setText("PassWord:");
pwd.setBounds(10, 45, 80, 25);
final JPasswordField txtpwd =new JPasswordField();
txtpwd.setBounds(85, 45, 200, 25);
//Button
JButton button=new JButton();
button.setText("Cancel");
button.setBounds(85,105,85,25);
JButton button1=new JButton();
button1.setText("Login");
button1.setBounds(175,105,85,25);
// checkbox
final JCheckBox chkrem= new JCheckBox();
chkrem.setText("Remember This PassWord ?");
chkrem.setBounds(85, 75, 300, 25);
JCheckBox checked= chkrem;
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//JOptionPane.showMessageDialog(null, "Login button is Clicked!");
if(txtuser.getText().toString().equals("")){
JOptionPane.showMessageDialog(null, "Please input UserName !");
txtuser.requestFocus();
}else if(txtpwd.getText().toString().equals("")){
JOptionPane.showMessageDialog(null, "Please input Password");
txtpwd.requestFocus();
}else if( txtuser.getText().toString().equals("admin") && txtpwd.getText().toString().equals("admin")){
JOptionPane.showMessageDialog(null, "! Now you are Login !");
}//else if(chkrem.isselect(true)){
//}
else{
JOptionPane.showMessageDialog(null, "Invalid password Or Username");
}
}
});
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
txtuser.setText("");
txtpwd.setText("");
txtuser.requestFocus();
}
});
Log frm=new Log();
frm.setTitle("Form Login");
frm.setBounds(20, 20, 350, 200);
frm.setVisible(true);
frm.setLayout(null);
frm.add(button1);
frm.add(button);
frm.add(pwd);
frm.add(txtpwd);
frm.add(user);
frm.add(txtuser);
frm.add(chkrem);
}
}
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.Border;
public class Log extends JFrame{
public static void main(String args[]){
JLabel user=new JLabel();
user.setText("UserName:");
user.setBounds(10, 10, 80, 25);
final JTextField txtuser =new JTextField();
txtuser.setBounds(85, 10, 200, 25);
// Label
JLabel pwd=new JLabel();
pwd.setText("PassWord:");
pwd.setBounds(10, 45, 80, 25);
final JPasswordField txtpwd =new JPasswordField();
txtpwd.setBounds(85, 45, 200, 25);
//Button
JButton button=new JButton();
button.setText("Cancel");
button.setBounds(85,105,85,25);
JButton button1=new JButton();
button1.setText("Login");
button1.setBounds(175,105,85,25);
// checkbox
final JCheckBox chkrem= new JCheckBox();
chkrem.setText("Remember This PassWord ?");
chkrem.setBounds(85, 75, 300, 25);
JCheckBox checked= chkrem;
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//JOptionPane.showMessageDialog(null, "Login button is Clicked!");
if(txtuser.getText().toString().equals("")){
JOptionPane.showMessageDialog(null, "Please input UserName !");
txtuser.requestFocus();
}else if(txtpwd.getText().toString().equals("")){
JOptionPane.showMessageDialog(null, "Please input Password");
txtpwd.requestFocus();
}else if( txtuser.getText().toString().equals("admin") && txtpwd.getText().toString().equals("admin")){
JOptionPane.showMessageDialog(null, "! Now you are Login !");
}//else if(chkrem.isselect(true)){
//}
else{
JOptionPane.showMessageDialog(null, "Invalid password Or Username");
}
}
});
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
txtuser.setText("");
txtpwd.setText("");
txtuser.requestFocus();
}
});
Log frm=new Log();
frm.setTitle("Form Login");
frm.setBounds(20, 20, 350, 200);
frm.setVisible(true);
frm.setLayout(null);
frm.add(button1);
frm.add(button);
frm.add(pwd);
frm.add(txtpwd);
frm.add(user);
frm.add(txtuser);
frm.add(chkrem);
}
}
No comments:
Post a Comment