java swing制作的topik练习软件源代码数据库相连接的.docx
- 文档编号:5095580
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:40
- 大小:29.45KB
java swing制作的topik练习软件源代码数据库相连接的.docx
《java swing制作的topik练习软件源代码数据库相连接的.docx》由会员分享,可在线阅读,更多相关《java swing制作的topik练习软件源代码数据库相连接的.docx(40页珍藏版)》请在冰豆网上搜索。
javaswing制作的topik练习软件源代码数据库相连接的
packagepage;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.event.ListSelectionEvent;
importjavax.swing.event.ListSelectionListener;
importponent.RiverLayout;
importjava.sql.*;
importjava.util.Collections;
importjava.util.Vector;
publicclassProject1extendsJFrame{
/**
*
*/
privatestaticfinallongserialVersionUID=1L;
Connectionconn;
JFrameframe;
StringframeTitle="TOPIK2012";//登陆界面的名称
StringinputID;
staticJTextFieldID;
JPasswordFieldpassword;
JButtonlogIn;
JButtonlogOn;
JPanelcenterTopPanel=newJPanel(newRiverLayout());
JPaneltopPanel=newJPanel();
JPanelcenterPanel=newJPanel(newGridLayout(1,3));
JPanelcenterLeftPanel=newJPanel(newRiverLayout());
JPanelcenterRightPanel=newJPanel(newRiverLayout());
JPanelbottomPanel=newJPanel(newFlowLayout());
JPanelmainPanel=newJPanel(newBorderLayout());
privateJPanelimagePanel;
privateImageIconbackground;
//ImageIconimage=newImageIcon("E:
/2012Second/2009JSPworkplace/徐娟/src/image/3.jpg");//添加背景图片;
//JLabelimgLabel=newJLabel(image);
publicstaticvoidmain(String[]args){
Project1client=newProject1();
client.setUpGui();
client.dbConnectionInit();
}
publicvoidcenterWindow(Componentcomponent){//设置窗口显示的初始位置为电脑正中央
Toolkittoolkit=Toolkit.getDefaultToolkit();
DimensionscmSize=toolkit.getScreenSize();
intwidth=375;
intheight=250;
component.setLocation(scmSize.width/2-(width/2),scmSize.height/2-(height/2));
}
//*************************登陆界面GUI设定************************************************
privatevoidsetUpGui(){
frame=newJFrame(frameTitle);
ID=newJTextField(10);
password=newJPasswordField(10);//设置密码栏为不可见。
password.setEchoChar('*');
topPanel.add("brcenter",newJLabel(""));
//topPanel.setSize(375,150);
topPanel.setOpaque(false);
centerLeftPanel.add("pright",newJLabel("ID"));
centerLeftPanel.setOpaque(false);
centerLeftPanel.add("pright",newJLabel("PASSWORD"));
centerRightPanel.add("pleft",ID);
centerRightPanel.add("pleft",password);
centerRightPanel.setOpaque(false);
centerPanel.add(centerLeftPanel);
centerPanel.add(centerRightPanel);
centerPanel.setOpaque(false);
logIn=newJButton("로그인");
centerRightPanel.add("pcenter",logIn);
logOn=newJButton("로그온");
centerRightPanel.add(logOn);
background=newImageIcon(getClass().getResource("3.jpg"));
JLabellabel=newJLabel(background);
label.setBounds(0,0,background.getIconWidth(),background.getIconHeight());
imagePanel=(JPanel)frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(newBorderLayout());
imagePanel.add(topPanel,BorderLayout.NORTH);
imagePanel.add(bottomPanel,BorderLayout.SOUTH);
imagePanel.add(centerPanel,BorderLayout.CENTER);
logIn.addActionListener(newlogInButtonListener());//设置logIn按钮的监听。
logOn.addActionListener(newlogOnActionListener());
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label,newInteger(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(background.getIconWidth(),background.getIconHeight());
frame.setVisible(true);
centerWindow(frame);
frame.getRootPane().setDefaultButton(logIn);
}
privatevoiddbConnectionInit(){//与数据库相连接
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:
mysql:
//localhost/proj1","root","dmlrhd");
}
catch(ClassNotFoundExceptioncnfe){
System.out.println("JDBC드라이버클래스를찾을수없습니다:
"+cnfe.getMessage());
}
catch(Exceptionex){
System.out.println("DB연결에러:
"+ex.getMessage());
}
}
staticclassGID{//设置全局变量,用以保存用户输入的ID
publicstaticStringgID;
}
publicclasslogInButtonListenerimplementsActionListener{//为登陆界面上的登录按钮设置监听,如果ID和密码都正确就显示出另一额界面,
//可以练习topik,修改自己的信息,如果是管理员登陆的话还可以添加用户,删除用户,修改用户的信息
publicvoidactionPerformed(ActionEvente){
try{
GID.gID=ID.getText();
Statementstmt=conn.createStatement();
ResultSetrs=stmt.executeQuery("SELECTID,passwordFROMkoreaWHEREID='"+GID.gID+"';");//从数据库中调出用户名和密码。
//System.out.println("SELECTID,passwordFROMkoreaWHEREID='"+ID.getText()+"';");
if(rs.next()){//验证用户名与密码是否正确。
StringsqlID=rs.getString("ID");//从数据库中查到的ID和password
Stringsqlpassword=rs.getString("password");
//System.out.println(sqlID+""+sqlpassword);//验证数据库中的ID和password
inputID=ID.getText();//从窗口上接收到的ID和password
char[]spassword=password.getPassword();
Stringinputpassword=String.valueOf(spassword);//把char[]的password转化为String型的password
//System.out.println(inputID+""+inputpassword);//验证从键盘得到的ID和password是不是正确的
if((rs!
=null)&&(inputID.equals(sqlID))&&(inputpassword.equals(sqlpassword))){//如果ID和passwrd都吻合的话
frame.setVisible(false);//设置如果登陆成功的话就跳转到试题窗口,关闭登陆界面
newMyFrame1().launch();
}
}
stmt.close();
}catch(SQLExceptionsqlex){
System.out.println("SQL에러:
"+sqlex.getMessage());
sqlex.printStackTrace();
}catch(Exceptionex){
System.out.println("DBHandling에러(LOGIN리스너):
"+ex.getMessage());
ex.printStackTrace();
}
}
}
publicclasslogOnActionListenerimplementsActionListener{//注册界面
publicvoidactionPerformed(ActionEvente){
//frame.setVisible(false);
newlogOnFrame().logOn();
}
}
}
classlogOnFrameextendsProject1{
/**
*
*/
privatestaticfinallongserialVersionUID=1L;
logOnFrameLogOnFrame;
StringlogOnTitle="로그온페이지";
JTextFieldnewID=newJTextField(15);
JTextFieldnewpassword=newJTextField(15);
JTextFieldnewname=newJTextField(15);
JTextFieldnewbirthday=newJTextField(15);
JTextFieldnewkoreagrade=newJTextField(15);
JTextFieldnewsex=newJTextField(15);
JTextFieldnewage=newJTextField(15);
JTextFieldnewemail=newJTextField(15);
JButtonsaveButton=newJButton("저장");
publiclogOnFrame(StringlogOnTitle){
//TODOAuto-generatedconstructorstub
}
publiclogOnFrame(){
//TODOAuto-generatedconstructorstub
}
publicvoidlogOn(){//注册界面的设定
LogOnFrame=newlogOnFrame(logOnTitle);
saveButton.setBackground(Color.orange);
newID.setPreferredSize(newDimension(15,25));
newpassword.setPreferredSize(newDimension(15,25));
newname.setPreferredSize(newDimension(15,25));
newbirthday.setPreferredSize(newDimension(15,25));
newkoreagrade.setPreferredSize(newDimension(15,25));
newsex.setPreferredSize(newDimension(15,25));
newage.setPreferredSize(newDimension(15,25));
newemail.setPreferredSize(newDimension(15,25));
JPaneltopPanel=newJPanel(newBorderLayout());
JPaneltopTopPanel=newJPanel();
JPaneltopBottomPanel=newJPanel();
JLabelsignUp=newJLabel("SignUp");
Fontfnt=newFont("Parchment",Font.ITALIC,35);
signUp.setFont(fnt);
topTopPanel.add("pcenter",signUp);
topBottomPanel.add("pcenter",newJLabel("-------------------------------------"+
"----------------------------------------------------------------------------------------------------------"));
topPanel.add(BorderLayout.CENTER,topTopPanel);
topPanel.add(BorderLayout.SOUTH,topBottomPanel);
JPanelleftCenterPanel=newJPanel();//用于放左边的图片
ImageIconimage=newImageIcon(getClass().getResource("korea.jpg"));//添加背景图片;
JLabelimgLabel=newJLabel(image);
imgLabel.setOpaque(false);//设置背景透明化
leftCenterPanel.add(imgLabel);
imgLabel.setBounds(0,0,image.getIconWidth(),image.getIconHeight());
FontfntJlabel=newFont("HaanSollipB",Font.ITALIC,15);
JLabelIDLabel=newJLabel("ID");
IDLabel.setFont(fntJlabel);
JLabelpasswordLabel=newJLabel("Password");
passwordLabel.setFont(fntJlabel);
JLabelnameLabel=newJLabel("Name");
nameLabel.setFont(fntJlabel);
JLabelbirthdayLabel=newJLabel("Birthday");
birthdayLabel.setFont(fntJlabel);
JLabelkoreagradeLabel=newJLabel("KoreaGrade");
koreagradeLabel.setFont(fntJlabel);
JLabelsexLabel=newJLabel("Sex");
sexLabel.setFont(fntJlabel);
JLabelageLabel=newJLabel("Age");
ageLabel.setFont(fntJlabel);
JLabelemailLabel=newJLabel("Email");
emailLabel.setFont(fntJlabel);
JPanelrightCenterPanel=newJPanel(newRiverLayout());
rightCenterPanel.add("br",IDLabel);
rightCenterPanel.add("tab",newID);
rightCenterPanel.add("br",passwordLabel);
rightCenterPanel.add("tab",newpassword);
rightCenterPanel.add("br",nameLabel);
rightCenterPanel.add("tab",newname);
rightCenterPanel.add("br",birthdayLabel);
rightCenterPanel.add("tab",newbirthday);
rightCenterPanel.add("br",koreagradeLabel);
rightCenterPanel.add("tab",newkoreagrade);
rightCenterPanel.add("br",sexLabel);
rightCenterPanel.add("tab",newsex);
rightCenterPanel.add("br",ageLabel);
rightCenterPanel.add("tab",newage);
rightCenterPanel.add("br",emailLabel);
rightCenterPanel.add("tab",newemail);
JPanelbottomPanel=newJPanel(newBorderLayout());
JPanelbottomCenterPanel=newJPanel();
JPanelbottomBottomPanel=newJPanel(newGridLayout(1,2));
JPanelbottomBottomLeftPanel=newJPanel();
JPanelbottomBottomRightPanel=newJPanel();
bottomCenterPanel.add("pcenter",newJLabel("-------------------------------------"+
"----------------------------------------------------------------------------------------------------------"));
bottomBottomRightPanel.add("pcenter",saveButton);
bottomBottomPanel.add(bottomBottomLeftPanel);
bottomBottomPanel.add(bottom
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java swing制作的topik练习软件源代码数据库相连接的 swing 制作 topik 练习 软件 源代码 数据库 相连
![提示](https://static.bdocx.com/images/bang_tan.gif)