1 Kich thuoc cua 2 TextField bi chenh lech mac du khai bao chung bang nhau Sat Nov 17, 2012 11:44 pm
1101817
Vịt mới lớn
Xem dum minh bai code nay nhe hog hieu tai sao 2 cai textfield no lai hien thi k dc deu ma lai chenh lech nhau ve kich thuoc nhu z...mong cac ban giai quyet dum minh thanks...
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class llform_dangnhap {
private JPanel jp1,jp2;
private JTextField tx1,tx2;
private JLabel username,usericon,password,passicon;
private JFrame frame;
private JButton Login,Cancel;
public llform_dangnhap(){
frame = new JFrame();
frame.setTitle(" Login Form ");
frame.setBounds(900,100,400,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
jp1 = new JPanel();
jp1.setLayout(new GridLayout(1,2));
usericon = new JLabel(new ImageIcon("username.png"));
jp1.add(usericon);
username = new JLabel("Username:");
jp1.add(username);
tx1 = new JTextField(10);
jp1.add(tx1);
frame.add(jp1);
jp2 = new JPanel();
jp2.setLayout(new GridLayout(1,2));
passicon = new JLabel(new ImageIcon("pass.png"));
jp2.add(passicon);
password = new JLabel("Password:");
jp2.add(password);
tx2 = new JTextField(10);
jp2.add(tx2);
frame.add(jp2);
Login = new JButton("Login");
Login.addActionListener(new dangnhap(tx1,tx2));
Cancel = new JButton("Cancel");
Cancel.addActionListener(new thoat());
frame.add(Login);
frame.add(Cancel);
frame.setVisible(true);
}
public static void main(String[] args) {
llform_dangnhap dn = new llform_dangnhap();
}
}
class dangnhap implements ActionListener{
JTextField tx1,tx2;
dangnhap(JTextField tx1,JTextField tx2){
this.tx1 = tx1;
this.tx2 = tx2;
}
@Override
public void actionPerformed(ActionEvent e) {
if(tx1.getText().equals("") || tx2.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Ten dang nhap hoac pass khong dc co khoang trang");
}
else
{
if(tx1.getText().equals(tx2.getText()))
JOptionPane.showMessageDialog(null,"Dang nhap thanh cong");
else
JOptionPane.showMessageDialog(null,"Dang nhap that bai");
}
}
}
class thoat implements ActionListener{
@Override
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
}
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class llform_dangnhap {
private JPanel jp1,jp2;
private JTextField tx1,tx2;
private JLabel username,usericon,password,passicon;
private JFrame frame;
private JButton Login,Cancel;
public llform_dangnhap(){
frame = new JFrame();
frame.setTitle(" Login Form ");
frame.setBounds(900,100,400,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
jp1 = new JPanel();
jp1.setLayout(new GridLayout(1,2));
usericon = new JLabel(new ImageIcon("username.png"));
jp1.add(usericon);
username = new JLabel("Username:");
jp1.add(username);
tx1 = new JTextField(10);
jp1.add(tx1);
frame.add(jp1);
jp2 = new JPanel();
jp2.setLayout(new GridLayout(1,2));
passicon = new JLabel(new ImageIcon("pass.png"));
jp2.add(passicon);
password = new JLabel("Password:");
jp2.add(password);
tx2 = new JTextField(10);
jp2.add(tx2);
frame.add(jp2);
Login = new JButton("Login");
Login.addActionListener(new dangnhap(tx1,tx2));
Cancel = new JButton("Cancel");
Cancel.addActionListener(new thoat());
frame.add(Login);
frame.add(Cancel);
frame.setVisible(true);
}
public static void main(String[] args) {
llform_dangnhap dn = new llform_dangnhap();
}
}
class dangnhap implements ActionListener{
JTextField tx1,tx2;
dangnhap(JTextField tx1,JTextField tx2){
this.tx1 = tx1;
this.tx2 = tx2;
}
@Override
public void actionPerformed(ActionEvent e) {
if(tx1.getText().equals("") || tx2.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Ten dang nhap hoac pass khong dc co khoang trang");
}
else
{
if(tx1.getText().equals(tx2.getText()))
JOptionPane.showMessageDialog(null,"Dang nhap thanh cong");
else
JOptionPane.showMessageDialog(null,"Dang nhap that bai");
}
}
}
class thoat implements ActionListener{
@Override
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
}