⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainpanel.java

📁 我做的第一个java MIS项目
💻 JAVA
字号:
package client;

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

import client.Welcomepanel;
import sun.awt.resources.awt;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import server.io.Userio;
import java.io.*;
//主模块
public class Mainpanel extends JFrame{
    //组件定义
        //工具栏容器
        FlowLayout flowLayout1 = new FlowLayout();
        JPanel toolspanel=new JPanel(flowLayout1);
        //工具栏图形按钮
        JLabel tools1=new JLabel(new ImageIcon(".\\pic\\tools\\tools1.jpg"));
        JLabel tools2=new JLabel(new ImageIcon(".\\pic\\tools\\tools2.jpg"));
        JLabel tools3=new JLabel(new ImageIcon(".\\pic\\tools\\tools3.jpg"));
        JLabel tools4=new JLabel(new ImageIcon(".\\pic\\tools\\tools4.jpg"));
        JLabel tools5=new JLabel(new ImageIcon(".\\pic\\tools\\tools5.jpg"));
        JLabel tools6=new JLabel(new ImageIcon(".\\pic\\tools\\tools6.jpg"));
        JLabel tools7=new JLabel(new ImageIcon(".\\pic\\tools\\tools7.jpg"));

        //锁定容器
        JPanel Lock=new JPanel(null);
        JButton btnunlock = new JButton("解  锁");
        JPasswordField pwdf = new JPasswordField();
        JLabel txfinf = new JLabel();

        BorderLayout borderLayout1 = new BorderLayout();
        JLabel lockback = new JLabel();

        //设定面板标记
        int paneindex=1;

    public Mainpanel() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        //设置标题
        this.setTitle("音像租赁系统 V1.0");
        this.getContentPane().setLayout(borderLayout1);
        //设置主窗体
        this.setResizable(false);
        //设置工具栏
        toolspanel.setBackground(new Color(224,246,208));
        toolspanel.setBorder(BorderFactory.createEtchedBorder());
        tools1.addMouseListener(new Mainpanel_tools1_mouseAdapter(this));
        tools2.addMouseListener(new Mainpanel_tools2_mouseAdapter(this));
        tools3.addMouseListener(new Mainpanel_tools3_mouseAdapter(this));
        tools4.addMouseListener(new Mainpanel_tools4_mouseAdapter(this));
        tools6.addMouseListener(new Mainpanel_tools6_mouseAdapter(this));
        tools7.setToolTipText("详细帮助信息");
        tools7.setBounds(new Rectangle(242, 92, 75, 80));
        tools7.addMouseListener(new Mainpanel_tools7_mouseAdapter(this));
        tools6.setToolTipText("当您离开电脑时,通过锁定系统来保证信息安全");
        tools6.setBounds(new Rectangle(162, 92, 75, 80));
        tools4.setToolTipText("查询当天、当月、当年的借还统计和罚款统计");
        tools4.setText("");
        tools4.setBounds(new Rectangle(282, 7, 75, 80));
        btnunlock.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
        btnunlock.addActionListener(new Mainpanel_btnunlock_actionAdapter(this));
        pwdf.setToolTipText("回车解锁");
        pwdf.setText("");
        pwdf.setBounds(new Rectangle(283, 312, 179, 23));
        pwdf.addKeyListener(new Mainpanel_pwdf_keyAdapter(this));
        txfinf.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
        txfinf.setToolTipText("");
        txfinf.setText("请输入解锁密码:");
        txfinf.setBounds(new Rectangle(271, 275, 173, 19));
        lockback.setBounds(new Rectangle(0, 0, 796, 570));
        tools5.addMouseListener(new Mainpanel_tools5_mouseAdapter(this));
        tools1.setToolTipText("光碟租赁、归还操作");
        tools1.setText("");
        tools2.setToolTipText("对数据表的浏览和编辑操作");
        tools2.setText("");
        tools3.setToolTipText("会员卡查询,碟片查询,借还记录查询等操作");
        tools5.setToolTipText("系统设置选项、业务设置选项");

        //添加图标工具
        toolspanel.add(tools1);
        toolspanel.add(tools2);
        toolspanel.add(tools3);
        toolspanel.add(tools4);
        toolspanel.add(tools5);
        toolspanel.add(tools6);
        toolspanel.add(tools7);
        //解锁pnl
        Lock.setLayout(null);
        btnunlock.setBounds(new Rectangle(393, 357, 71, 23));
        btnunlock.setText("解  锁");
        Lock.add(txfinf);
        Lock.add(btnunlock);
        Lock.add(pwdf);
        Lock.add(lockback);
        lockback.setIcon(new ImageIcon(".\\pic\\lock\\lockback.jpg"));
        lockback.setBounds(0,0,796,570); //添加面板
        this.getContentPane().add(new Welcomepanel(),java.awt.BorderLayout.CENTER);
        this.getContentPane().add(toolspanel, java.awt.BorderLayout.NORTH);
    }

    //帮助信息按钮动作
    public void tools7_mouseClicked(MouseEvent e){
        //调用外部EXE
        try {Runtime.getRuntime().exec(".\\hlp\\mrshlp.exe");}
        catch (IOException ex) {}
    }
    //光碟管理按钮动作
    public void tools1_mouseClicked(MouseEvent e){
        if(paneindex!=2)
        {
            this.getContentPane().remove(0);
            this.getContentPane().add(new Cdmanage(),0);
            this.show();
            paneindex=2;
        }
    }
    //数据管理按钮动作
    public void tools2_mouseClicked(MouseEvent e){
        if(paneindex!=3)
        {
            //验证超级管理员密码
            String newpwd = "";
            try
            {newpwd = new JOptionPane().showInputDialog(this, "请输入密码","请输入管理员密码:", JOptionPane.INFORMATION_MESSAGE).trim();}
            catch (Exception ex) {System.out.println("操作员撤消输入。");}
            if (newpwd != null && !newpwd.equals("")) {
                if (!newpwd.equals(Userio.getsuperuserpwd()))
                {JOptionPane.showMessageDialog(this, "密码错误", "提示",JOptionPane.INFORMATION_MESSAGE);}
                else
                {
                    this.getContentPane().remove(0);
                    this.getContentPane().add(new Dbmanage(), 0);
                    this.show();
                    paneindex = 3;
                }
            }
        }
    }
    //业务统计按钮动作
    public void tools4_mouseClicked(MouseEvent e){
        if(paneindex!=4)
        {
            this.getContentPane().remove(0);
            this.getContentPane().add(new Businessstat(), 0);
            this.show();
            paneindex=4;
        }
    }
    //数据查询按钮动作
    public void tools3_mouseClicked(MouseEvent e) {
        if(paneindex!=5)
        {
            this.getContentPane().remove(0);
            this.getContentPane().add(new Dbsearch(), 0);
            this.show();
            paneindex=5;
        }
    }
    //系统设置按钮动作
    public void tools5_mouseClicked(MouseEvent e) {
        if(paneindex!=6)
        {
            //验证超级管理员密码
            String newpwd="";
            try
            {newpwd = new JOptionPane().showInputDialog(this, "请输入密码","请输入管理员密码:", JOptionPane.INFORMATION_MESSAGE).trim();}
            catch(Exception ex){System.out.println("操作员撤消输入。");}
            if(newpwd!=null && !newpwd.equals(""))
            {
                if (!newpwd.equals(Userio.getsuperuserpwd())) {JOptionPane.showMessageDialog(this, "密码错误", "提示",JOptionPane.INFORMATION_MESSAGE);}
                else
                {
                    this.getContentPane().remove(0);
                    this.getContentPane().add(new Sysconfig(), 0);
                    this.show();
                    paneindex = 6;
                }
            }
        }
    }
    //锁定按钮动作
    public void tools6_mouseClicked(MouseEvent e) {
        this.getContentPane().remove(0);
        this.getContentPane().remove(0);
        this.getContentPane().add(Lock,0);
        txfinf.setText("请输入解锁密码:");
        pwdf.setText("");
        this.update(this.getGraphics());
        this.show();
    }
    //解锁按钮动作
    public void btnunlock_actionPerformed(ActionEvent e) {
        //初始化
        txfinf.setText("");
        //得到输入值
        String newpwd= new String(pwdf.getPassword());
        //核对密码
        if(!Userio.getsuperuserpwd().equals(newpwd))
        {txfinf.setText("密码错误,请重试。");}
        else
        {
            this.getContentPane().remove(0);
            this.getContentPane().add(new Welcomepanel(),java.awt.BorderLayout.CENTER);
            this.getContentPane().add(toolspanel, java.awt.BorderLayout.NORTH);
            this.update(this.getGraphics());
            this.show();
            paneindex=1;
        }
    }
    //回车确定
    public void pwdf_keyPressed(KeyEvent e) {
        if(e.getKeyCode()==10)
        {
             //初始化
             txfinf.setText("");
             //得到输入值
             String newpwd= new String(pwdf.getPassword());
             //核对密码
             if(!Userio.getsuperuserpwd().equals(newpwd))
             {txfinf.setText("密码错误,请重试。");}
             else
             {
                 this.getContentPane().remove(0);
                 this.getContentPane().add(new Welcomepanel(),java.awt.BorderLayout.CENTER);
                 this.getContentPane().add(toolspanel, java.awt.BorderLayout.NORTH);
                 this.update(this.getGraphics());
                 this.show();
                 paneindex=1;
             }
        }
    }
}


//===========监听器、适配器===========
class Mainpanel_tools4_mouseAdapter extends MouseAdapter {
    private Mainpanel adaptee;
    Mainpanel_tools4_mouseAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {

        adaptee.tools4_mouseClicked(e);
    }
}
class Mainpanel_tools2_mouseAdapter extends MouseAdapter {
    private Mainpanel adaptee;
    Mainpanel_tools2_mouseAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {

        adaptee.tools2_mouseClicked(e);
    }
}
class Mainpanel_tools1_mouseAdapter extends MouseAdapter {
    private Mainpanel adaptee;
    Mainpanel_tools1_mouseAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.tools1_mouseClicked(e);
    }
}
class Mainpanel_tools3_mouseAdapter extends MouseAdapter {
    private Mainpanel adaptee;
    Mainpanel_tools3_mouseAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.tools3_mouseClicked(e);
    }
}
class Mainpanel_tools7_mouseAdapter extends MouseAdapter {
    private Mainpanel adaptee;
    Mainpanel_tools7_mouseAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {

        adaptee.tools7_mouseClicked(e);
    }
}
class Mainpanel_tools6_mouseAdapter extends MouseAdapter {
    private Mainpanel adaptee;
    Mainpanel_tools6_mouseAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }
    public void mouseClicked(MouseEvent e) {
        adaptee.tools6_mouseClicked(e);
    }
}
class Mainpanel_btnunlock_actionAdapter implements ActionListener {
    private Mainpanel adaptee;
    Mainpanel_btnunlock_actionAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnunlock_actionPerformed(e);
    }
}
class Mainpanel_tools5_mouseAdapter extends MouseAdapter {
    private Mainpanel adaptee;
    Mainpanel_tools5_mouseAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.tools5_mouseClicked(e);
    }
}
class Mainpanel_pwdf_keyAdapter extends KeyAdapter {
    private Mainpanel adaptee;
    Mainpanel_pwdf_keyAdapter(Mainpanel adaptee) {
        this.adaptee = adaptee;
    }

    public void keyPressed(KeyEvent e) {
        adaptee.pwdf_keyPressed(e);
    }
}

//===========监听器、适配器===========

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -