package com.example; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Home extends JFrame implements ActionListener { JMenuBar menuBar; JMenu menu; // 库存菜单 进货菜单 销售菜单 JMenuItem StockMenuItem,InventoryMenuItem,SalesMenuItem; Home() { super("城市进销存信息管理系统"); menuBar = new JMenuBar(); menu = new JMenu("菜单"); StockMenuItem = new JMenuItem("库存信息管理"); InventoryMenuItem = new JMenuItem("进货信息管理"); SalesMenuItem = new JMenuItem("销售信息管理"); menu.add(StockMenuItem); menu.add(InventoryMenuItem); menu.add(SalesMenuItem); menuBar.add(menu); setJMenuBar(menuBar); StockMenuItem.addActionListener(this); InventoryMenuItem.addActionListener(this); SalesMenuItem.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100,100,500,500); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==StockMenuItem){ new StockProductManagement(); this.setVisible(false); } if(e.getSource()==InventoryMenuItem){ new InventoryProductManagement(); this.setVisible(false); } if(e.getSource()==SalesMenuItem){ new SalesProductManagement(); this.setVisible(false); } } }