You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
test/branch_zyx/MainView.java

703 lines
32 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.lingnan.supermarket.view; // 定义包名,所有视图相关的类都在这个包下
import java.awt.event.ActionEvent; // 导入ActionEvent类用于监听动作事件
import java.awt.event.ActionListener; // 导入ActionListener接口用于实现动作事件监听
import java.awt.event.MouseEvent; // 导入MouseEvent类用于监听鼠标事件
import java.awt.event.MouseListener; // 导入MouseListener接口用于实现鼠标事件监听
import java.awt.event.WindowEvent; // 导入WindowEvent类用于监听窗口事件
import java.awt.event.WindowListener; // 导入WindowListener接口用于实现窗口事件监听
import java.io.File; // 导入File类用于文件操作
import java.io.IOException; // 导入IOException类用于处理输入输出异常
import java.util.Date; // 导入Date类用于处理日期
import java.util.Random; // 导入Random类用于生成随机数
import java.util.Vector; // 导入Vector类用于实现动态数组
import javax.imageio.ImageIO; // 导入ImageIO类用于图像输入输出
import javax.swing.ImageIcon; // 导入ImageIcon类用于显示图片
import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JMenu; // 导入JMenu类用于创建菜单
import javax.swing.JMenuBar; // 导入JMenuBar类用于创建菜单栏
import javax.swing.JMenuItem; // 导入JMenuItem类用于创建菜单项
import javax.swing.JOptionPane; // 导入JOptionPane类用于显示对话框
import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.JSplitPane; // 导入JSplitPane类用于创建分隔面板
import javax.swing.Timer; // 导入Timer类用于实现定时器
import com.lingnan.supermarket.componet.BGPanel; // 导入自定义的BGPanel类
import com.lingnan.supermarket.dao.impl.BufferImpl; // 导入BufferImpl类可能是数据访问层的实现
import com.lingnan.supermarket.dao.impl.inOrderServiceImpl; // 导入inOrderServiceImpl类可能是订单服务的实现
import com.lingnan.supermarket.dialog.CloseDialog; // 导入CloseDialog类可能是关闭对话框
import com.lingnan.supermarket.dialog.InDialog; // 导入InDialog类可能是入库对话框
import com.lingnan.supermarket.dialog.UserDialog; // 导入UserDialog类可能是用户对话框
import com.lingnan.supermarket.dialog.UserInfDialog; // 导入UserInfDialog类可能是用户信息对话框
import com.lingnan.supermarket.dto.InOrder; // 导入InOrder类可能是订单数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入Production类可能是产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类可能是用户数据传输对象
import com.lingnan.supermarket.utils.DateUtil; // 导入DateUtil类可能是日期工具类
import com.lingnan.supermarket.utils.FontUtil; // 导入FontUtil类可能是字体工具类
import com.lingnan.supermarket.view.base.BaseView; // 导入BaseView类可能是视图基类
import java.awt.*; // 导入awt包中的所有类
// 主视图类继承自BaseView并实现多个事件监听接口
public class MainView extends BaseView implements ActionListener, MouseListener,WindowListener{
JMenuBar menuBar; // 声明菜单栏变量
JMenu settingMenu,helpMenu; // 声明设置菜单和帮助菜单变量
JMenuItem skinMenuItem,configMenuItem; // 声明皮肤菜单项和配置菜单项变量
JSplitPane containerPanel; // 声明分隔面板变量,用于左右布局
CardLayout rightPanelLayout; // 声明卡片布局管理器变量,用于右侧面板
JPanel leftPanel,rightPanel; // 声明左侧和右侧面板变量
/*菜单栏组件*/
JLabel logoLabel,userMenuLabel1,homeMenuLabel,userMenuLabel,inMenuLabel,
outMenuLabel,storageMenuLabel,supplierMenuLabel,catalogMenuLabel;
// 声明菜单栏中各个标签的变量
static JLabel remindMenuLabel;/*声明静态标签变量,用于全局调用刷新*/
JPanel bottomPanel; // 声明底部面板变量
JLabel timeLabel; // 声明时间标签变量
JPanel purposePanel,timePanel; // 声明目的面板和时间面板变量
JLabel purposeLabel; // 声明目的标签变量
JButton saveBtn,unSaveBtn,cancleBtn;/*退出时按钮*/
//
Timer timer; // 声明定时器变量,用于执行周期性任务
private User user ;/*从登录界面传过来的用户信息,用于当前视图的用户上下文*/
private BufferImpl bufferImpl; // 声明BufferImpl对象可能是用于缓存处理的实现
private Image bgImage ; // 声明背景图片变量
private String iconSkin; // 声明图标皮肤路径变量
private int skin; // 声明皮肤编号变量
private Vector<Production> vP=new Vector<Production>() ;/*用于进货缓存,存储产品信息*/
private int location; // 声明位置变量,可能用于记录当前视图的状态或位置
private int sSuper=-1;//界面权限,用于标识用户权限级别
private static inOrderServiceImpl inOrderImpl = new inOrderServiceImpl(); // 声明并实例化订单服务实现类
private static int unConfirmmark;/*未确认订单的数量*/
// 构造方法,接收用户信息、皮肤编号和图标皮肤路径
public MainView(User user,int skin,String iconSkin) {
super(1300,850,"新民超市管理系统欢迎您",user,skin); // 调用父类构造方法,设置窗口大小、标题、用户信息和皮肤
timer = new Timer(1000,this); // 创建定时器每1000毫秒执行一次
timer.start(); // 启动定时器
this.user = user; // 保存用户信息到当前视图
this.sSuper=user.getUsuper();//界面权限,从用户信息中获取权限级别
System.out.println("userid="+user.getId()); // 打印用户ID
this.addWindowListener(this); // 为当前窗口添加窗口事件监听器
this.skin = skin; // 保存皮肤编号
this.iconSkin = iconSkin; // 保存图标皮肤路径
ImageIcon icon=new ImageIcon(iconSkin); // 创建ImageIcon对象加载图标皮肤
this.setIconImage(icon.getImage()); // 设置窗口图标
// 获得未进货的信息
Vector<InOrder> vInOrder;
vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找未确认的订单
unConfirmmark=vInOrder.size(); // 设置未确认订单的数量
initView(user,skin); // 初始化视图
}
// 另一个构造方法,只接收用户信息
public MainView(User user) {
super(1300,850,"新民超市管理系统欢迎您"); // 调用父类构造方法,设置窗口大小和标题
timer = new Timer(1000,this); // 创建定时器每1000毫秒执行一次
timer.start(); // 启动定时器
this.user = user; // 保存用户信息到当前视图
this.sSuper=user.getUsuper();//界面权限,从用户信息中获取权限级别
System.out.println("userid="+user.getId()); // 打印用户ID
this.addWindowListener(this); // 为当前窗口添加窗口事件监听器
// 获得未进货的信息
Vector<InOrder> vInOrder;
vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找未确认的订单
unConfirmmark=vInOrder.size(); // 设置未确认订单的数量
initView(user,skin); // 初始化视图这里没有为skin赋值可能会出错
}
public static void refreshRemind() {
Vector<InOrder> vInOrder; // 声明未确认订单的向量
vInOrder = inOrderImpl.findUnconfirmInOrder(); // 查找所有未确认的订单
unConfirmmark = vInOrder.size(); // 获取未确认订单的数量
remindMenuLabel.setText("待确认进货:" + unConfirmmark); // 更新菜单标签,显示未确认订单的数量
}
// 以下是注释掉的代码,没有实现功能
/* public static User getUserInf() {
return user; // 返回用户信息
}*/
@Override
protected void initView(User user, int skin) {
// 初始化视图的方法,接收用户信息和皮肤编号
/*菜单栏*/
menuBar = new JMenuBar(); // 创建菜单栏
settingMenu = new JMenu("设置"); // 创建设置菜单
helpMenu = new JMenu("帮助"); // 创建帮助菜单
skinMenuItem = new JMenuItem("随机切换皮肤", new ImageIcon("static\\icon\\skin.png")); // 创建切换皮肤的菜单项
/*for循环被注释掉了没有实际作用
for(int i = 3;i<9;i++) {
}*/
configMenuItem = new JMenuItem("参数设置", new ImageIcon("static\\icon\\setting.png")); // 创建参数设置的菜单项
skinMenuItem.addActionListener(this); // 为切换皮肤菜单项添加动作监听器
settingMenu.add(configMenuItem); // 将参数设置菜单项添加到设置菜单
settingMenu.add(skinMenuItem); // 将切换皮肤菜单项添加到设置菜单
menuBar.add(settingMenu); // 将设置菜单添加到菜单栏
menuBar.add(helpMenu); // 将帮助菜单添加到菜单栏
setJMenuBar(menuBar); // 将菜单栏设置到当前窗口
/*左边菜单栏设置*/
try {
bgImage = ImageIO.read(new File("static\\bg\\bg" + skin + ".jpg")); // 读取背景图片
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); // 打印异常堆栈信息
}
leftPanel = new BGPanel(bgImage); /*皮肤*/ // 创建带有背景的左边面板
leftPanel.setLayout(null); // 设置左边面板布局为空,即绝对布局
/*菜单栏:用户登录信息*/
System.out.println("用户头像地址==" + user.getImg()); // 打印用户头像地址
JLabel logoLabel = new JLabel(new ImageIcon(user.getImg()), JLabel.LEFT); // 创建用户头像标签
System.out.println(user.getImg()); // 再次打印用户头像地址
leftPanel.add(logoLabel); // 将用户头像标签添加到左边面板
logoLabel.setBounds(25, 30, 150, 150); // 设置用户头像标签的位置和大小
/*账号名字*/
String x = UsuperIcon(user.getUsuper()); /*判断权限返回icon地址*/ // 根据用户权限返回相应的图标地址
System.out.println("身份地址:" + x); // 打印身份图标地址
userMenuLabel1 = new JLabel("|" + user.getUsername() + "|" + user.getRname(), new ImageIcon(x), JLabel.LEFT); // 创建用户信息标签
userMenuLabel1.setFont(FontUtil.userFont); // 设置用户信息标签的字体
userMenuLabel1.addMouseListener(this); // 为用户信息标签添加鼠标监听器
userMenuLabel1.setBounds(20, 170, 180, 32); // 设置用户信息标签的位置和大小
userMenuLabel1.setForeground(Color.white); // 设置用户信息标签的前景色为白色
leftPanel.add(userMenuLabel1); /*添加用户选项到菜单栏*/ // 将用户信息标签添加到左边面板
/*菜单栏:首页*/
homeMenuLabel = new JLabel("新民首页", new ImageIcon("static\\icon\\home1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示首页菜单
homeMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
homeMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
homeMenuLabel.setBounds(20, 250, 150, 32); // 设置菜单标签的位置和大小
homeMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(homeMenuLabel); // 将首页菜单标签添加到左侧面板
/*菜单栏:人员管理*/
userMenuLabel = new JLabel("人员管理", new ImageIcon("static\\icon\\user1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示人员管理菜单
userMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
userMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
userMenuLabel.setBounds(20, 300, 150, 32); // 设置菜单标签的位置和大小
userMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(userMenuLabel); // 将人员管理菜单标签添加到左侧面板
/*菜单栏:进货系统*/
inMenuLabel = new JLabel("进货系统", new ImageIcon("static\\icon\\in1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示进货系统菜单
inMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
inMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
inMenuLabel.setBounds(20, 350, 150, 32); // 设置菜单标签的位置和大小
inMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(inMenuLabel); // 将进货系统菜单标签添加到左侧面板
/*菜单栏:收银系统*/
outMenuLabel = new JLabel("收银系统", new ImageIcon("static\\icon\\out1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示收银系统菜单
outMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
outMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
outMenuLabel.setBounds(20, 400, 150, 32); // 设置菜单标签的位置和大小
outMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(outMenuLabel); // 将收银系统菜单标签添加到左侧面板
/*菜单栏:库存*/
storageMenuLabel = new JLabel("商品库存", new ImageIcon("static\\icon\\storage1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示商品库存菜单
storageMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
storageMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
storageMenuLabel.setBounds(20, 450, 150, 32); // 设置菜单标签的位置和大小
storageMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(storageMenuLabel); // 将商品库存菜单标签添加到左侧面板
/*菜单栏:供应商*/
supplierMenuLabel = new JLabel("供应商", new ImageIcon("static\\icon\\supplier1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示供应商菜单
supplierMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
supplierMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
supplierMenuLabel.setBounds(20, 500, 150, 32); // 设置菜单标签的位置和大小
supplierMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(supplierMenuLabel); // 将供应商菜单标签添加到左侧面板
/*菜单栏:商品目录*/
catalogMenuLabel = new JLabel("商品目录", new ImageIcon("static\\icon\\catalog1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于表示商品目录菜单
catalogMenuLabel.setFont(FontUtil.menuFont); // 设置菜单标签的字体样式
catalogMenuLabel.addMouseListener(this); // 为菜单标签添加鼠标事件监听器
catalogMenuLabel.setBounds(20, 550, 150, 32); // 设置菜单标签的位置和大小
catalogMenuLabel.setForeground(Color.white); // 设置菜单标签的前景色为白色
leftPanel.add(catalogMenuLabel); // 将商品目录菜单标签添加到左侧面板
/*提醒进货确认模块*/
remindMenuLabel = new JLabel("待确认进货:"+unConfirmmark, new ImageIcon("static\\icon\\remind1.png"), JLabel.LEFT); // 创建一个带有图标的JLabel用于显示待确认进货的数量
remindMenuLabel.setFont(FontUtil.remindFont); // 设置提醒菜单标签的字体样式
remindMenuLabel.addMouseListener(this); // 为提醒菜单标签添加鼠标事件监听器
remindMenuLabel.setBounds(0, 650, 200, 32); // 设置提醒菜单标签的位置和大小
remindMenuLabel.setForeground(Color.white); // 设置提醒菜单标签的前景色为白色
leftPanel.add(remindMenuLabel); // 将提醒菜单标签添加到左侧面板
// 设置右侧面板的布局管理器为卡片布局
rightPanelLayout = new CardLayout();
// 0.超市首页展示,创建并实例化首页视图面板
JPanel homePanel = new HomeView(this);
// 1.用户管理界面:用户的列表,创建并实例化用户管理视图面板
JPanel userPanel = new UserView(this);
// 2.进货系统界面,创建并实例化进货系统视图面板
JPanel inPanel = new InView(this, user, vP, 1);
// 3.收银系统界面,创建并实例化收银系统视图面板
JPanel outPanel = new OutView(this, user);
// 4.库存系统界面,创建并实例化库存系统视图面板
JPanel storagePanel = new StorageView(this);
// 5.供应商界面,创建并实例化供应商视图面板
JPanel supplierPanel = new SupplierView(this);
// 6.商品目录界面,创建并实例化商品目录视图面板
JPanel ProdCatalogPanel = new ProdCatalogView(this);
// 7.超市总览界面,创建并实例化超市总览视图面板
JPanel superPanel = new SuperView(this);
// 8.进货信息提示界面,创建并实例化进货信息提示视图面板
JPanel inPanel2 = new InView(this, user, vP, 0);
// 创建右侧面板并设置布局管理器为之前定义的卡片布局
rightPanel = new JPanel(rightPanelLayout);
rightPanel.add(homePanel, "0"); // 添加首页视图面板并设置其索引为"0"
rightPanel.add(userPanel, "1"); // 添加用户管理视图面板并设置其索引为"1"
rightPanel.add(inPanel, "2"); // 添加进货系统视图面板并设置其索引为"2"
rightPanel.add(outPanel, "3"); // 添加收银系统视图面板并设置其索引为"3"
rightPanel.add(storagePanel, "4"); // 添加库存系统视图面板并设置其索引为"4"
rightPanel.add(supplierPanel, "5"); // 添加供应商视图面板并设置其索引为"5"
rightPanel.add(ProdCatalogPanel, "6"); // 添加商品目录视图面板并设置其索引为"6"
rightPanel.add(superPanel, "7"); // 添加超市总览视图面板并设置其索引为"7"
rightPanel.add(inPanel2, "8"); // 添加进货信息提示视图面板并设置其索引为"8"
// 创建一个分割面板,将左侧面板和右侧面板水平分割
containerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
containerPanel.setDividerLocation(180); // 设置分割线的位置
containerPanel.setDividerSize(0); // 设置分割线的尺寸为0即隐藏分割线
// 创建底部面板,默认使用流式布局
bottomPanel = new JPanel();
bottomPanel.setBackground(Color.WHITE); // 设置底部面板的背景色为白色
bottomPanel.setLayout(new BorderLayout()); // 设置底部面板的布局管理器为边界布局
// 创建目的地区面板,用于显示当前位置信息
purposePanel = new JPanel();
purposePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // 设置目的地区面板的布局管理器为左对齐的流式布局
purposePanel.setBackground(Color.WHITE); // 设置目的地区面板的背景色为白色
purposeLabel = new JLabel("当前位置是:超市首页"); // 创建标签显示当前位置信息
purposePanel.add(purposeLabel); // 将位置信息标签添加到目的地区面板
// 创建一个新的 JPanel 实例用于显示时间
timePanel=new JPanel();
// 设置 timePanel 的布局为 FlowLayout并指定元素靠右对齐
timePanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
// 设置 timePanel 的背景颜色为白色
timePanel.setBackground(Color.WHITE);
// 创建一个新的 JLabel 实例,显示当前日期和时间,使用 DateUtil 工具类进行格式化
timeLabel = new JLabel(DateUtil.dateToString(new Date(),null));
// 将 timeLabel 添加到 timePanel 中
timePanel.add(timeLabel);
// 将 purposePanel 添加到 bottomPanel 的西边West
bottomPanel.add(purposePanel,"West");
// 将 timePanel 添加到 bottomPanel 的东边East
bottomPanel.add(timePanel,"East");
// 获取当前窗口的内容窗格
Container container = getContentPane();
// 将 containerPanel 添加到内容窗格的中心Center
container.add(containerPanel,"Center");
// 将 bottomPanel 添加到内容窗格的南边South
container.add(bottomPanel,"South");
}
@Override
// 定义当触发动作事件时的处理方法
public void actionPerformed(ActionEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 更新时间标签以显示当前时间
timeLabel.setText(DateUtil.dateToString(new Date(),null));
// 检查事件源是否为皮肤菜单项,如果是则进行换肤操作
if(source==skinMenuItem)/*换肤*/{
// 打印换肤操作信息到控制台
System.out.println("切换皮肤");
// 创建一个新的随机数生成器实例
Random random=new Random();
// 生成一个0到9之间的随机数作为皮肤编号
skin=random.nextInt(10);
// 销毁当前窗口
this.dispose();
// 创建并显示一个新的主视图窗口,传入用户信息、皮肤编号和图标皮肤
new MainView(user,skin,iconSkin);
}
}
@Override/*左侧菜单栏点击事件*/
// 定义当鼠标点击事件发生时的处理方法
public void mouseClicked(MouseEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 检查事件源是否为首页菜单标签,如果是则显示对应的面板
if(source==homeMenuLabel) {
rightPanelLayout.show(rightPanel,"0"); // 显示首页面板
location=0; // 更新当前位置索引为0
}
// 检查事件源是否为用户菜单标签,根据权限显示不同面板
else if(source==userMenuLabel) {
if(sSuper==0) // 如果权限为0
rightPanelLayout.show(rightPanel,"1"); // 显示用户面板1
else{ // 如果权限不为0
rightPanelLayout.show(rightPanel,"7"); // 显示用户面板7
}
location=1; // 更新当前位置索引为1
}
// 检查事件源是否为入库菜单标签,根据权限显示不同面板
else if(source==inMenuLabel) {
if(sSuper==2) // 如果权限为2
rightPanelLayout.show(rightPanel,"7"); // 显示面板7
else{ // 如果权限不为2
rightPanelLayout.show(rightPanel,"2"); // 显示入库面板
}
location=2; // 更新当前位置索引为2
}
// 检查事件源是否为出库菜单标签,如果是则显示对应的面板
else if(source==outMenuLabel) {
rightPanelLayout.show(rightPanel,"3"); // 显示出库面板
location=3; // 更新当前位置索引为3
}
// 检查事件源是否为库存菜单标签,如果是则显示对应的面板
else if(source==storageMenuLabel) {
rightPanelLayout.show(rightPanel,"4"); // 显示库存面板
location=4; // 更新当前位置索引为4
}
// 检查事件源是否为供应商菜单标签,如果是则显示对应的面板
else if(source==supplierMenuLabel) {
rightPanelLayout.show(rightPanel,"5"); // 显示供应商面板
location=5; // 更新当前位置索引为5
}
// 检查事件源是否为目录菜单标签,如果是则显示对应的面板
else if(source==catalogMenuLabel) {
rightPanelLayout.show(rightPanel,"6"); // 显示目录面板
location=6; // 更新当前位置索引为6
}
// 检查事件源是否为提醒菜单标签,根据权限显示不同面板
else if(source==remindMenuLabel) {
if(sSuper==2) // 如果权限为2
rightPanelLayout.show(rightPanel,"7"); // 显示面板7
else{ // 如果权限不为2
rightPanelLayout.show(rightPanel,"8"); // 显示提醒面板
}
location=7; // 更新当前位置索引为7
}
// 检查事件源是否为用户信息菜单标签1如果是则显示用户信息对话框
else if(source==userMenuLabel1){
UserInfDialog userInfDialog = new UserInfDialog(this,user); // 创建用户信息对话框
userInfDialog.setVisible(true); // 显示用户信息对话框
location=8; // 更新当前位置索引为8
}
// 调用refreshRemove方法可能用于刷新界面或执行其他操作
refreshRemove();
}
//获取当前位置
// 定义一个方法用于刷新和移除面板内容
public void refreshRemove(){
// 从目的面板中移除所有组件
purposePanel.removeAll();
// 根据当前的位置索引设置不同的目的标签文本
if(location==0){
purposeLabel = new JLabel("当前位置是:"+homeMenuLabel.getText()); // 设置当前位置为首页
}
else if(location==1){
purposeLabel = new JLabel("当前位置是:"+userMenuLabel.getText()); // 设置当前位置为用户菜单
}
else if(location==2){
purposeLabel = new JLabel("当前位置是:"+inMenuLabel.getText()); // 设置当前位置为入库菜单
}
else if(location==3){
purposeLabel = new JLabel("当前位置是:"+outMenuLabel.getText()); // 设置当前位置为出库菜单
}
else if(location==4){
purposeLabel = new JLabel("当前位置是:"+storageMenuLabel.getText()); // 设置当前位置为库存菜单
}
else if(location==5){
purposeLabel = new JLabel("当前位置是:"+supplierMenuLabel.getText()); // 设置当前位置为供应商菜单
}
else{
purposeLabel = new JLabel("当前位置是:"+catalogMenuLabel.getText()); // 设置当前位置为目录菜单
}
// 将新的目的标签添加到目的面板
purposePanel.add(purposeLabel);
// 可能需要调用重新绘制界面或更新界面显示的方法,但这里没有显示出来
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override/*鼠标焦点时*/
// 重写鼠标进入组件事件的处理方法
public void mouseEntered(MouseEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 如果事件源是首页菜单标签,则改变前景色和图标
if(source==homeMenuLabel) {
homeMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是用户菜单标签,则改变前景色和图标
if(source==userMenuLabel) {
userMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
userMenuLabel.setIcon(new ImageIcon("static\\icon\\user2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是入库菜单标签,则改变前景色和图标
else if(source==inMenuLabel) {
inMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
inMenuLabel.setIcon(new ImageIcon("static\\icon\\in2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是出库菜单标签,则改变前景色和图标
else if(source==outMenuLabel) {
outMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
outMenuLabel.setIcon(new ImageIcon("static\\icon\\out2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是库存菜单标签,则改变前景色和图标
else if(source==storageMenuLabel) {
storageMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是供应商菜单标签,则改变前景色和图标
else if(source==supplierMenuLabel) {
supplierMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是目录菜单标签,则改变前景色和图标
else if(source==catalogMenuLabel) {
catalogMenuLabel.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog2.png")); // 设置鼠标进入时的图标
}
// 如果事件源是用户菜单标签1则改变前景色
else if(source==userMenuLabel1) {
userMenuLabel1.setForeground(new Color(18, 150, 219)); // 设置前景色为蓝色
// 注意:这里没有设置图标,可能是因为该标签没有对应的鼠标进入图标
}
// 方法结束,没有设置图标的变化,只是改变了前景色
}
@Override
// 重写鼠标离开组件事件的处理方法
public void mouseExited(MouseEvent e) {
// 获取触发事件的源对象
Object source = e.getSource();
// 如果事件源是首页菜单标签,则恢复前景色和图标
if(source==homeMenuLabel) {
homeMenuLabel.setForeground(Color.white); // 恢复前景色为白色
homeMenuLabel.setIcon(new ImageIcon("static\\icon\\home1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是用户菜单标签,则恢复前景色和图标
else if(source==userMenuLabel) {
userMenuLabel.setForeground(Color.white); // 恢复前景色为白色
userMenuLabel.setIcon(new ImageIcon("static\\icon\\user1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是入库菜单标签,则恢复前景色和图标
else if(source==inMenuLabel) {
inMenuLabel.setForeground(Color.white); // 恢复前景色为白色
inMenuLabel.setIcon(new ImageIcon("static\\icon\\in1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是出库菜单标签,则恢复前景色和图标
else if(source==outMenuLabel) {
outMenuLabel.setForeground(Color.white); // 恢复前景色为白色
outMenuLabel.setIcon(new ImageIcon("static\\icon\\out1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是库存菜单标签,则恢复前景色和图标
else if(source==storageMenuLabel) {
storageMenuLabel.setForeground(Color.white); // 恢复前景色为白色
storageMenuLabel.setIcon(new ImageIcon("static\\icon\\storage1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是供应商菜单标签,则恢复前景色和图标
else if(source==supplierMenuLabel) {
supplierMenuLabel.setForeground(Color.white); // 恢复前景色为白色
supplierMenuLabel.setIcon(new ImageIcon("static\\icon\\supplier1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源是目录菜单标签,则恢复前景色和图标
else if(source==catalogMenuLabel) {
catalogMenuLabel.setForeground(Color.white); // 恢复前景色为白色
catalogMenuLabel.setIcon(new ImageIcon("static\\icon\\catalog1.png")); // 设置鼠标离开时的默认图标
}
// 如果事件源不是上述任何一个标签则默认处理用户菜单标签1
else {
userMenuLabel1.setForeground(Color.white); // 恢复前景色为白色
// 注意:这里没有设置图标,可能是因为该标签没有对应的鼠标离开图标
}
// 方法结束,所有菜单标签的前景色和图标已根据鼠标离开事件进行了相应的恢复
}
@Override
protected void initView() {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
// 重写窗口关闭事件的处理方法
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
// 获取触发事件的源对象
Object source = e.getSource();
// 如果事件源是当前窗口对象,执行以下操作
if(source==this) {
// 关闭窗口时检查进货系统和出货系统是否还有记录
this.vP =InView.getVector(); // 获取进货系统的记录向量
System.out.println("v的size="+vP.size()); // 打印进货系统记录的数量
bufferImpl = new BufferImpl(); // 创建缓冲区实现对象
// 如果进货系统的购物车还有记录或者出货系统的缓冲区还有记录
if(vP.size()!=0||bufferImpl.allOutBuffer().size()!=0) {
// 如果购物车还有记录,则显示关闭确认对话框
CloseDialog closeDialog = new CloseDialog(this,vP); // 创建关闭对话框
closeDialog.setVisible(true); // 显示关闭对话框
} else {
// 如果没有记录,则直接退出程序
System.exit(0); // 安全退出程序
}
}
// 方法结束,窗口关闭事件已处理
}
@Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
}