这是全部内容,谢谢了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.*;
public class Login
{
public static void main(String args[])
{
LoginFrame frame=new LoginFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//
frame.setResizable(false);
frame.setVisible(true);
}
}
class LoginFrame extends JFrame
{
public LoginFrame()
{
setTitle("注册");
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screen=kit.getScreenSize();
//
setBounds(screen.width/4,screen.height/4,screen.width/2,screen.height/2);
setSize(screen.width,screen.height);
Image img=kit.getImage("1.jpg");
setIconImage(img);
GridBagLayout layout=new GridBagLayout();
JPanel panel=new JPanel();
add(panel);
Icon icon = new ImageIcon ("2.jpg");
panel.setBorder(new MatteBorder(200, 400, 200, 400, icon));
panel.setLayout(layout);
//添加用户名
JLabel idlb=new JLabel("用户名");
JTextField idtxt=new JTextField("fff");
txtListener txtlistener=new txtListener();
idtxt.getDocument().addDocumentListener(txtlistener);
idlab=new JLabel();
//
idtxt.Maxlength=10;
//添加用户密码
JLabel pw1lb=new JLabel("用户密码");
JPasswordField pw1txt=new JPasswordField();
JLabel pw1lab=new JLabel();
pw1txt.setEchoChar('★');
//
pw1txt.setPreferredSize(new Dimension(200, 21));
//添加确认密码
JLabel pw2lb=new JLabel("确认密码");
JPasswordField pw2txt=new JPasswordField();
JLabel pw2lab=new JLabel();
pw2txt.setEchoChar('★');
//
pw2txt.setMaximumSize(pw2txt.getPreferredSize());
//添加姓名
JLabel nmlb=new JLabel("姓名");
JTextField nmtxt=new JTextField();
JLabel nmlab=new JLabel();
//添加性别
JLabel sexlb=new JLabel("性别");
JPanel sexPanel=new JPanel();
ButtonGroup sex=new ButtonGroup();
JRadioButton manbt=new JRadioButton("男");
manbt.setSelected(true);
JRadioButton wmanbt=new JRadioButton("女");
sexPanel.add(manbt);
sexPanel.add(wmanbt);
sexPanel.setBorder(BorderFactory.createEtchedBorder());
sex.add(manbt);sex.add(wmanbt);
JLabel sexlab=new JLabel();
//添加年龄
JLabel agelb=new JLabel("年龄");
int MINY=1900;
int MINM=1;
int MIND=1;
int MAXY=2008;
int MAXM=12;
int MAXD=31;
JPanel agePanel=new JPanel();
JLabel ageY=new JLabel("年");
JLabel ageM=new JLabel("月");
JLabel ageD=new JLabel("日");
String ageYE[]=new String[MAXY-MINY+1];
String ageMO[]=new String[MAXM];
yearListener ylistener=new yearListener();
for(int j=0;MAXY>=MINY;j++)
ageYE[j]=String.valueOf(MAXY--);
for(int j=0;MINM<=MAXM;j++)
ageMO[j]=String.valueOf(MINM++);
ageYCombo=new JComboBox(ageYE);
ageYCombo.setSelectedItem("1987");
ageMCombo=new JComboBox(ageMO);
ageMCombo.setSelectedItem("9");
ageYCombo.addActionListener(ylistener);
ageMCombo.addActionListener(ylistener);
String ageDA[]=new String[MAXD];
for(int j=0;MIND<=MAXD;j++)
ageDA[j]=String.valueOf(MIND++);
ageDCombo=new JComboBox(ageDA);
ageDCombo.setSelectedItem("3");
JLabel agelab=new JLabel();
agePanel.add(ageYCombo);agePanel.add(ageY);
agePanel.add(ageMCombo);agePanel.add(ageM);
agePanel.add(ageDCombo);agePanel.add(ageD);
//添加班级
JLabel cllb=new JLabel("班级");
JComboBox clCombo=new JComboBox(new String []{"06大专网络","06物流1班","06大专财会","06大专软件"});
JLabel cllab=new JLabel();
//添加身份证
JLabel Pidlb=new JLabel("身份证");
JTextField Pidtxt=new JTextField("36048119870");
JLabel Pidlab=new JLabel();
//添加家庭住址
JLabel adrlb=new JLabel("家庭住址");
JTextField adrtxt=new JTextField("江西省瑞昌市白杨镇黄桥十五组");
JLabel adrlab=new JLabel();
//添加命令按钮
JButton okbt= new JButton("提交");
JButton cancelbt=new JButton("取消");
//添加评分
JLabel grlb=new JLabel("<html><font color=green>请给该窗体打分</font></html>");
JSlider grsid=new JSlider(0,100,90);
JLabel grlab=new JLabel();
grsid.setMajorTickSpacing(20);
grsid.setMinorTickSpacing(5);
grsid.setPaintTicks(true);
grsid.setSnapToTicks(true);
grsid.setPaintLabels(true);
// 添加到窗体
panel.add(idlb,new GBC(0,0,1,1).setAnchor(GBC.WEST).setInsets(1));
panel.add(idtxt,new GBC(1,0,1,1).setFill(GBC.HORIZONTAL).setInsets(4));
panel.add(idlab,new GBC(2,0,1,1).setAnchor(GBC.EAST).setInsets(1));
panel.add(pw1lb,new GBC(0,1,1,1).setAnchor(GBC.WEST));
panel.add(pw1txt,new GBC(1,1,1,1).setFill(GBC.HORIZONTAL).setInsets(4));
panel.add(pw1lab,new GBC(2,1,1,1).setAnchor(GBC.EAST).setInsets(1));
panel.add(pw2lb,new GBC(0,2,1,1).setAnchor(GBC.WEST));
panel.add(pw2txt,new GBC(1,2,1,1).setFill(GBC.BOTH).setInsets(4));
panel.add(pw2lab,new GBC(2,2,1,1).setFill(GBC.BOTH).setAnchor(GBC.EAST).setInsets(1));
panel.add(nmlb,new GBC(0,3,1,1).setAnchor(GBC.WEST));
panel.add(nmtxt,new GBC(1,3,1,1).setFill(GBC.BOTH).setInsets(4));
panel.add(nmlab,new GBC(2,3,1,1).setFill(GBC.BOTH).setAnchor(GBC.EAST).setInsets(1));
panel.add(sexlb,new GBC(0,4,1,1).setAnchor(GBC.WEST));
panel.add(sexPanel,new GBC(1,4,1,1).setFill(GBC.BOTH).setAnchor(GBC.CENTER));
panel.add(sexlab,new GBC(2,4,1,1).setFill(GBC.BOTH).setAnchor(GBC.EAST).setInsets(1));
panel.add(agelb,new GBC(0,5,1,1).setAnchor(GBC.WEST));
panel.add(agePanel,new GBC(1,5,1,1).setFill(GBC.BOTH).setInsets(4));
panel.add(agelab,new GBC(2,5,1,1).setFill(GBC.BOTH).setAnchor(GBC.EAST).setInsets(1));
panel.add(cllb,new GBC(0,6,1,1).setAnchor(GBC.WEST));
panel.add(clCombo,new GBC(1,6,1,1).setFill(GBC.BOTH).setInsets(4));
panel.add(cllab,new GBC(2,6,1,1).setFill(GBC.BOTH).setAnchor(GBC.EAST).setInsets(1));
panel.add(Pidlb,new GBC(0,7,1,1).setAnchor(GBC.WEST));
panel.add(Pidtxt,new GBC(1,7,1,1).setFill(GBC.BOTH).setInsets(4));
panel.add(Pidlab,new GBC(2,7,1,1).setAnchor(GBC.EAST).setInsets(1));
panel.add(adrlb,new GBC(0,8,1,1).setAnchor(GBC.WEST));
panel.add(adrtxt,new GBC(1,8,1,1).setFill(GBC.BOTH).setInsets(4));
panel.add(adrlab,new GBC(2,8,1,1).setFill(GBC.BOTH).setAnchor(GBC.EAST).setInsets(1));
panel.add(grlb,new GBC(0,9,1,1).setAnchor(GBC.WEST));
panel.add(grsid,new GBC(1,9,1,1).setFill(GBC.BOTH).setInsets(4));
panel.add(grlab,new GBC(2,9,1,1).setAnchor(GBC.EAST).setInsets(1));
panel.add(okbt,new GBC(0,10,1,1).setAnchor(GBC.SOUTH).setInsets(4));
panel.add(cancelbt,new GBC(1,10,2,1).setAnchor(GBC.SOUTH).setInsets(4));
}
private class yearListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
stry=Integer.parseInt((String)ageYCombo.getSelectedItem());
strm=Integer.parseInt((String)ageMCombo.getSelectedItem());
if(tag1)
{
ageDCombo.addItem("31");
tag1=false;
}
if(tag2)
{
ageDCombo.addItem("30");
ageDCombo.addItem("31");
tag2=false;
}
if(tag3)
{
ageDCombo.addItem("29");
ageDCombo.addItem("30");
ageDCombo.addItem("31");
tag3=false;
}
if(strm==4||strm==6||strm==9||strm==11)
{
ageDCombo.removeItem("31");
tag1=true;
}
if(((stry%4==0&&stry%100!=0)||stry%400==0)&&strm==2)
{
ageDCombo.removeItem("31");
ageDCombo.removeItem("30");
tag2=true;
}
if(!((stry%4==0&&stry%100!=0)||stry%400==0)&&strm==2)
{
ageDCombo.removeItem("31");
ageDCombo.removeItem("30");
ageDCombo.removeItem("29");
tag3=true;
}
}
boolean tag1=false;
boolean tag2=false;
boolean tag3=false;
int stry=1990;
int strm=1;
}
private class txtListener implements DocumentListener
{
public void insertUpdate(DocumentEvent e)
{
str=idtxt.getText();
int i=str.length();
if(i<8)
idlab.setText("<html><font color=red>!字符过短!</color></html>");
if(i>16)
idlab.setText("<html><font color=red>!字符过短!</color></html>");
}
public void removeUpdate(DocumentEvent e)
{
/* str=idtxt.getText();
int i=str.length();
if(i<8)
idlab.setText("<html><font color=red>!字符过短!</color></html>");
if(i>16)
*/ idlab.setText("<html><font color=red>!字符过短!</color></html>");
}
public void changedUpdate(DocumentEvent e)
{
}
String str;
}
private JComboBox ageYCombo;
private JComboBox ageMCombo;
private JTextField idtxt;
private JLabel idlab;
private JLabel pw1lab;
private JLabel pw2lab;
private JLabel Pidlab;
private JLabel grlab;
private JComboBox ageDCombo;
}
[[it] 本帖最后由 y218z903 于 2008-5-28 17:04 编辑 [/it]]