package com.mol.view;
import javax.swing.*;
import javax.swing.Timer;
import com.mol.tools.ImagePanel;
import com.mol.tools.MyTools;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.*;
public class Windows1 extends JFrame implements ActionListener{
//定义所需要的组件
Image titelImage,timeBg;
//工具栏的图标
ImageIcon imageIcom1,imageIcom2,imageIcom3,imageIcom4,imageIcom5,imageIcom6,imageIcom7,
imageIcom8,imageIcom9,imageIcom10;
JMenuBar jmb;
//一级菜单
JMenu jm1,jm2,jm3,jm4,jm5,jm6;
//二级菜单
JMenuItem jmm1,jmm2,jmm3,jmm4,jmm5,jmm6,jmm7,jmm8,jmm9,jmm10,jmm11,jmm12;
//创建图标
ImageIcon jmm1_image;
//创建工具栏
JToolBar jtb;
JButton jb1, jb2, jb3, jb4, jb5, jb6, jb7, jb8,jb9, jb10;
JPanel jp1,jp2,jp3,jp4,jp5;
JLabel nowtime;
//Timer类实现时间的实时变化
javax.swing.Timer t;
public static void main(String[] args) {
Windows1 w = new Windows1();
}
public Windows1() {
//创建组件
try {
titelImage = ImageIO.read(new File("image/titelImage.jpg"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//初始化图标
jmm1_image = new ImageIcon("image/jt2.jpg");
int w = Toolkit.getDefaultToolkit().getScreenSize().width;
int h = Toolkit.getDefaultToolkit().getScreenSize().height;
//创建一级菜单
jm1 = new JMenu("系统管理");
jm1.setFont(MyTools.f1);
//创建二级菜单,添加图标
jmm1 = new JMenuItem("切换用户",jmm1_image);
jmm1.setFont(MyTools.f2);
jmm2 = new JMenuItem("切换到收款界面");
jmm2.setFont(MyTools.f2);
jmm3 = new JMenuItem("登陆管理");
jmm3.setFont(MyTools.f2);
jmm4 = new JMenuItem("万年历");
jmm4.setFont(MyTools.f2);
jmm5 = new JMenuItem("退出");
jmm5.setFont(MyTools.f2);
//添加二级菜单
jm1.add(jmm1);
jm1.add(jmm2);
jm1.add(jmm3);
jm1.add(jmm4);
jm1.add(jmm5);
jm2 = new JMenu("人事管理");
jmm6 = new JMenuItem("添加成员");
jmm7 = new JMenuItem("删除成员");
jmm8 = new JMenuItem("修改权限");
jmm9 = new JMenuItem("入职时间");
jmm10 = new JMenuItem("晋升机制");
jm2.add(jmm6);
jm2.add(jmm7);
jm2.add(jmm8);
jm2.add(jmm9);
jm2.add(jmm10);
jm3 = new JMenu("菜单服务");
jm4 = new JMenu("报表统计");
jm5 = new JMenu("成本及库房");
jm6 = new JMenu("帮助");
//创建菜单栏
jmb = new JMenuBar();
//添加到Jmenubar
jmb.add(jm1);
jmb.add(jm2);
jmb.add(jm3);
jmb.add(jm4);
jmb.add(jm5);
jmb.add(jm6);
//添加到JFrame
this.setJMenuBar(jmb);
//创建工具栏的图标........
imageIcom1 = new ImageIcon("image/jt1.jpg");
jtb = new JToolBar();
//禁止菜单栏浮动
jtb.setFloatable(false);
//添加图标到按钮里
jb1 = new JButton(imageIcom1);
jtb.add(jb1);
//设置最底栏的时间
jp5 = new JPanel();
jp5.setLayout(new BorderLayout());
try {
timeBg = ImageIO.read(new File("image/bj.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//获取container
Container ct=this.getContentPane();
ct.add(jtb, "North");
ct.add(jp5,"South");
//把图片放进去
ImagePanel ip1 = new ImagePanel(timeBg);
//把jlable nowtime 放进去
ip1.setLayout(new BorderLayout());
jp5.add(ip1);
//一秒触发一次
t = new Timer(1000, this);
t.start();
nowtime = new JLabel(Calendar.getInstance().getTime().toString());
ip1.add(nowtime,"East");
//设置大小
this.setSize(h,w-25);
//把图片加入进去
this.setIconImage(titelImage);
this.setTitle("我的练习项目");
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
this.nowtime.setText(Calendar.getInstance().getTime().toString());
}
}