求指点。本人代码错误的地方。
import java.awt.BorderLayout;import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Logindemo1 extends JFrame implements ActionListener,ItemListener{
String Sex="",Year="",Month="";
String strKey;
boolean flag=true;
JLabel lYourInform,lLogin, lKey;
JTextField textLogin;
JPasswordField textKey;
Checkbox box1,box2;
CheckboxGroup boxgroup;
JLabel lSex;
JTextField textName;
JLabel lBirthday;
Choice y,m;
TextArea areaInform;
JButton bEnter;
public Logindemo1(){
super("个人信息");
lYourInform = new JLabel("个人信息登录");
add(lYourInform,BorderLayout.NORTH);
//设置中心面板,从中心面板开始
Panel centerPanel = new Panel();
Panel panel1 = new Panel(); //panel1
lLogin = new JLabel("账号:");
lLogin.setForeground(Color.black);
textLogin = new JTextField("",2);
panel1.add(textLogin);
panel1.add(lLogin);
centerPanel.add(panel1);
Panel panel2 = new Panel(); //panel2
lKey = new JLabel("密码:");
lKey.setForeground(Color.black);
textKey = new JPasswordField("",2);
panel2.add(lKey);
textKey.setEchoChar('*');
panel2.add(textKey);
centerPanel.add(panel2);
JPanel panel3 = new JPanel(); //panel3
lSex = new JLabel("性别:");
lSex.setForeground(Color.red);
textName = new JTextField("",3);
boxgroup = new CheckboxGroup();
box1 = new Checkbox("男",boxgroup,true);
box2 = new Checkbox("女",boxgroup,false);
panel3.add(lSex);
panel3.add(box1);
panel3.add(box2);
centerPanel.add(panel3);
JPanel panel4 = new JPanel(); //panel4
lBirthday = new JLabel("出生日期:");
lBirthday.setForeground(Color.blue);
y = new Choice();
y.add("1990");
y.add("1991");
y.add("1992");
y.add("1993");
y.add("1994");
y.add("1995");
y.add("1996");
y.add("1997");
y.setForeground(Color.black);
m = new Choice();
m.add("1");
m.add("2");
m.add("3");
m.add("4");
m.add("5");
m.add("6");
m.add("7");
m.add("8");
m.add("9");
m.add("10");
m.add("11");
m.add("12");
m.setForeground(Color.blue);
// dchoice = new Choice();
//dchoice.add("11");
// dchoice.add("12");
//dchoice.setForeground(Color.blue);
y.addItemListener(this);
m.addItemListener(this);
//dchoice.addItemListener(this);
panel4.add(lBirthday);
panel4.add(y);
panel4.add(m);
// add(dchoice);
centerPanel.add(panel4);
areaInform = new TextArea("",6,25); //文本域
centerPanel.add(areaInform);
add(areaInform); //中心面板结束
JPanel bPanel = new JPanel(); //按钮面板
bEnter = new JButton("确定");
bEnter.addActionListener(this);
bPanel.add(bEnter);
add(bPanel,BorderLayout.SOUTH); //按钮面板结束
setSize(200,300);
setLocation(400,200);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing( WindowEvent e ){
System.exit( 0 );
}
} );
}
public void actionPerformed(ActionEvent a){
areaInform.setText("");
if(a.getSource()==bEnter){
if(flag==true){
flag = false;
areaInform.append("用户名:"+textLogin.getText()+"\n");
areaInform.append("密码:"+textKey.getText()+"\n");
areaInform.append("性别:"+Sex+"\n");
areaInform.append("出生日期:"+Year + Month +"\n");
strKey = textKey.getText();
textKey.setText("");
}
}
}
public void itemStateChanged(ItemEvent i){
if(i.getItemSelectable()==y){
Year=y.getSelectedItem();
}
if(i.getItemSelectable()==m){
Month=m.getSelectedItem();
}
// if(i.getItemSelectable()==dchoice){
// Day=dchoice.getSelectedItem();
// }
if(box1.getState()){
Sex = box1.getLabel();
}
if(box2.getState()){
Sex = box2.getLabel();
}
}
public static void main(String[] arg){
new Logindemo1 ();
}
}
本人新手一枚,BorderLayout布局管理不会。panel1,panel2,panel3,panel4都显示不出啊。