JAVA程序设计团购网站的注册.docx
- 文档编号:30177978
- 上传时间:2023-08-05
- 格式:DOCX
- 页数:18
- 大小:159.83KB
JAVA程序设计团购网站的注册.docx
《JAVA程序设计团购网站的注册.docx》由会员分享,可在线阅读,更多相关《JAVA程序设计团购网站的注册.docx(18页珍藏版)》请在冰豆网上搜索。
JAVA程序设计团购网站的注册
xxxx大学计算机与信息学院
综合性设计性实验报告
班级:
学号:
姓名:
实验项目名称:
实验项目性质:
实验所属课程:
实验室(中心):
指导教师:
实验完成时间:
年月日
一、实验目的
熟悉Java语言中的GUI的运用,更深入的了解Java的框架,增强动手能力。
二、实验内容及要求
独立完成一个Java课程设计,题目自拟,熟悉Java的语言风格以及进一步认识类的概念。
三、实验设备及软件
计算机、JCreatorV4
四、设计方案
㈠题目:
团购网站的注册
㈡设计的主要思路
主要包括两个frame,父窗体里是团购的宣传图片和两个button,通过点击button新建子窗体,并关闭父窗体,通过子窗体内的button,text,label等组件,使用户完成注册。
五、主要代码
1.引用包
importjava.awt.*;
importjavax.swing.*;
importjava.awt.event.*;
2.新建zhuce类,main方法
publicclasszhuce
{publicstaticvoidmain(String[]args)
{
TestFrameframe=newTestFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
3.父窗体TestFrame
classTestFrameextendsJFrame
{
publicTestFrame()
{
setSize(400,500);
setTitle("拉手网——中国最大的团购网");
ImagePanelpanel=newImagePanel();
ContainercontentPane=getContentPane();
contentPane.add(panel);
JPanelbuttonPanel=newJPanel();
addButton(buttonPanel,"注册",newActionListener()//利用addButton方法,添加一个按钮
{
publicvoidactionPerformed(ActionEventevt)
{
dispose();//关闭当前窗口
ZuFramejf=newZuFrame();//新建一个Frame
jf.setSize(500,440);
jf.setTitle("注册拉手网");
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
});
addButton(buttonPanel,"退出",newActionListener()//利用addButton方法,添加一个按钮
{
publicvoidactionPerformed(ActionEventevt)
{
System.exit(0);
}
});
contentPane.add(buttonPanel,BorderLayout.SOUTH);
LabelPanelpanel1=newLabelPanel();
contentPane.add(panel1,BorderLayout.NORTH);
}
publicvoidaddButton(Containerc,Stringtitle,ActionListenerlistener)//addButton方法
{
JButtonbutton=newJButton(title);
c.add(button);
button.addActionListener(listener);
}
}
4.往父框体里插入图片-团购.jpg,往父框体里加入一个label
classImagePanelextendsJPanel//imagepanel
{
publicImagePanel()
{
//得到image图像文件
image=Toolkit.getDefaultToolkit().getImage("团购.jpg");
MediaTrackertracker=newMediaTracker(this);
tracker.addImage(image,1);
try
{
tracker.waitForID
(1);
}
catch(InterruptedExceptionexception)
{
}
}
publicvoidpaintComponent(Graphicsg)
{
super.paintComponent(g);
//得到image的尺寸
intimageWidth=image.getWidth(this);
intimageHeight=image.getHeight(this);
//得到窗口的尺寸
intFrameWidth=getWidth();
intFrameHeight=getHeight();
//算出image的坐标,是他显示在窗口的正中间
intx=(FrameWidth-imageWidth)/2;
inty=(FrameHeight-imageHeight)/2;
//显示image
g.drawImage(image,x,y,null);
}
privateImageimage;
}
classLabelPanelextendsJPanel//labelpanel
{
publicLabelPanel()
{
JLabellable1=newJLabel("加入拉手网,成为团购达人!
");
lable1.setFont(newFont("楷体",Font.PLAIN,20));
lable1.setForeground(Color.RED);
add(lable1);
}
}
5子框体ZuFrame,新建布局
classZuFrameextendsJFrame
{
publicZuFrame()
{
MainPanelmainpanel=newMainPanel();//主面板
ButtonPanelbuttonpanel=newButtonPanel();
ContainercontentPane=getContentPane();
setLayout(newGridBagLayout());//新建布局
GridBagConstraintsc=newGridBagConstraints();
c.gridx=0;
c.gridy=GridBagConstraints.RELATIVE;
c.gridwidth=1;
c.gridheight=1;
c.fill=GridBagConstraints.BOTH;
c.weightx=1;
c.weighty=400;
add(mainpanel,c);
c.gridx=0;
c.gridy=GridBagConstraints.RELATIVE;
c.gridwidth=1;
c.gridheight=1;
c.fill=GridBagConstraints.BOTH;
c.weightx=1;
c.weighty=100;
add(buttonpanel,c);
}
}
6.把子框体分为两个部分,MainPanel和ButtonPanel,MainPanel包括email.密码.确认密码.手机号码在内的9个panel,依次排列下来
classMainPanelextendsJPanel//mainPanel
{
publicMainPanel()
{
setSize(WIDTH,HEIGHT);
setBackground(Color.WHITE);
//从Email按序排列panel
MainPanelOneone=newMainPanelOne();//Email
MainPanelTwotwo=newMainPanelTwo();//对email的解释
MainPanelThreethree=newMainPanelThree();//账号
MainPanelFourfour=newMainPanelFour();//对账号的解释
MainPanelFivefive=newMainPanelFive();//密码
MainPanelSixsix=newMainPanelSix();//对密码的解释
MainPanelSevenseven=newMainPanelSeven();//确认密码
MainPanelEighteight=newMainPanelEight();//手机号
MainPanelNinenine=newMainPanelNine();//所在城市
add(one);
add(two);
add(three);
add(four);
add(five);
add(six);
add(seven);
add(eight);
add(nine);
}
publicstaticfinalintWIDTH=500;
publicstaticfinalintHEIGHT=400;
}
classButtonPanelextendsJPanelimplementsActionListener//buttonPanel
{
publicButtonPanel()
{
setSize(WIDTH,HEIGHT);
setLayout(null);
btnregister=newJButton("注册");//注册按钮
Fontfontset=newFont("宋体",Font.PLAIN,12);
btnregister.setFont(fontset);
btnregister.setSize(80,30);
btnregister.setLocation(30,20);
btnocancel=newJButton("取消");//取消按钮
Fontfontlogin=newFont("宋体",Font.PLAIN,12);
btnocancel.setFont(fontlogin);
btnocancel.setSize(80,30);
btnocancel.setLocation(380,20);
add(btnregister);
add(btnocancel);
btnregister.addActionListener(this);
btnocancel.addActionListener(this);
}
//实现抽象函数actionPerformed
publicvoidactionPerformed(ActionEventevent)
{
Objectsource=event.getSource();
StringstrEmail=MainPanelOne.textEmail.getText();//得到email地址
StringstrId=MainPanelThree.textUsername.getText();//得到账号
char[]passWord=MainPanelFive.textPassword.getPassword();//得到密码
char[]spassWord=MainPanelSeven.surePassword.getPassword();//得到确认密码
Stringtellnumber=MainPanelEight.textTellphone.getText();//得到手机号
if(source==btnregister)
{
if((strEmail.equals("")||strId.equals("")||passWord.equals('')||spassWord.equals('')||tellnumber.equals("")))//如果任意一栏没填
{
JOptionPane.showMessageDialog(null,"请填完整您的注册信息");
return;
}
JOptionPane.showMessageDialog(null,"感谢您的注册,注册成功!
");//
}
elseif(source==btnocancel)
{
System.exit(0);
}
}
//绘制按钮面板背景图片
publicvoidpaintComponent(Graphicsg)
{
super.paintComponent(g);
ImageIconimg=newImageIcon("4.jpg");
g.drawImage(img.getImage(),0,0,null);
}
publicstaticfinalintWIDTH=500;
publicstaticfinalintHEIGHT=80;
publicJButtonbtnregister;
publicJButtonbtnocancel;
}
classMainPanelOneextendsJPanel//注册
{
publicstaticJTextFieldtextEmail=newJTextField(30);
publicMainPanelOne()
{
setBackground(Color.WHITE);
textEmail.setBackground(Color.yellow);
JLabellableEmail=newJLabel("Email:
");
lableEmail.setFont(newFont("宋体",Font.PLAIN,20));
lableEmail.setForeground(Color.BLUE);
add(lableEmail);
add(textEmail);
}
}
classMainPanelTwoextendsJPanel//对于注册的解释
{
publicMainPanelTwo()
{
setBackground(Color.WHITE);
JLabellableSuggest=newJLabel("用于登录及找回密码,不会公开,请放心填写");
lableSuggest.setFont(newFont("宋体",Font.PLAIN,14));
lableSuggest.setForeground(Color.RED);
add(lableSuggest);
}
}
classMainPanelThreeextendsJPanel//账号
{
publicstaticJTextFieldtextUsername=newJTextField(30);
publicMainPanelThree()
{
setBackground(Color.WHITE);
textUsername.setBackground(Color.yellow);
JLabellableUsername=newJLabel("账号:
");
lableUsername.setFont(newFont("宋体",Font.PLAIN,20));
lableUsername.setForeground(Color.BLUE);
add(lableUsername);
add(textUsername);
}
}
classMainPanelFourextendsJPanel//对于账号的解释
{
publicMainPanelFour()
{
setBackground(Color.WHITE);
JLabellableSuggest=newJLabel("填写4-6个字符,一个汉字为两个字符");
lableSuggest.setFont(newFont("宋体",Font.PLAIN,14));
lableSuggest.setForeground(Color.RED);
add(lableSuggest);
}
}
classMainPanelFiveextendsJPanel//密码
{
publicstaticJPasswordFieldtextPassword=newJPasswordField(30);
publicMainPanelFive()
{
textPassword.setEchoChar('*');
textPassword.setBackground(Color.yellow);
setBackground(Color.WHITE);
JLabellablePassword=newJLabel("密码:
");
lablePassword.setFont(newFont("宋体",Font.PLAIN,20));
lablePassword.setForeground(Color.BLUE);
add(lablePassword);
add(textPassword);
}
}
classMainPanelSixextendsJPanel//对于密码的解释
{
publicMainPanelSix()
{
setBackground(Color.WHITE);
JLabellableSuggest=newJLabel("为了您的账号安全,建议密码至少6个字符以上");
lableSuggest.setFont(newFont("宋体",Font.PLAIN,14));
lableSuggest.setForeground(Color.RED);
add(lableSuggest);
}
}
classMainPanelSevenextendsJPanel//确认密码
{
publicstaticJPasswordFieldsurePassword=newJPasswordField(30);
publicMainPanelSeven()
{
surePassword.setEchoChar('*');
surePassword.setBackground(Color.yellow);
setBackground(Color.WHITE);
JLabellableSurePassword=newJLabel("确认密码:
");
lableSurePassword.setFont(newFont("宋体",Font.PLAIN,20));
lableSurePassword.setForeground(Color.BLUE);
add(lableSurePassword);
add(surePassword);
}
}
classMainPanelEightextendsJPanel//手机号
{
publicstaticJTextFieldtextTellphone=newJTextField(10);
publicMainPanelEight()
{
setBackground(Color.WHITE);
textTellphone.setBackground(Color.yellow);
JLabellableTellphone=newJLabel("手机号码:
");
lableTellphone.setFont(newFont("宋体",Font.PLAIN,20));
lableTellphone.setForeground(Color.BLUE);
JLabellabel=newJLabel("手机号码是我们联系您的最好方式");
add(lableTellphone);
add(textTellphone);
add(label);
}
}
classMainPanelNineextendsJPanel//所在城市
{
publicstaticJComboBoxcomboBox=newJComboBox();
publicMainPanelNine()
{
setBackground(Color.WHITE);
JLabellableCity=newJLabel("所在城市:
");
lableCity.setFont(newFont("宋体",Font.PLAIN,20));
lableCity.setForeground(Color.BLUE);
comboBox.setFont(newFont("宋体",Font.PLAIN,20));
comboBox.setForeground(Color.BLUE);
comboBox.setEditable(false);
comboBox.addItem("北京");
comboBox.addItem("上海");
comboBox.addItem("重庆");
comboBox.addItem("成都");
JLabellabel=newJLabel(""+"");
add(lableCity);"+"add(comboBox);
add(label);
}
}
六、运行结果
如果点击退出,则退出程序
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 程序设计 网站 注册