資源描述:
《java網(wǎng)站登錄界面示例》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、建立網(wǎng)站的注冊界面,運(yùn)行結(jié)果如圖。程序運(yùn)行時(shí),將窗口的各項(xiàng)填充完整,若各項(xiàng)都填充正確,單擊“注冊”按鈕,則彈出一個(gè)“消息”對(duì)話框,提示注冊成功。否則給出相應(yīng)提醒。若單擊“清除”,則剛才所填寫的內(nèi)容將被清空。importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassLoginextendsJAppletimplementsActionListener{JLabellb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8;JComboBoxjcb;JCheckBoxcb;JTextAreata;J
2、Buttonbt1,bt2;JPasswordFieldpf1,pf2;JTextFieldtf1,tf2;JRadioButtonrb[]=newJRadioButton[2];JListlist;JPanelpn1,pn2,pn3;JScrollPanesp1,sp2;ButtonGroupbtg;publicLogin(){lb1=newJLabel("用戶名:");lb2=newJLabel("密碼:");lb3=newJLabel("確認(rèn)密碼:");lb4=newJLabel("血型:");lb5=newJLabel("性別:");lb6=newJLabel("郵箱:")
3、;lb7=newJLabel("個(gè)人簡歷:");lb8=newJLabel("了解本網(wǎng)站的途徑:");jcb=newJComboBox();jcb.addItem("A型");jcb.addItem("B型");jcb.addItem("AB型");jcb.addItem("O型");jcb.setSelectedIndex(0);cb=newJCheckBox("我愿意公開個(gè)人信息",true);ta=newJTextArea(5,15);bt1=newJButton("注冊");bt2=newJButton("清除");bt1.addActionListener(this);b
4、t2.addActionListener(this);pf1=newJPasswordField(15);pf2=newJPasswordField(15);tf1=newJTextField(15);tf2=newJTextField(15);sp1=newJScrollPane();sp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);sp1.getViewport().add(ta);rb[0]=newJRadioButton("男");rb[1]=newJRadioButton("女");
5、rb[0].setSelected(true);btg=newButtonGroup();btg.add(rb[0]);btg.add(rb[1]);Stringdata[]={"因特網(wǎng)","報(bào)紙雜志","朋友同事","其他方式"};list=newJList(data);list.setSelectedIndex(0);sp2=newJScrollPane();sp2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);sp2.getViewport().add(list);pn1=newJPanel
6、();pn1.add(lb5);pn1.add(rb[0]);pn1.add(rb[1]);GridBagLayoutgb=newGridBagLayout();Containercon=getContentPane();con.setLayout(gb);GridBagConstraintsc=newGridBagConstraints();c.fill=GridBagConstraints.HORIZONTAL;c.anchor=GridBagConstraints.EAST;c.weightx=1.0;c.weighty=1.0;c.gridwidth=1;c.gridhei
7、ght=1;gb.setConstraints(lb1,c);con.add(lb1);gb.setConstraints(tf1,c);con.add(tf1);c.gridwidth=1;gb.setConstraints(lb2,c);con.add(lb2);c.gridwidth=GridBagConstraints.REMAINDER;gb.setConstraints(pf1,c);con.add(pf1);c.gridwidth=1;gb.setCon