Java课程设计总结报告Word文档格式.docx
- 文档编号:19368697
- 上传时间:2023-01-05
- 格式:DOCX
- 页数:24
- 大小:1.18MB
Java课程设计总结报告Word文档格式.docx
《Java课程设计总结报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《Java课程设计总结报告Word文档格式.docx(24页珍藏版)》请在冰豆网上搜索。
1.数据库存储入住人信息
2.数据库登陆账号密码
4.公共类设计
(1)公共类用于加载数据库驱动
packagexg。
dao;
importjava。
sql.Connection;
sql.DriverManager;
importjavax.swing.JOptionPane;
publicclassDAO{
@SuppressWarnings("
unused”)
privatestaticDAOdao=newDAO();
/**
*构造方法,加载数据库驱动
*/
publicDAO(){
try{
Class。
forName("
net.sourceforge。
jtds。
jdbc。
Driver"
);
}catch(ClassNotFoundExceptione){
JOptionPane.showMessageDialog(null,"
数据库驱动加载失败,请将JTDS驱动配置到构建路径中.\n”+e.getMessage());
}
/**
*获得数据库连接的方法
*
*@returnConnection
publicstaticConnectiongetConn(){
Connectionconn=null;
Stringurl="
jdbc:
jtds:
sqlserver:
//localhost:
1433/XG”;
//数据库XG路径
Stringusername="
sa”;
//数据库的用户名
Stringpassword="
123456”;
//数据库密码
conn=DriverManager.getConnection(url,username,password);
//建立连接
returnconn;
}catch(Exceptione){
JOptionPane.showMessageDialog(null,”数据库连接失败。
\n请检查数据库用户名和密码是否正确。
”+e。
getMessage());
returnnull;
}
}
5.程序主要系统开发
(1)系统登录界面
登录系统在绘制背景前先获取该图片用getImage()方法获得image类型的对象,然后获取ImagIcon类型对象,用该构造方法传递URL参数。
主要函数超累构造方法:
调用父类方法,绘制图像:
与数据库连接判断函数:
实现登陆功能:
(主要函数)
privateJPanelgetJPanel(){
if(jPanel==null){
jLabel1=newJLabel();
jLabel1.setBounds(newRectangle(221,176,63,18));
jLabel1。
setText("
密码:
”);
setForeground(Color。
WHITE);
jLabel=newJLabel();
jLabel.setBounds(newRectangle(220,141,63,18));
jLabel.setText(”用户:
"
jLabel。
setForeground(Color.WHITE);
url=UpdateFrame。
class.getResource(”/image/酒店登陆背景。
jpg"
//获得图片的URL
image=newImageIcon(url)。
getImage();
//创建图像对象
jPanel=newBackgroundPanel(image);
jPanel。
setLayout(null);
jPanel.add(jLabel,null);
jPanel.add(jLabel1,null);
add(getTf_username(),null);
jPanel.add(getPf_password(),null);
add(getBtn_login(),null);
add(getBtn_reset(),null);
jPanel.add(getBtn_exit(),null);
returnjPanel;
/*举例其中一个按钮设置*/
privateJTextFieldgetTf_username(){
if(tf_username==null){
tf_username=newJTextField();
tf_username.setBounds(newRectangle(290,140,143,22));
tf_username。
addActionListener(newjava。
awt.event.ActionListener(){
@Override
publicvoidactionPerformed(java。
awt.event。
ActionEvente){
pf_password。
requestFocus();
});
returntf_username;
6.系统主界面
主要函数代码:
等其他看eclipse中的函数。
7.登记入住界面/查看界面
实现过程:
登记入住界面用于酒店登记住户该窗体用到6个文本框和3个命令按钮.
在sqldao中可以进行判断输入的数据是否符合要求或者是否有信息没有填写。
packagexg.frame;
importjava.awt。
BorderLayout;
FlowLayout;
//importjava。
awt。
Font;
awt.Image;
importjava.awt.Rectangle;
net。
URL;
importjavax.swing。
ImageIcon;
JButton;
JFrame;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
importxg.bean.S;
importxg。
dao。
SQLDao;
panel.BackgroundPanel;
publicclassAEFrameextendsJFrame{
privatestaticfinallongserialVersionUID=1L;
privateJPaneljContentPane=null;
privateURLurl=null;
//声明图片的URL
privateImageimage=null;
//声明图像对象
privateBackgroundPaneljPanel=null;
//声明自定义背景面板对象
privateJTextFieldtf_A1=null;
privateJTextFieldtf_A2=null;
privateJTextFieldtf_sendCompany=null;
privateJTextFieldtf_timE1=null;
privateJTextFieldtf_timE2=null;
privateJTextFieldtf_timE3=null;
privateJPaneljPanel1=null;
privateJButtonbtn_clear=null;
privateJButtonbtn_save=null;
privateJButtonbtn_return=null;
privateJPanelgetJPanel1(){
if(jPanel1==null){
jPanel1=newJPanel();
jPanel1。
setLayout(newFlowLayout());
jPanel1.add(getBtn_clear(),null);
jPanel1.add(getBtn_save(),null);
add(getBtn_return(),null);
returnjPanel1;
privateJButtongetBtn_clear(){
if(btn_clear==null){
btn_clear=newJButton();
btn_clear。
清空”);
btn_clear.addActionListener(newjava。
event.ActionListener(){
@Override
publicvoidactionPerformed(java.awt.event。
ActionEvente){
tf_A1。
setText(”姓名:
tf_A2.setText("
房间类型(A/B/C):
);
tf_sendCompany.setText(”身份证:
tf_timE1.setText(”联系电话:
tf_timE2。
入住时间(年/月/日):
”);
tf_timE3.setText("
退房日期(年/月/日):
requestFocus();
});
returnbtn_clear;
privateJButtongetBtn_save(){
if(btn_save==null){
btn_save=newJButton();
btn_save。
保存”);
event。
ActionListener(){
StringBufferbuffer=newStringBuffer();
Sm=newS();
m.setA1(tf_A1.getText()。
trim());
m.setA2(tf_A2。
getText().trim());
m.setA3(tf_sendCompany。
getText()。
buffer.append(tf_A1.getX()+"
,”+tf_A1.getY()+"
/”);
buffer.append(tf_A2.getX()+”,"
+tf_A2.getY()+”/"
buffer.append(tf_sendCompany.getX()+”,"
+tf_sendCompany。
getY()+”/”);
buffer。
append(tf_timE1.getX()+"
”+tf_timE1。
getY()+"
/"
append(tf_timE2.getX()+”,”+tf_timE2。
getY()+”/"
append(tf_timE3.getX()+"
”+tf_timE3。
m.setControlPosition(newString(buffer));
m.setExpressSize(jPanel。
getWidth()+"
"
+jPanel。
getHeight());
SQLDao.insertExpress(m);
returnbtn_save;
privateJButtongetBtn_return(){
if(btn_return==null){
btn_return=newJButton();
btn_return。
setText(”返回”);
dispose();
returnbtn_return;
publicAEFrame(){
super();
initialize();
privatevoidinitialize(){
this.setSize(617,413);
this。
setTitle("
登记入住界面”);
this.setContentPane(getJContentPane());
privateJPanelgetJContentPane(){
if(jContentPane==null){
jContentPane=newJPanel();
jContentPane.setLayout(newBorderLayout());
jContentPane.add(getJPanel(),BorderLayout.CENTER);
jContentPane.add(getJPanel1(),BorderLayout。
SOUTH);
returnjContentPane;
privateBackgroundPanelgetJPanel(){
url=AEFrame。
class.getResource("
/image/登记界面.jpg"
setLayout(null);
jPanel.add(getTf_A1(),null);
add(getTf_A2(),null);
jPanel.add(getTf_sendCompany(),null);
jPanel.add(getTf_timE1(),null);
jPanel.add(getTf_timE2(),null);
jPanel.add(getTf_timE3(),null);
returnjPanel;
privateJTextFieldgetTf_A1(){
if(tf_A1==null){
tf_A1=newJTextField(”姓名:
tf_A1.setBounds(newRectangle(114,114,139,22));
returntf_A1;
privateJTextFieldgetTf_A2(){
if(tf_A2==null){
tf_A2=newJTextField();
tf_A2。
setBounds(newRectangle(347,114,131,22));
returntf_A2;
privateJTextFieldgetTf_sendCompany(){
if(tf_sendCompany==null){
tf_sendCompany=newJTextField(”身份证:
tf_sendCompany。
setBounds(newRectangle(114,141,362,22));
returntf_sendCompany;
privateJTextFieldgetTf_timE1(){
if(tf_timE1==null){
tf_timE1=newJTextField("
联系电话:
tf_timE1.setBounds(newRectangle(114,179,362,22));
returntf_timE1;
privateJTextFieldgetTf_timE2(){
if(tf_timE2==null){
tf_timE2=newJTextField("
入住时间(年/月/日):
tf_timE2.setBounds(newRectangle(114,205,362,22));
returntf_timE2;
privateJTextFieldgetTf_timE3(){
if(tf_timE3==null){
tf_timE3=newJTextField("
退房日期(年/月/日):
tf_timE3。
setBounds(newRectangle(114,230,362,22));
returntf_timE3;
}
8.修改登记入住界面
修改入住界面多了一个可以修改的按钮,修改后的数据可以保存到数据库中并且显示
privateJButtongetBtn_update(){
if(btn_update==null){
btn_update=newJButton();
btn_update.setText("
修改"
btn_update.addActionListener(newjava。
m。
setId(id);
setA1(tf_A1。
setA2(tf_A2。
trim());
m.setA3(tf_sendCompany.getText()。
settimE(tf_timE1.getText().trim()+"
|”+tf_timE2。
trim()+”|"
+tf_timE3.getText().trim());
append(tf_A1。
getX()+"
”+tf_A1。
buffer.append(tf_A2。
”+tf_A2.getY()+”/"
buffer.append(tf_sendCompany.getX()+"
,"
+tf_sendCompany.getY()+”/”);
buffer.append(tf_timE1.getX()+"
,”+tf_timE1.getY()+”/"
buffer.append(tf_timE2。
”+tf_timE2.getY()+"
append(tf_timE3.getX()+”,"
+tf_timE3。
SQLDao。
updateExpress(m);
queryResultVector=SQLDao。
queryAllExpress();
if(queryResultVector!
=null){
m=queryResultVector。
get(queryRow);
});
returnbtn_update;
数据库中修改连接代码
publicstaticvoidupdateExpress(Sm){
Connectionconn=null;
PreparedStatementps=null;
conn=DAO。
getConn();
ps=conn
。
prepareStatement("
updatetb_receiveSendMessagesetA1=?
,A2=?
,A3=?
timE=?
,ControlPosition=?
expressSize=?
whereid=?
ps.setString(1,m。
getA1());
ps.setString(2,m.getA2());
ps.setString(3,m.getA3());
ps。
setString(4,m.gettimE());
ps.setString(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 课程设计 总结报告