[韩顺平]Java从入门到精通满汉楼系统代码(自己整理)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

view/UserLogin.java

package com.class76.view;

//插入自定义包
import erModel;
import com.class76.tool.*;
//插入类包
import javax.swing.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;

public class UserLogin extends JDialog implements ActionListener{

//定义需要的组件
JLabel jl1,jl2,jl3;
JTextField jtf1;
JPasswordField jpf;
JButton jcon,jcancel;

public static void main(String[] args) {
// TODO Auto-generated method stub
UserLogin ul=new UserLogin();
}

public UserLogin()
{
Container ct=this.getContentPane();
//做成空布局,不用之前的布局方式。
this.setLayout(null);

//创建各个组件
jl1=new JLabel("请输入用户名:");
//设置组件位置
jl1.setBounds(60, 190, 150, 30);
//设置组件上面字体
jl1.setFont(FontTool.f1);
//将组件添加至容器
ct.add(jl1);

jtf1=new JTextField();
jtf1.setBounds(170, 190, 130, 30);
//设置下陷感觉
jtf1.setBorder(BorderFactory.createLoweredBevelBorder());
ct.add(jtf1);

jl2=new JLabel("(或员工号)");
jl2.setBounds(100, 210, 100, 30);
jl2.setFont(FontTool.f2);
//设置前景色
jl2.setForeground(Color.red);
ct.add(jl2);

jl3=new JLabel("请输入密 码:");
jl3.setBounds(60, 230, 150, 30);
jl3.setFont(FontTool.f1);
ct.add(jl3);

jpf=new JPasswordField(20);
jpf.setBounds(170, 230, 130, 30);
jpf.setBorder(BorderFactory.createLoweredBevelBorder());
ct.add(jpf);

jcon=new JButton("确定");
jcon.addActionListener(this);
jcon.setFont(FontTool.f1);
jcon.setBounds(110, 300, 70, 30);
ct.add(jcon);

jcancel=new JButton("取消");
jcancel.addActionListener(this);
jcancel.setFont(FontTool.f1);
jcancel.setBounds(200, 300, 70, 30);
ct.add(jcancel);



//创建一个BackImage类
BackImage bi=new BackImage();
//把图片位置确定
bi.setBounds(0, 0, 360, 360);

//添加组件
//this.add(bi);
//把一个组件放入到JFrame或者JDialog中可以直接放入,也可以这样做
//Container ct=this.getContentPane();
//ct.add(bi);

ct.add(bi);

//不使用上下框
this.setUndecorated(true);
this.setSize(360,360);
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(width/2-200, height/2-150);
this.setVisible(true);
}

//内部类
class BackImage extends JPanel
{
Image im;
//构造函数
public BackImage()
{
try {
im=ImageIO.read(new File("image/index\\login.gif"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
public void paintComponent(Graphics g)
{
g.drawImage(im, 0, 0, 360, 360, this);

}
}

//响应用户登录的

请求
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource()==jcon)
{

//取出员工号和密码
String u=this.jtf1.getText().trim();
String p=new String(this.jpf.getPassword());
UserModel ul=new UserModel();
String res=ul.checkUser(u, p);
if(res.equals("主管"))
{
new Window1();
//关闭界面
this.dispose();
}

}else if(arg0.getSource()==jcancel)
{
this.dispose();
}

}
}


view/Index.java

/**
* 用户登录的闪屏效果
*
*/
package com.class76.view;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//
//import javax.swing.event.*;
//import javax.swing.border.*;
//


public class Index extends JWindow implements Runnable{

/**
* @param args
*/
paintcomponent1 p;

public static void main(String[] args) {
// TODO Auto-generated method stub
Index index=new Index();
Thread t=new Thread(index);
t.start();
}

public Index()
{
//创建P
p=new paintcomponent1();
this.add(p);

this.setSize(400,250);
//确定Jwindow初始位置
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(width/2-200, height/2-150);
this.setVisible(true);
}

public void run() {
// TODO Auto-generated method stub
while(true)
{
//根据计算等待闪屏效果结束后,再跳转到登陆界面
try {
Thread.sleep(30*500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//跳转到登陆界面
System.out.println("闪屏结束");
System.exit(0);
this.dispose();
break;
}
}
}

//开发闪屏类
class paintcomponent1 extends JPanel implements Runnable
{
Thread t;
int x=10;
int i=0,j=40,u=10;
String gg[]={"系","统","正","在","加","载",",请","稍","候"};
int k=0,tt=0;
String shi[]={"满","汉","楼","融","满","汉","精","华","做","天"
,"下","美","味","系","统","正","在","加","载",",请","稍","候"};
Font f=new Font("隶书",Font.PLAIN,18);

boolean ifok=true;
int width=180;
int heigh=0;
int dian=0;


paintcomponent1()
{
t=new Thread(this);
t.start();

}

public void run()
{
// TODO Auto-generated method stub
while(true)
{
if(x<=380) repaint();

try {
Thread.sleep(70);
i++;
j=j-6;
u=u+10;

if(tt==3) width=width-20;

if(i==4)
{
tt++;
if(ifok&&x>120+k*20) k++;
if(k>=gg.length-1) ifok=false;
x=x+10;
i=0;
j=40;
u=10;
dian++;
if(dian>3) dian=0;
}

} catch (InterruptedException e) {
// TODO: handle exception
//e.printStackTrace();
System.out.println("线程中断");
}

}

}

public void paint(Graphi

cs g)
{
//super.paintComponent(g);
super.paint(g);

Image image;
image=Toolkit.getDefaultToolkit().getImage("image/index/index.jpg");
g.drawImage(image, 0, 0, this.getWidth(), 200, this);

int r=(int)(Math.random()*255);
int b=(int)(Math.random()*255);
int y=(int)(Math.random()*255);

g.setColor(new Color(253,250,250));
g.fillRect(x, 210, 390-x, 30);
g.setColor(new Color(253,250,250));
if(i>1) g.fillRect(x, 255-(j+20)/2, 10, j+20);
if(j>25) g.setColor(new Color(r, b, y));
else g.setColor(new Color(123, 194, 252));
g.fillRect(x, 255-(j+20)/2, 10, j);
g.setColor(new Color(123,194,252));
g.drawRect(10, 210, 380, 30);

if(x<120)
{
for(int l=0;l{
g.setColor(new Color(0,0,0));
g.drawString(gg[l], 120+l*20, 230);
}
for(int l=0;l{
g.setColor(new Color(0,0,0));
g.drawString("*", 300+l*10, 235);
}
g.drawString("*", 300+10*dian, 235);
}
else
{
g.setColor(new Color(23,23,230));
g.drawString(gg[k], 120+k*20, 230);
for(int l=k+1;l{
g.setColor(new Color(0,0,0));
g.drawString(gg[l], 120+l*20, 230);
}
if(x>300+dian*10) g.setColor(new Color(23,23,230));
for(int l=0;l{
g.drawString("*", 300+l*10, 235);
}
g.drawString("*", 300+10*dian, 235);
}

//逐字写诗
if(tt<3)
{
for(int rr=0;rr<=tt;rr++)
{
g.setColor(new Color(r,b,y));
g.drawString(shi[rr], 180, 60+rr*20);
}
g.drawString(shi[tt], 180, 60+tt*20);
}

if(tt>=3&&tt<7)
{
g.setColor(new Color(230,0,0));
for(int rr=0;rr<3;rr++) g.drawString(shi[rr], 180, 60+rr*20);
g.setColor(new Color(r,b,y));

if(tt<8) for(int rr=3;rr<=tt;rr++) g.drawString(shi[rr], 150, rr*20);
if(tt>=7) for(int rr=3;rr<8;rr++) g.drawString(shi[rr], 150, rr*20);
}
if(tt>=7&&tt<13)
{
g.setColor(new Color(230,0,0));
for(int rr=0;rr<3;rr++) g.drawString(shi[rr], 180, 60+rr*20);
for(int rr=3;rr<=7;rr++) g.drawString(shi[rr], 150, rr*20-20);
g.setColor(new Color(r,b,y));
if(tt<13) for(int rr=8;rr<=tt;rr++) g.drawString(shi[rr], 120, rr*20);
if(tt>=13) for(int rr=8;rr<13;rr++) g.drawString(shi[rr], 120, rr*20);

}
if(tt>=13&&tt<18)
{
g.setColor(new Color(230,0,0));
for(int rr=0;rr<3;rr++) g.drawString(shi[rr], 180, 60+rr*20);
for(int rr=3;rr<=7;rr++) g.drawString(shi[rr], 150, rr*20-20);
for(int rr=8;rr<13;rr++) g.drawString(shi[rr], 120, rr*20-120);
g.setColor(new Color(r,b,y));
if(tt<18) for(int rr=13;rr<=tt;rr++) g.drawString(shi[rr], 90, rr*20);
if(tt>=18) for(int rr=13;rr<13;rr++) g.drawString(shi[rr], 90, rr*20);

}
if(tt>=18&&tt<23)
{
g.setColor(new Color(230,0,0));
for(int rr=0;rr<3;rr++) g.drawString(shi[rr], 180, 60+rr*20);
for(int rr=3;rr<=7;rr++) g.drawString(shi[rr], 150, rr*20-20);
for(int rr=8;rr<13;rr++) g.drawStrin

g(shi[rr], 120, rr*20-120);
for(int rr=13;rr<18;rr++) g.drawString(shi[rr], 90, rr*20-220);
g.setColor(new Color(r,b,y));
if(tt<23) for(int rr=18;rr<=tt;rr++) g.drawString(shi[rr], 60, rr*20);
if(tt>=23) for(int rr=18;rr<23;rr++) g.drawString(shi[rr], 60, rr*20);
}
if(tt>=23&&tt<30)
{
g.setColor(new Color(230,0,0));
for(int rr=0;rr<3;rr++) g.drawString(shi[rr], 180, 60+rr*20);
for(int rr=3;rr<=7;rr++) g.drawString(shi[rr], 150, rr*20-20);
for(int rr=8;rr<13;rr++) g.drawString(shi[rr], 120, rr*20-120);
for(int rr=13;rr<18;rr++) g.drawString(shi[rr], 90, rr*20-220);
for(int rr=18;rr<23;rr++) g.drawString(shi[rr], 60, rr*20-320);
g.setColor(new Color(r,b,y));
if(tt<30) for(int rr=23;rr<=tt;rr++) g.drawString(shi[rr], 30, rr*20);
if(tt>=30) for(int rr=18;rr<23;rr++) g.drawString(shi[rr], 30, rr*20);
}
if(tt>=30)
{
g.setColor(new Color(230,0,0));
for(int rr=0;rr<3;rr++) g.drawString(shi[rr], 180, 60+rr*20);
for(int rr=3;rr<=7;rr++) g.drawString(shi[rr], 150, rr*20-20);
for(int rr=8;rr<13;rr++) g.drawString(shi[rr], 120, rr*20-120);
for(int rr=13;rr<18;rr++) g.drawString(shi[rr], 90, rr*20-220);
for(int rr=18;rr<23;rr++) g.drawString(shi[rr], 60, rr*20-320);
for(int rr=23;rr<30;rr++) g.drawString(shi[rr], 30, rr*20-400);
}
}

}


view/Window1.java

/**
* 这是系统管理员、经理和主管可以进入的界面
* 完成界面顺序,从上到下,从左到右。
*/
package com.class76.view;

import com.class76.tool.*;
import javax.swing.*;
import javax.swing.Timer;

import java.awt.*;
import java.awt.event.*;

import javax.imageio.*;
import java.io.*;
//用于显示当前时间
import java.util.*;

import com.class76.tool.*;

public class Window1 extends JFrame implements ActionListener{

//定义变量
//图标
Image titleImage,timebg;
//主菜单
JMenuBar jmb;
//一级菜单
JMenu jm1,jm2,jm3,jm4,jm5,jm6;
//二级菜单
JMenuItem jmm1,jmm2,jmm3,jmm4,jmm5;
//菜单图标
ImageIcon jmm1_icon,jmm2_icon,jmm3_icon,jmm4_icon,jmm5_icon;

//创建工具栏
JToolBar jtb;
JButton jb1,jb2,jb3,jb4,jb5,jb6,jb7,jb8,jb9,jb10;

//定义需要的5个面板
JPanel p1,p2,p3,p4,p5;
//显示状态栏上当前时间
JLabel timeNow;

//javax.swing包中的timer类可以定时的出发ACTION事件
//因此可利用它完成获取实时时间,并显示。
javax.swing.Timer t;

//创建Image面板用于p1
ImagePanel p1_imgPanel;
JLabel p1_lab1,p1_lab2,p1_lab3,p1_lab4,p1_lab5,p1_lab6,p1_lab7,p1_lab8;
//p1背景图片
Image p1_bg = null;
//给p2面板定义需要的lable
JLabel p2_lab1,p2_lab2;

//p3背景图片
Image zhu_image=null;

JSplitPane jsp1;


public static void main(String[] args) {
// TODO Auto-generated method stub
Window1 w1=new Window1();
}

public Window1()
{
//创建组件

//图标、title
//引入图标照片,

需插入java.io.*
try {
titleImage=ImageIO.read(new File("image/index/title.gif"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//设置窗体图标
this.setIconImage(titleImage);
//设置title
this.setTitle("满汉楼餐饮管理系统");

//菜单栏
//创建一级菜单
jm1=new JMenu("系统管理");
//设置一级菜单字体
jm1.setFont(FontTool.f1);
//创建二级菜单图标
jmm1_icon=new ImageIcon("image/menu_image/jmm1_icon.jpg");
jmm2_icon=new ImageIcon("image/menu_image/jmm2_icon.jpg");
jmm3_icon=new ImageIcon("image/menu_image/jmm3_icon.jpg");
jmm4_icon=new ImageIcon("image/menu_image/jmm4_icon.jpg");
jmm5_icon=new ImageIcon("image/menu_image/jmm5_icon.jpg");
//创建二级菜单,并添加图标(就近原则,这样接着写可提高代码可读性)
jmm1=new JMenuItem("切换用户",jmm1_icon);
jmm2=new JMenuItem("切换到收款界面",jmm2_icon);
jmm3=new JMenuItem("登录管理",jmm3_icon);
jmm4=new JMenuItem("万年历",jmm4_icon);
jmm5=new JMenuItem("退出",jmm5_icon);
//设置二级菜单字体
jmm1.setFont(FontTool.f2);
jmm2.setFont(FontTool.f2);
jmm3.setFont(FontTool.f2);
jmm4.setFont(FontTool.f2);
jmm5.setFont(FontTool.f2);
//加入至一级菜单
jm1.add(jmm1);
jm1.add(jmm2);
jm1.add(jmm3);
jm1.add(jmm4);
jm1.add(jmm5);

jm2=new JMenu("人事管理");
jm2.setFont(FontTool.f1);
jm3=new JMenu("菜单服务");
jm3.setFont(FontTool.f1);
jm4=new JMenu("报表统计");
jm4.setFont(FontTool.f1);
jm5=new JMenu("成本及库房");
jm5.setFont(FontTool.f1);
jm6=new JMenu("帮助");
jm6.setFont(FontTool.f1);

//把一级菜单加入到主菜单中
jmb=new JMenuBar();
jmb.add(jm1);
jmb.add(jm2);
jmb.add(jm3);
jmb.add(jm4);
jmb.add(jm5);
jmb.add(jm6);

//将菜单添加至Frame中
this.setJMenuBar(jmb);

//工具栏

//处理工具栏组件
jtb=new JToolBar();
//设置工具栏是否可以浮动
jtb.setFloatable(false);
//创建工具栏按钮+图标
jb1=new JButton(new ImageIcon("image/toolBar_image/jb1.jpg"));
jb2=new JButton(new ImageIcon("image/toolBar_image/jb2.jpg"));
jb3=new JButton(new ImageIcon("image/toolBar_image/jb3.jpg"));
jb4=new JButton(new ImageIcon("image/toolBar_image/jb4.jpg"));
jb5=new JButton(new ImageIcon("image/toolBar_image/jb5.jpg"));
jb6=new JButton(new ImageIcon("image/toolBar_image/jb6.jpg"));
jb7=new JButton(new ImageIcon("image/toolBar_image/jb7.jpg"));
jb8=new JButton(new ImageIcon("image/toolBar_image/jb8.jpg"));
jb9=new JButton(new ImageIcon("image/toolBar_image/jb9.jpg"));
jb10=new JButton(new ImageIcon("image/toolBar_image/jb10.jpg"));
//把按钮加入到jtb
jtb.add(jb1);
jtb.add(jb2);
jtb.add(jb3);
jtb.add(jb4);
jtb.add(jb5);
jtb.add(jb6);
jtb.add(jb7);
jtb.add(jb8)

;
jtb.add(jb9);
jtb.add(jb10);

//从JFrame中取得container,不直接用this.add(jtb,"north"),防止出现小问题
Container ct=this.getContentPane();
ct.add(jtb,"North");



//处理P1面板
p1=new JPanel(new BorderLayout());

try {
p1_bg = ImageIO.read(new File("image/center_image/jp1_bg.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.p1_imgPanel=new ImagePanel(p1_bg);
//设置p1_imgPanel的布局
this.p1_imgPanel.setLayout(new GridLayout(8,1));
//设置p1_lab1...的格式及背景图
p1_lab1=new JLabel(new ImageIcon("image/center_image/label_1.gif"));
p1_lab2=new JLabel("人 事 管 理",new ImageIcon("image/center_image/label_2.jpg"),0);
p1_lab3=new JLabel("人 事 管 理",new ImageIcon("image/center_image/label_3.jpg"),0);
p1_lab4=new JLabel("菜 谱 价 格",new ImageIcon("image/center_image/label_4.jpg"),0);
p1_lab5=new JLabel("报 表 统 计",new ImageIcon("image/center_image/label_5.jpg"),0);
p1_lab6=new JLabel("成本及库房",new ImageIcon("image/center_image/label_6.jpg"),0);
p1_lab7=new JLabel("系 统 设 置",new ImageIcon("image/center_image/label_7.jpg"),0);
p1_lab8=new JLabel("动 态 帮 助",new ImageIcon("image/center_image/label_8.jpg"),0);
//设置p1_lab...上的字体
p1_lab1.setFont(FontTool.f2);
p1_lab2.setFont(FontTool.f2);
p1_lab3.setFont(FontTool.f2);
p1_lab4.setFont(FontTool.f2);
p1_lab5.setFont(FontTool.f2);
p1_lab6.setFont(FontTool.f2);
p1_lab7.setFont(FontTool.f2);
p1_lab8.setFont(FontTool.f2);
//在p1_imgPanel中按GridLayout布局添加p1_lab1...
p1_imgPanel.add(p1_lab1);
p1_imgPanel.add(p1_lab2);
p1_imgPanel.add(p1_lab3);
p1_imgPanel.add(p1_lab4);
p1_imgPanel.add(p1_lab5);
p1_imgPanel.add(p1_lab6);
p1_imgPanel.add(p1_lab7);
p1_imgPanel.add(p1_lab8);
p1.add(this.p1_imgPanel);
//设置拆分窗口后,不是添加p1,而是添加p1所在的jsp1
//ct.add(p1,"Center");



//处理p2,p3,p4
p4=new JPanel(new BorderLayout());
//p2为卡片布局
p2=new JPanel(new CardLayout());
//给p2_lab1,p2_lab2设背景图片
p2_lab1=new JLabel(new ImageIcon("image/center_image/jp2_left.jpg"));
p2_lab2=new JLabel(new ImageIcon("image/center_image/jp2_right.jpg"));
//添加至P2面板中,“0”,“1”是给卡片的编号
p2.add(p2_lab1,"0");
p2.add(p2_lab2,"1");
//p3为卡片布局
p3=new JPanel(new CardLayout());
//先给p3加入主界面的卡片(imagepanel)

try {
zhu_image = ImageIO.read(new File("image/center_image/jp3_bg.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ImagePanel ip=new ImagePanel(zhu_image);
p3.add(ip,"0");
//



//把p2和p3加入到p4
p4.add(p2,"West");
p4.add(p3,"Center");

//做一个拆分窗口,分别存放p1和p4
jsp1=new JSplitPane(

JSplitPane.HORIZONTAL_SPLIT,true,p1,p4);
//指定左边的面板占多大的范围
jsp1.setDividerLocation(130);
//把边界线设为0
jsp1.setDividerSize(0);

//加入到JFrame中
ct.add(jsp1,"Center");

//状态栏
//先处理p5状态栏面板,如果只用p5=new JPanel(),就会只显示时间背景的一点点,不会是一整条。
p5=new JPanel(new BorderLayout());
//创建Timer,每隔一秒去出发ActionEvent
t=new Timer(1000,this);
//启动定时器
t.start();
//获取当前系统时间
//timeNow=new JLabel(Calendar.getInstance().getTime().toString());
timeNow=new JLabel(Calendar.getInstance().getTime().toLocaleString());
timeNow.setFont(FontTool.f2);
//加载时间图片背景
try {
timebg=ImageIO.read(new File("image/time_bg.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

ImagePanel ip1=new ImagePanel(timebg);
ip1.setLayout(new BorderLayout());
ip1.add(timeNow,"East");


//将时间添加至P5状态栏
p5.add(ip1);
//将p5状态栏添加至Jframe
ct.add(p5,"South");


//设置窗体大小
int w=Toolkit.getDefaultToolkit().getScreenSize().width;
int h=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setSize(w,h-25);
this.setVisible(true);

//设置关闭窗口时退出程序
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
//this.timeNow.setText(Calendar.getInstance().getTime().toString());
this.timeNow.setText("当前时间:"+Calendar.getInstance().getTime().toLocaleString());
}

}


db/SqlHelper.java

/**
* 对数据库操作的类
* 对数据库的操作,就是crud(增删改查)
* 调用存储过程(后话)
*/
package com.class76.db;

import java.sql.*;
import java.util.*;

public class SqlHelper {

//定义需要的对象
PreparedStatement ps=null;
ResultSet rs=null;
Connection ct=null;

String driverName="com.ibm.db2.jcc.DB2Driver";
String url="jdbc:db2://localhost:50000/RESTAURT";
String user="lenovo";
String passwd="90";

//构造函数,初始化ct
public SqlHelper()
{
try {
Class.forName(driverName);
ct = DriverManager.getConnection(url, user, passwd);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}


}

//查询
public ResultSet query(String sql,String[] paras)
{
try {
ps=ct.prepareStatement(sql);
//对sql参数赋值
for(int i=0;i{
ps.setString(i+1, paras[i]);
}
rs=ps.executeQuery();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return rs;
}

//关闭资源
public void close()
{
try {
if(rs!=null) rs.close();
if(ps!=null) ps.close();
if(ct!=null) ct.close();
} catch (Exce

ption e) {
// TODO: handle exception
e.printStackTrace();
}
}
}


model/UserModel.java


/**
* 用户表数据模型,用于完成对用户的各种操作。
* 主要编写项目需要的业务操作。
*/
package com.class76.model;

import java.sql.*;

import com.class76.db.SqlHelper;

public class UserModel {
/**
*
* @param uid 用户编号
* @param p 用户密码
* @return 该用户的职位,如果用户不存在,则返回“”
*/


//查询输入用户是否存在,密码是否正确,职位是否为主管、经理等
public String checkUser(String uid,String p)
{
String zhiwei="";
SqlHelper sp=null;
try {

//组织sql语句和参数
String sql="select c.cleZw from login l,clerkinfo c where l.cleId =c.cleId and l.cleId=? and l.passwd =?";
String[] paras={uid,p};
sp=new SqlHelper();
ResultSet rs=sp.query(sql,paras);
if(rs.next())
{
//取出职位
zhiwei=rs.getString(1);
}else{
zhiwei="kong";
}

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally
{
sp.close();
}

return zhiwei;
}


}


tool/FontTool.java

package com.class76.tool;

import java.awt.Font;

public class FontTool {
public static Font f1=new Font("宋体",Font.PLAIN,16);
public static Font f2=new Font("宋体",Font.PLAIN,12);
public static Font f3=new Font("宋体",Font.PLAIN,10);
}


tool/ImagePanel.java

/**
* 这是一个可以动态加载一个图片做背景的JPanel
*
*/
package com.class76.tool;

import javax.swing.*;
import javax.imageio.*;
import java.awt.*;

public class ImagePanel extends JPanel{

Image im;

//构造函数去指定该JPanel大小
public ImagePanel(Image im)
{
this.im=im;
//希望它大小自适应
int w=Toolkit.getDefaultToolkit().getScreenSize().width;
int h=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setSize(w,h);

}

//画出背景,paintComponent用于画组件的
public void paintComponent(Graphics g)
{
//清屏
super.paintComponents(g);
g.drawImage(im, 0, 0, this.getWidth(), this.getHeight(), this);
}

}


相关文档
最新文档