importjavax.swing.UnsupportedLookAndFeelException;
importcom.agen.library.factory.DAOFactory;
importcom.agen.library.util.GlobalUser;
importcom.agen.library.vo.User;
/**
*@author__USER__
publicclassLoginextendsjavax.swing.JFrame{
privatestaticfinallongserialVersionUID=-2176093732040600809L;
/**CreatesnewformLogin*/
publicLogin(){
super("易云图书管理软件V1.0");
Imageime=Toolkit.getDefaultToolkit().getImage(
getClass().getResource("/images/ico.png"));
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(ClassNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(InstantiationExceptione){
}catch(IllegalAccessExceptione){
}catch(UnsupportedLookAndFeelExceptione){
}
setIconImage(ime);
initComponents();
setLocationRelativeTo(null);
this.setResizable(false);
*Thismethodiscalledfromwithintheconstructortoinitializetheform.
*WARNING:DoNOTmodifythiscode.Thecontentofthismethodisalways
*regeneratedbytheFormEditor.
//GEN-BEGIN:initComponents
//editor-folddefaultstate="collapsed"desc="GeneratedCode"
privatevoidinitComponents(){
jLabel2=newjavax.swing.JLabel();
jLabel3=newjavax.swing.JLabel();
jTextField1=newjavax.swing.JTextField();
jPasswordField1=newjavax.swing.JPasswordField();
jButton1=newjavax.swing.JButton();
jButton2=newjavax.swing.JButton();
jLabel1=newjavax.swing.JLabel();
jMenuBar1=newjavax.swing.JMenuBar();
jMenu1=newjavax.swing.JMenu();
jMenuItem1=newjavax.swing.JMenuItem();
jMenu2=newjavax.swing.JMenu();
jMenuItem2=newjavax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addKeyListener(newjava.awt.event.KeyAdapter(){
publicvoidkeyPressed(java.awt.event.KeyEventevt){
formKeyPressed(evt);
publicvoidkeyTyped(java.awt.event.KeyEventevt){
formKeyTyped(evt);
});
jLabel2.setFont(newjava.awt.Font("微软雅黑",0,14));
jLabel2.setText("\u7528\u6237\u540d\uff1a");
jLabel3.setFont(newjava.awt.Font("微软雅黑",0,14));
jLabel3.setText("\u5bc6\u7801\uff1a");
jTextField1.setFont(newjava.awt.Font("微软雅黑",0,14));
jTextField1.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEventevt){
jTextField1ActionPerformed(evt);
jPasswordField1.setFont(newjava.awt.Font("微软雅黑",0,12));
jPasswordField1.addKeyListener(newjava.awt.event.KeyAdapter(){
jPasswordField1KeyTyped(evt);
jButton1.setBackground(newjava.awt.Color(223,216,216));
jButton1.setFont(newjava.awt.Font("微软雅黑",0,14));
jButton1.setText("\u767b\u9646");
jButton1.addActionListener(newjava.awt.event.ActionListener(){
jButton1ActionPerformed(evt);
jButton2.setBackground(newjava.awt.Color(223,216,216));
jButton2.setFont(newjava.awt.Font("微软雅黑",0,14));
jButton2.setText("\u53d6\u6d88");
jButton2.addActionListener(newjava.awt.event.ActionListener(){
jButton2ActionPerformed(evt);
jLabel1.setIcon(newjavax.swing.ImageIcon(
getClass().getResource("/images/login_main.jpg")));//NOI18N
jMenu1.setText("File");
jMenu1.setFont(newjava.awt.Font("微软雅黑",0,14));
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_Q,
java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Exit");
jMenuItem1.addMouseListener(newjava.awt.event.MouseAdapter(){
publicvoidmouseClicked(java.awt.event.MouseEventevt){
jMenuItem1MouseClicked(evt);
jMenuItem1.addActionListener(newjava.awt.event.ActionListener(){
jMenuItem1ActionPerformed(evt);
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Help");
jMenu2.setFont(newjava.awt.Font("微软雅黑",0,14));
jMenuItem2.setText("About");
jMenuItem2.addActionListener(newjava.awt.event.ActionListener(){
jMenuItem2ActionPerformed(evt);
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayoutlayout=newjavax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(
layout.createSequentialGroup()
.addContainerGap()
layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(
jLabel2,
javax.swing.GroupLayout.Alignment.LEADING)
javax.swing.GroupLayout.Alignment.LEADING,
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGap(10,
10,
10)
jButton1)
.addGap(47,
47,
47)
jButton2))
jPasswordField1)
jTextField1,
javax.swing.GroupLayout.DEFAULT_SIZE,
197,
Short.MAX_VALUE))
.addContainerGap()))));
layout.setVerticalGroup(layout
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
javax.swing.GroupLayout.PREFERRED_SIZE,
24,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel3)
jPasswordField1,
23,
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(
Short.MAX_VALUE)));
pack();
}///editor-fold
//GEN-END:initComponents
privatevoidjMenuItem2ActionPerformed(java.awt.event.ActionEventevt){
//TODOaddyourhandlingcodehere:
About.start();
privatevoidjPasswordField1KeyTyped(java.awt.event.KeyEventevt){
if(evt.getKeyChar()=='\n'){
Stringname=jTextField1.getText();//获取用户名
Stringpass=String.valueOf(jPasswordField1.getPassword());//获取密码
Useruser=null;
//未输入用户名
if(name.equals("")||name==null){
JOptionPane.showMessageDialog(this,"用户名不允许为空!","cuowu",0);
return;
user=DAOFactory.getIUserDAOInstance().findById(name);
if(user!=null){
if(user.getPass()!=nulluser.getPass().equals(pass)){
GlobalUser.LOGIN_USER=user;//记录当前用户
//进入主界面
Main.start();
this.dispose();
}else{
JOptionPane.showMessageDialog(this,"用户名或密码错误!");
}catch(Exceptione){
if(user==null){
JOptionPane.showMessageDialog(this,"用户名或密码错误!","消息",0);
privatevoidformKeyTyped(java.awt.event.KeyEventevt){
privatevoidformKeyPressed(java.awt.event.KeyEventevt){
privatevoidjTextField1ActionPerformed(java.awt.event.ActionEventevt){
privatevoidjButton2ActionPerformed(java.awt.event.ActionEventevt){
jTextField1.setText("");
jPasswordField1.setText("");
jTextField1.requestFocus();
privatevoidjButton1ActionPerformed(java.awt.event.ActionEventevt){
if(name.equals("")){
JOptionPane.showMessageDialog(this,"用户名不允许为空!");
privatevoidjMenuItem1ActionPerformed(java.awt.event.ActionEventevt){
if(JOptionPane.showConfirmDialog(this,"你确定要退出吗?","提示",
JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
System.exit(0);
privatevoidjMenuItem1MouseClicked(java.awt.event.MouseEventevt){
System.exit(1);
*@paramargs
*thecommandlinearguments
publicstaticvoidmain(Stringargs[]){
//System.out.println(Login.class.getResource("src/images/images/login_main.jpg"));
//newjavax.swing.ImageIcon(
//Login.class.getResource("../../../../images/login_main.jpg"));
//newLogin().setVisible(true);
java.awt.EventQueue.invokeLater(newRunnable(){
publicvoidrun(){
newLogin().setVisible(true);
//GEN-BEGIN:variables
//Variablesdeclaration-donotmodify
privatejavax.swing.JButtonjButton1;
privatejavax.swing.JButtonjButton2;
privatejavax.swing.JLabeljLabel1;
privatejavax.swing.JLabeljLabel2;
privatejavax.swing.JLabeljLabel3;
privatejavax.swing.JMenujMenu1;
privatejavax.swing.JMenujMenu2;
privatejavax.swing.JMenuBarjMenuBar1;
privatejavax.swing.JMenuItemjMenuItem1;
privatejavax.swing.JMenuItemjMenuItem2;
privatejavax.swing.JPasswordFieldjPasswordField1;
privatejavax.swing.JTextFieldjTextField1;
//Endofvariablesdeclaration//GEN-END:variables
最近好多人要这份源码啊感觉..有建表脚本..使用mysql数据库..建表之后就可以直接运行了.
使用java语言设计一款小型图书管理系统,能够通过主界面根据关键字查询图书信息,能够添加图书信息和删除过去图书信息
#includeiostream
#includestring//C++磁盘操作头文件
#includeistream
#includefstream
#includeiomanip//自定义输出宽度
usingnamespacestd;
structBook//结构类型
{
stringbookname;//书名
stringauthor;//作者名
Book*next;
};
classBookList
public:
BookList(){first=newBook;first-next=NULL;}
intNewBook();
voidSOldBook();
voidtestread();
voidtestwrite();
voidDisplayBook();
~BookList();
private:
Book*first;
intj;
intBookList::NewBook()
Book*s;s=newBook;//为插入的新书申请结点
Book*q;q=newBook;
Book*p;p=newBook;
cout"输入新书书名:";
cins-bookname;
cout"输入作者:";
cins-author;
p=first;q=first;//建立链表
if(first-next==NULL)//如果原链表为空,把新书的结点插入到链表中
first-next=s;//头插法
s-next=NULL;
else{
while(p-next-booknames-bookname)//按书名排序插入
p=p-next;
if(p-next==NULL)break;
s-next=p-next;
p-next=s;
return1;
voidBookList::SOldBook()//查询
Book*s;s=newBook;
cout"输入你要查询的书名:";
p=first-next;
while(p-bookname!=s-bookname)
p=p-next;//接着查找下一个结点
if(p==NULL)break;
if(p==NULL)
cout"你所查询的书没找到!"endl;
else
cout"找到:《"p-bookname"》"p-authorendl;
voidBookList::testread()
ifstreamin;j=0;//读出文件流
in.open("BookList.txt",ios::in);//以读的形式打开原文件
if(!in)
cerr"错误!不能打开文件!";
exit(1);
p=first;
cout"从BookList.txt中读出已有图书如下:"endl;
while(!in.eof())//判断文件是否为空
inq-booknameq-author;//从文件里面读到链表
coutq-bookname""q-authorendl;
j++;
p-next=q;
p=q;
q-next=newBook;
q=q-next;
p-next=NULL;
cout"共有图书"j"本"endlendl;
in.close();
voidBookList::DisplayBook()
j=0;
cout"本馆现有书籍有:"endl;
while(p!=NULL)//输出链表中的元素
coutp-bookname""p-authorendl;
cout"共有图书"j"本"endl;
voidBookList::testwrite()
ofstreamout;//写入文件流
out.open("BookList.txt",ios::out);
if(!out)
for(p=first-next;p!=NULL;p=p-next)
outp-bookname'\t'p-authorendl;//把链表中的元素写到文件中
out.close();
BookList::~BookList()//析构函数
while(p)
q=p;
deleteq;
voidmain()
chars;
inti,k,count=0;
BookListL;//定义对象
L.testread();//把文件中的内容读到链表中
while(1)
char*menu[]={"输入新书","查询旧书","显示所有图书","退出",""};//字符串指针数组
for(i=0;menu[i][0]!='\0';i++)
couti+1"、"menu[i]endl;
cink;
switch(k)
case1:count=L.NewBook();break;
case2:L.SOldBook();break;
case3:L.DisplayBook();break;
default:if(k!=4)cout"输入错误!"endl;break;
if(k==4)
{if(count)
{cout"修改后的BookList.txt未保存,是否保存(y/n):";
cins;
if(s=='y')
L.testwrite();
break;
涉及到页面不刷新技术,这是在考察AJAX,在页面写入AJAX,利用AJAX进行访问action,调用action里的方法,要在页面写好JS
packagepack_view;
importjava.awt.BorderLayout;
importjava.awt.Dimension;
importjava.awt.Font;
importjava.awt.Graphics;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.FocusEvent;
importjava.awt.event.KeyAdapter;
importjava.awt.event.KeyEvent;
importjava.awt.event.MouseAdapter;
importjava.awt.event.MouseEvent;
importjava.awt.event.WindowEvent;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjavax.swing.ImageIcon;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JPasswordField;
importjavax.swing.JTextField;
importjavax.swing.plaf.multi.MultiLookAndFeel;
importpack_DB.DB;
publicclassLoginextendsJFrame{
*登陆界面
privatestaticfinallongserialVersionUID=1L;
JFramejf=newJFrame();
privateJPanelpanel_all;
privateJPanelpanel1=newJPanel();
privateJPanelpanel2=newJPanel();
privateJPanelpanel3=newJPanel();
privateJPanelpanel4=newJPanel();
privateJLabeljLabel_title;
privateJLabeljLabel_name=newJLabel();
privateJLabeljLabel_password=newJLabel();
privateJTextFieldjTextField_name=newJTextField(15);
privateJPasswordFieldjPasswordField=newJPasswordField(15);
privateJButtonjb1=newJButton();
privateJButtonjb2=newJButton();
privateFontfont;
Stringcid="";
Stringpasswd="";
//加载背景图片
//privateImageIconimageicon;
//privateImageimage;
jf.setTitle("客户端登陆");
jf.setSize(350,300);
DimensionscreenSize=Toolkit.getDefaultToolkit().getScreenSize();//把用户的显示器屏幕的尺寸(长和宽)赋值给变量screenSize
DimensionframeSize=jf.getSize();
if(frameSize.heightscreenSize.height){
frameSize.height=screenSize.height;
if(frameSize.widthscreenSize.width){
frameSize.width=screenSize.width;
//把弹出的对话框窗口放置在屏幕中间
jf.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);
//imageicon=newImageIcon(ClassLoader
//.getSystemResource("res/backgound.jpg".toString()));
panel_all=newJPanel(){
publicvoidpaintComponent(Graphicsg){
super.paintComponents(g);
//image=imageicon.getImage();
//if(image!=null)
//g.drawImage(image,0,0,getWidth(),getHeight(),this);
font=newFont("宋体正文",0,20);
jLabel_title=newJLabel(newImageIcon(ClassLoader
.getSystemResource("res/Login.jpg".toString())));
jLabel_title.setFont(font);
jLabel_title.setText("用户登陆");
jLabel_name.setFont(newjava.awt.Font("Dialog",0,14));
jLabel_name.setText("用户名:");
jLabel_password.setFont(newjava.awt.Font("Dialog",0,14));
jLabel_password.setText("密码:");
jb1.setFont(newjava.awt.Font("Dialog",0,18));
jb1.setText("确认");
jb2.setText("取消");
jb2.setFont(newjava.awt.Font("Dialog",0,18));
jTextField_name.addKeyListener(newKeyAdapter()
publicvoidkeyPressed(KeyEvente)
if(e.getKeyCode()==KeyEvent.VK_ENTER)
jb1.doClick();
}});
jPasswordField.addKeyListener(newKeyAdapter()
panel1.add(jLabel_name);
panel1.add(jTextField_name);
panel2.add(jLabel_password);
panel2.add(jPasswordField);
panel3.add(jb1);
panel3.add(jb2);
panel4.add(jLabel_title);
panel_all.setLayout(newGridLayout(4,1));
panel_all.add(panel4);
panel_all.add(panel1);
panel_all.add(panel2);
panel_all.add(panel3);
panel_all.setOpaque(false);
jf.setLayout(newBorderLayout());
jf.add(panel_all);
jb1.addMouseListener(newMouseAdapter(){
publicvoidmouseClicked(MouseEventme){
//if(lc.validate(jTextField_name.getText().trim(),newString(jPasswordField.getPassword()).trim())){
//doLogin();
//newMainFrame();
//}
//else
//JOptionPane.showMessageDialog(null,"Passworddoesn'tmatchaccount,pleasetryagain!");
jb2.addMouseListener(newMouseAdapter(){
jf.setVisible(true);
jf.repaint();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*publicvoiddoLogin(){
cid=jTextField_name.getText().trim();
passwd=jPasswordField.getText().trim();
Stringsql="select*fromcustomerwhere"+"cid='"+cid+"'andpassword='"+passwd+"'";