java之GUI仿QQ登陆,餐饮管理系统模型

------- android培训java培训、期待与您交流! ----------

对于这章感觉自己学的没白学,因为看到了东西,不像纯代码,看了以后不明白具体如何跟图形化进行联系。看不见成果。

对于这张我感觉最有帮助的就是网络象棋的小项目,服务器做的比较简单,但是客户端虽然简陋,但是挑战,认输,下棋,拒绝挑战等功能都做了,

具体用到了,集合,多线程,IO流,Socket,ServerSocket 等知识,能够将这些知识总和起来。对我的帮助很大。听说DOM2模式就是 图形一个包,链接类一个包。数据库一个包。

三个包组合一个项目,看着简单。网络象棋这个小项目就是用的这种模型,感觉挺好。

通过这章:一开始,我把所有的标签按钮监听等都在一个方法中写遇到错误好乱啊,到最后,每个步骤都在一个方法中,初始化组件一个方法,初始化窗体一个方法,初始化监听一个方法。在构造函数中,分别调用,这样看着更加清晰。找错更加容易。

对于GUI这一张:在网上找的小项目练习的挺多,感觉遇到问题,看看这些小项目,就可以找到问题了,所以直接上图:

仿QQ登陆界面:


代码如下:

package Interface;
import java.awt.*;
import Model.*;
import gongg.xinxi;
import javax.swing.*;
import java.awt.event.*;
public class QQDL extends JFrame implements ActionListener{
JPanel p1,p2,p3;
JButton b1,b2,b3,b4;
JLabel bq1,bq2,bq3,bq4,bq5,bq6;
JCheckBox fx1,fx2;
JTextField wbk;
JPasswordField mmk;
JTabbedPane xxk;
public static void main(String[] args){
QQDL one=new QQDL();
}
public QQDL(){
bq1=new JLabel("QQ账号",JLabel.CENTER);bq2=new JLabel("QQ密码",JLabel.CENTER);
bq3=new JLabel("<html><a href='www.qq.com'>忘记密码</a>");bq3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
bq4=new JLabel("<html><a href='www.qq.com'>申请密码保护</a>");bq4.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
bq5=new JLabel(new ImageIcon("images/QQ.jpg"));
bq6=new JLabel("无内容");
bq6.setFont(new Font("宋体",Font.PLAIN,22));
wbk=new JTextField(10);mmk=new JPasswordField(10);
b1=new JButton(new ImageIcon("images/QQ1.jpg"));
b2=new JButton(new ImageIcon("images/QQ2.jpg"));
b2.addActionListener(this);
b2.setActionCommand("11");
b3=new JButton(new ImageIcon("images/QQ3.jpg"));
b3.addActionListener(this);
b3.setActionCommand("22");
b4=new JButton(new ImageIcon("images/QQ4.jpg"));
fx1=new JCheckBox("隐身登陆");fx2=new JCheckBox("记住密码");
p1=new JPanel();
p2=new JPanel();
p2.setLayout(new GridLayout(3,3));
p2.add(bq1);p2.add(wbk);p2.add(b1);
p2.add(bq2);p2.add(mmk);p2.add(bq3);
p2.add(fx1);p2.add(fx2);p2.add(bq4);
p3=new JPanel();
p3.add(b2);p3.add(b3);
xxk=new JTabbedPane();
p1.add(bq6);p1.setBackground(Color.GREEN);
xxk.add("普通用户",p2);xxk.add("QQ会员",p1);
this.add(bq5,BorderLayout.NORTH);
this.add(xxk,BorderLayout.CENTER);
this.add(p3,BorderLayout.SOUTH);
this.setSize(300,300);
this.setTitle("QQ用户端");
int a=Toolkit.getDefaultToolkit().getScreenSize().width;
int b=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(a/2-200,b/2-200);
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("11")){
xinxi xx=new xinxi();
xx.setUser(wbk.getText());
xx.setMima(new String(mmk.getPassword()));
fasong fs=new fasong();
if(fs.yanz(xx)){
liebiao lb=new liebiao(xx.getUser());
this.dispose();
System.out.println("登陆成功");
}
else{
JOptionPane.showMessageDialog(this,"用户名密码错误");}

}else if(e.getActionCommand().equals("22")){
System.out.println("取消");
this.dispose();
}
}

}

网上找的小项目餐饮管理系统:只是图形化界面写出来了,具体功能没有实现




读取界面的代码:

package cy_interface;
import javax.swing.*;
import cy_model.moxing;
import java.awt.*;
public class mainInterface extends JWindow implements Runnable{
JLabel bq;
JProgressBar jb;
int width,height;
public static void main(String[] args){
mainInterface one=new mainInterface();
Thread two=new Thread(one);
two.start();
}
public mainInterface(){
bq=new JLabel(new ImageIcon("images/index.gif"));
jb=new JProgressBar();
jb.setBackground(Color.darkGray);
jb.setStringPainted(true);
jb.setIndeterminate(false);
jb.setBorderPainted(false);
this.add(bq,BorderLayout.CENTER);
this.add(jb,BorderLayout.SOUTH);
this.setSize(400,260);
width=Toolkit.getDefaultToolkit().getScreenSize().width;
height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(width/2-100,height/2-200);
this.setVisible(true);
}
public void run(){
int[] arr={0,3,5,8,9,12,15,17,20,38,48,58,68,78,90,92,94,96,98,100};
for(int i=0;i<arr.length;i++){
try{
Thread.sleep(400);}
catch(Exception e){}
jb.setValue(arr[i]);

}
interface_2 one=new interface_2();
this.dispose();

}
}

登陆界面的代码:

package cy_interface;
import java.awt.*;
import cy_model.moxing;
import javax.swing.*;
import javax.imageio.*;
import java.io.*;
import javax.swing.border.*;
import java.awt.event.*;
class interface_2 extends JDialog implements ActionListener{
JLabel bq1,bq2,bq3;
JButton b1,b2;
Font f1;
JTextField wbk;
JPasswordField mmk;
int width,height;
public static void main(String[] args){
interface_2 one=new interface_2();
}
public interface_2(){
super();
bq1=new JLabel("请输入用户名:");
bq1.setBounds(40,170,150,30);
this.add(bq1);
bq2=new JLabel("或员工号");
bq2.setBounds(80,190,100,30);
//设置前景颜色为红色
bq2.setForeground(Color.red);
this.add(bq2);
bq3=new JLabel("请输入密码:");
bq3.setBounds(40,220,150,30);
this.add(bq3);
wbk=new JTextField(20);
wbk.setFocusable(true);
wbk.setBounds(160,170,120,25);
wbk.setBorder(BorderFactory.createLoweredBevelBorder());
this.add(wbk);
mmk=new JPasswordField(20);
//获取焦点
mmk.setFocusable(true);
mmk.setBounds(160,220,120,25);
//设置边框
mmk.setBorder(BorderFactory.createLoweredBevelBorder());
this.add(mmk);
b1=new JButton("确定");
b1.addActionListener(this);
b1.setActionCommand("11");
b1.setBounds(85,280, 75,30);
b1.setForeground(Color.BLUE);
this.add(b1);
b2=new JButton("取消");
b2.addActionListener(this);
b2.setActionCommand("22");
b2.setBounds(195, 280, 75, 30);
b2.setForeground(Color.BLUE);
this.add(b2);
tupian tt=new tupian();
//tt.setBounds(0,0,350,350);
this.add(tt);
//this.setLayout(null);
//this.setUndecorated(true);
this.setSize(350,350);
width=Toolkit.getDefaultToolkit().getScreenSize().width;
height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(width/2-100,height/2-200);
this.setVisible(true);
this.setResizable(true);

}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("11")){
String zhiwei=null;
String aa=wbk.getText();
String bb=new String(mmk.getPassword());
moxing mo=new moxing();
interface_3 one=new interface_3();
zhiwei=mo.yanzheng(aa,bb);
if(zhiwei.equals("经理")||zhiwei.equals("职员")){
//interface_3 one=new interface_3();
this.dispose();
}
else { JOptionPane.showMessageDialog(this,"账号密码输入错误");}
}




else if(e.getActionCommand().equals("22")){
this.dispose();
}
}
}
class tupian extends JPanel{
Image im;
ImageIcon ii;
public tupian(){
ii=new ImageIcon("images/login.gif");
im=ii.getImage();

}
public void paint(Graphics g){
g.drawImage(im,0,0,350,350,this);
}

进入后的界面:

package cy_interface;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class interface_3 extends JFrame implements MouseListener{
JMenuBar cd;
CardLayout card1,card2;
JToolBar jt;
JMenu cd1,cd2,cd3,cd4,cd5,cd6;
JMenuItem cdx1,cdx2,cdx3,cdx4,cdx5,cdx6,cdx7;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10;
ImageIcon ii;
Image im;
JSplitPane jsp;
JPanel pa1,pa2;
JPanel pa2x1,pa2x2;
JLabel hbx1,hbx2,hbx3,hbx4,hbx5,hbx6,hbx7,hbx8;
JLabel pa2x1_1,pa2x1_2;
JPanel pa2x2_1,pa2x2_2,pa2x2_3,pa2x2_4,pa2x2_5,pa2x2_6,pa2x2_7;
JLabel p2x2_1,p2x2_2,p2x2_3,p2x2_4,p2x2_5,p2x2_6,p2x2_7;
public static void main(String[] args){
interface_3 one=new interface_3();
}
public interface_3(){
this.method_1();
this.method_2();
this.method_3();
this.setFont(myfont.f1);
this.setTitle("满汉楼餐饮管理系统");
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setSize(1000,700);
ImageIcon ii=new ImageIcon("images/title.gif");
Image im=ii.getImage();
this.setIconImage(im);
this.setLocation(width/2-480, height/2-380);
this.setVisible(true);
this.setResizable(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void method_1(){//菜单
cd=new JMenuBar();
cdx1=new JMenuItem("切换用户");cdx2=new JMenuItem("切换到收款界面");cdx3=new JMenuItem("登陆管理");
cdx4=new JMenuItem("万年历");cdx5=new JMenuItem("退出");
cd1=new JMenu("系统管理(F)");cd1.setMnemonic('F');
cd2=new JMenu("人事管理(E)");cd2.setMnemonic('E');
cd3=new JMenu("菜单服务(R)");cd3.setMnemonic('R');
cd4=new JMenu("报表统计(W)");cd4.setMnemonic('W');
cd5=new JMenu("成本及库房(Q)");cd5.setMnemonic('Q');
cd6=new JMenu("帮助(H)");cd6.setMnemonic('H');
cd1.add(cdx1);cd1.add(cdx2);cd1.add(cdx3);cd1.add(cdx4);
cd1.add(cdx5);
cd.add(cd1);cd.add(cd2);cd.add(cd3);cd.add(cd4);cd.add(cd5);cd.add(cd6);
this.setJMenuBar(cd);

}
public void method_2()//工具栏
{
jt=new JToolBar();
b1=new JButton(new ImageIcon("images/jb1.jpg"));b1.setToolTipText("");
b2=new JButton(new ImageIcon("images/jb2.jpg"));b2.setToolTipText("");
b3=new JButton(new ImageIcon("images/jb3.jpg"));b3.setToolTipText("");
b4=new JButton(new ImageIcon("images/jb4.jpg"));b4.setToolTipText("");
b5=new JButton(new ImageIcon("images/jb5.jpg"));b5.setToolTipText("");
b6=new JButton(new ImageIcon("images/jb6.jpg"));b6.setToolTipText("");
b7=new JButton(new ImageIcon("images/jb7.jpg"));b7.setToolTipText("");
b8=new JButton(new ImageIcon("images/jb8.jpg"));b8.setToolTipText("");
b9=new JButton(new ImageIcon("images/jb9.jpg"));b9.setToolTipText("");
b10=new JButton(new ImageIcon("images/jb10.jpg"));//b10.setToolTipText("");
jt.add(b1);jt.add(b2);jt.add(b3);jt.add(b4);
jt.add(b5);jt.add(b6);jt.add(b7);jt.add(b8);
jt.add(b9);jt.add(b10);
this.add(jt,BorderLayout.NORTH);
}
public void method_3()//面板栏
//封装鼠标光标的类:指定为手型
{ Cursor mycursor=new Cursor(Cursor.HAND_CURSOR);
pa1=new JPanel();pa1.setLayout(new BorderLayout());
ImageIcon js1=new ImageIcon("images/jp1_bg.jpg");
Image tp1=js1.getImage();
huaban hb1=new huaban(tp1);
hb1.setLayout(new GridLayout(8,1));
hbx1=new JLabel(new ImageIcon("images/label_1.gif"));
hb1.add(hbx1);
hbx2=new JLabel("人事管理",new ImageIcon("images/label_2.jpg"),JLabel.LEFT);
hbx2.setEnabled(false);hbx2.setCursor(mycursor);hbx2.addMouseListener(this);
hbx2.setFont(myfont.f1);hb1.add(hbx2);
hbx3=new JLabel("登陆管理",new ImageIcon("images/label_3.jpg"),JLabel.LEFT);
hbx3.setEnabled(false);hbx3.setCursor(mycursor);hbx3.addMouseListener(this);
hbx3.setFont(myfont.f1);hb1.add(hbx3);
hbx4=new JLabel("菜谱价格",new ImageIcon("images/label_4.jpg"),JLabel.LEFT);
hbx4.setEnabled(false);hbx4.setCursor(mycursor);hbx4.addMouseListener(this);
hbx4.setFont(myfont.f1);hb1.add(hbx4);
hbx5=new JLabel("报表统计",new ImageIcon("images/label_5.jpg"),JLabel.LEFT);
hbx5.setCursor(mycursor);hbx5.setEnabled(false);hbx5.addMouseListener(this);
hbx5.setFont(myfont.f1);hb1.add(hbx5);
hbx6=new JLabel("成本及库房",new ImageIcon("images/label_6.jpg"),JLabel.LEFT);
hbx6.setEnabled(false);hbx6.setCursor(mycursor);hbx6.addMouseListener(this);
hbx6.setFont(myfont.f1);hb1.add(hbx6);
hbx7=new JLabel("系统设置",new ImageIcon("images/label_7.jpg"),JLabel.LEFT);
hbx7.setCursor(mycursor);hbx7.setEnabled(false);hbx7.addMouseListener(this);
hbx7.setFont(myfont.f1);hb1.add(hbx7);
hbx8=new JLabel("动画帮助",new ImageIcon("images/label_8.jpg"),JLabel.LEFT);
hbx8.setEnabled(false);hbx8.setCursor(mycursor);hbx8.addMouseListener(this);
hbx8.setFont(myfont.f1);hb1.add(hbx8);
pa1.add(hb1);





pa2=new JPanel(new BorderLayout());
card1=new CardLayout();
pa2x1=new JPanel(card1);
pa2x1_1=new JLabel(new ImageIcon("images/jp2_left.jpg"));
pa2x1_2=new JLabel(new ImageIcon("images/jp2_right.jpg"));
pa2x1.add(pa2x1_1,"0");pa2x1.add(pa2x1_2,"1");
pa2.add(pa2x1,BorderLayout.WEST);

card2=new CardLayout();
pa2x2=new JPanel(card2);
p2x2_1=new JLabel(new ImageIcon("images/jp3_1.jpg"));
pa2x2_1=new JPanel();pa2x2_1.add(p2x2_1);
p2x2_2=new JLabel(new ImageIcon("images/jp3_2.jpg"));
pa2x2_2=new JPanel();pa2x2_2.add(p2x2_2);
p2x2_3=new JLabel(new ImageIcon("images/jp3_3.jpg"));
pa2x2_3=new JPanel();pa2x2_3.add(p2x2_3);
p2x2_4=new JLabel(new ImageIcon("images/jp3_4.jpg"));
pa2x2_4=new JPanel();pa2x2_4.add(p2x2_4);
p2x2_5=new JLabel(new ImageIcon("images/jp3_5.jpg"));
pa2x2_5=new JPanel();pa2x2_5.add(p2x2_5);
p2x2_6=new JLabel(new ImageIcon("images/jp3_6.jpg"));
pa2x2_6=new JPanel();pa2x2_6.add(p2x2_6);
p2x2_7=new JLabel(new ImageIcon("images/jp3_7.jpg"));
pa2x2_7=new JPanel();pa2x2_7.add(p2x2_7);
pa2x2.add(pa2x2_1,"0");pa2x2.add(pa2x2_2,"1");pa2x2.add(pa2x2_3,"2");
pa2x2.add(pa2x2_4,"3");pa2x2.add(pa2x2_5,"4");pa2x2.add(pa2x2_6,"5");
pa2x2.add(pa2x2_7,"6");
pa2.add(pa2x2,BorderLayout.CENTER);








jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,pa1,pa2);
jsp.setDividerLocation(150);
jsp.setDividerSize(0);
this.add(jsp,BorderLayout.CENTER);
}



public void mouseClicked(MouseEvent e){
if(e.getSource()==hbx2){
this.card2.show(pa2x2,"0");
}else if(e.getSource()==hbx3){
card2.show(pa2x2, "1");
}else if(e.getSource()==hbx4){
card2.show(pa2x2, "2");
}else if(e.getSource()==hbx5){
card2.show(pa2x2, "3");
}else if(e.getSource()==hbx6){
card2.show(pa2x2,"4");
}else if(e.getSource()==hbx7){
card2.show(pa2x2, "5");
}else if(e.getSource()==hbx8){
card2.show(pa2x2, "6");
}
}
public void mouseEntered(MouseEvent e){
if(e.getSource()==hbx2){
hbx2.setEnabled(true);
}else if(e.getSource()==hbx3){
hbx3.setEnabled(true);
}else if(e.getSource()==hbx4){
hbx4.setEnabled(true);
}else if(e.getSource()==hbx5){
hbx5.setEnabled(true);
}else if(e.getSource()==hbx6){
hbx6.setEnabled(true);
}else if(e.getSource()==hbx7){
hbx7.setEnabled(true);
}else if(e.getSource()==hbx8){
hbx8.setEnabled(true);
}
}
public void mouseExited(MouseEvent e) {
if(e.getSource()==hbx2){
hbx2.setEnabled(false);
}else if(e.getSource()==hbx3){
hbx3.setEnabled(false);
}else if(e.getSource()==hbx4){
hbx4.setEnabled(false);
}else if(e.getSource()==hbx5){
hbx5.setEnabled(false);
}else if(e.getSource()==hbx6){
hbx6.setEnabled(false);
}else if(e.getSource()==hbx7){
hbx7.setEnabled(false);
}else if(e.getSource()==hbx8){
hbx8.setEnabled(false);
}
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}

}

}

验证账号密码错误的代码:链接类,通过这个类可以图形化界面与数据库之间有一个传递。

package cy_model;
import java.sql.*;
import cy_database.*;
public class moxing {
ResultSet rs=null;
shujuku sj=null;
String zhiwei="";
public String yanzheng(String a,String b){
try{
String sql="select zhiwei from xinxi aa,bumen bb where aa.zhanghao=bb.zhanghao and bb.zhanghao=? and bb.mima=?";
String[] arr={a,b};
sj=new shujuku();
rs=sj.fanhui(sql,arr);
if(rs.next()){

//在这里看的是这个账号密码对应的有没有职位是普通员工还是经理

//普通员工的登陆进来以后的界面功能可能比较少,如果是领导级的功能可能比较多

//在这里没有实现,只是看有没有职位,有的话就允许进入。
zhiwei=rs.getString(1);}
}

catch(Exception e){}
finally{
sj.close();
}
return zhiwei;
}

}

链接数据库的类:

package cy_database;
import java.sql.*;
public class shujuku {
Connection ct=null;
PreparedStatement ps=null;
ResultSet rs=null;
String un="sa";
String mm="qichang";
String qudong="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String wufuqi="jdbc:sqlserver://2012-20111117YN:1433;DatabaseName=company";
public shujuku(){
try{
Class.forName(qudong);
ct=DriverManager.getConnection(wufuqi,un,mm);
}
catch(Exception e){}

}
public ResultSet fanhui(String sql ,String[] arr){//接收链接类传递的sql语句以及账号密码
try{
ps=ct.prepareStatement(sql);
for(int i=0;i<arr.length;i++){
ps.setString(i+1,arr[i]);
}
rs=ps.executeQuery();
}
catch(Exception e){
System.out.println(e.toString());
}
return rs;//不管有或者没有返回RsultSet对象让链接类获取结果。
}



public void close(){
try{
if(ct!=null){
ct.close();
}if(ps!=null){
ps.close();
}if(rs!=null){
rs.close();
}
}
catch(Exception e){}
}
}




  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java项目package project.action.dialogAction; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; import project.dao.common.DbException; import project.dao.dataDao.LoginInfoDao; import project.dao.dataDaoImpl.LoginInfoDaoImpl; import project.view.dialog.AddLoginInfoDialog; import project.vo.LoginInfoVo; /** * 添加登录账号action * * @author Administrator * */ public class AddLoginInfoAction implements ActionListener { private AddLoginInfoDialog dialog; public AddLoginInfoAction(AddLoginInfoDialog dialog) { this.dialog = dialog; } public void actionPerformed(ActionEvent e) { String name = e.getActionCommand(); if (name.equals("确定")) { // 检验输入是否正确 if (dialog.checkInputValue()) { LoginInfoDao dao = null; LoginInfoVo vo = null; try { // 获得界面输入信息 vo = dialog.getInputInfo(); String confirm = dialog.getConfirm(); if (vo.getLog_pwd().equals(confirm)) { dao = new LoginInfoDaoImpl(); if (dao.insertLoginInfo(vo)) { // 打印提示信息 JOptionPane.showMessageDialog(null, "添加登录人员成功", "提示信息", JOptionPane.YES_OPTION); dialog.dispose(); } else { // 打印提示信息 JOptionPane.showMessageDialog(null, "添加登录人员失败", "提示信息", JOptionPane.YES_OPTION); } } else { // 如果密码确认输入错误,打印提示信息 JOptionPane.showMessageDialog(null, "密码确认错误,请重新输入", "提示信息", JOptionPane.YES_OPTION); } } catch (DbException ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "提示信息", JOptionPane.YES_OPTION); } } else { JOptionPane.showMessageDialog(null, "请确认输入是否完整正确", "提示信息", JOptionPane.YES_OPTION); } } else if (name.equals("取消")) { dialog.dispose(); } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值