这个程序怎么修改布局啊。
package study;import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//import javax.swing.event.*;
public class CheckLogin extends JFrame implements ActionListener,ItemListener {
JLabel user = new JLabel("用户:");
JLabel pass = new JLabel("密码:");
public String[] username = {"王平", "李四", "张三"};
JComboBox users = new JComboBox(username);
JButton login = new JButton("登录");
JPasswordField password = new JPasswordField(10);
//public char pw[] = {'d','d'};
public CheckLogin(){
JPanel pane = new JPanel();
//Container cont = getContentPane();
pane.add(user);
pane.add(users);
pane.add(pass);
pane.add(password);
pane.add(login);
pane.setLayout(new FlowLayout());
add(pane);
password.addActionListener(this);
users.addItemListener(this);
login.addActionListener(this);
}
public static void main(String args[]){
//Checklogin frame=new BorderLayoutTest();
CheckLogin cl = new CheckLogin();
cl.setTitle("用户登录页面");
cl.setVisible(true);
cl.setSize(500,300);
cl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public String setpwb(){
int flag = 0;
String pwb[] = {"123456", "112233", "123123"};
String pw;
while(true){
if (users.getSelectedItem() == username[flag]){
pw = pwb[flag];
break;
}
flag++;
}
return pw;
}
public void itemStateChanged(ItemEvent ex) {
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String passw = new String(password.getPassword());
if (e.getSource() == login){
if (passw.equals(setpwb())){
String dialogTitle = "提示";
String dialogMessage = "登录成功!";
int dialogType = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog((Component)null, dialogMessage, dialogTitle, dialogType);
return;
}
String dialogTitle = "提示";
String dialogMessage = "登录失败!";
int dialogType = JOptionPane.ERROR_MESSAGE;
JOptionPane.showMessageDialog((Component)null, dialogMessage, dialogTitle, dialogType);
}
}
}
把这个程序该成
用户名 名字
密码 输入密码的文本框
登陆