import javax.swing.;import java.awt.;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.;import java.util.ArrayList;public class Management extends JFrame{ Management(){ init(); setVisible(true); setTitle(“库存管理”); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void init() { ArrayList array=new ArrayList(); setLayout(new BorderLayout()); JPanel title = new JPanel(); title.setBackground(Color.pink); title.setBounds(0,0,800,200); JLabel t = new JLabel(“小涛库存管理”, JLabel.CENTER); t.setFont(new Font(“楷体雅黑”, 0, 30)); JMenuBar jm1 = new JMenuBar(); setJMenuBar(jm1); JMenu menu1 = new JMenu(“系统设置”); jm1.add(menu1); JMenu menu2 = new JMenu(“库存名称字体”); JMenu menu3 = new JMenu(“库存名称颜色”); JMenu menu4 = new JMenu(“背景”); JMenuItem over = new JMenuItem(“退出”); menu1.add(menu2); menu1.add(menu3); menu1.add(menu4); menu1.addSeparator(); menu1.add(over); over.addActionListener(new ActionListener() { @Override / * 设置退出事件 / public void actionPerformed(ActionEvent arg0) { int i = JOptionPane.showConfirmDialog(null, “是否真的退出登录”, “退出登录”, JOptionPane.YES_NO_OPTION); if (i == JOptionPane.YES_OPTION) { setVisible(false); } } }); / * 设置标题字体 / JMenuItem item1 = new JMenuItem(“楷体”); JMenuItem item2 = new JMenuItem(“宋体”); JMenuItem item3 = new JMenuItem(“黑体”); JMenuItem item4 = new JMenuItem(“正文”); menu2.add(item1); menu2.add(item2); menu2.add(item3); menu2.add(item4); item1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setFont(new Font(“楷体”, 0, 30)); } }); item2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setFont(new Font(“宋体”, 0, 30)); } }); item3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setFont(new Font(“黑体”, 0, 30)); } }); item4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setFont(new Font(“正文”, 0, 30)); } }); / * 设置标题颜色 / JMenuItem item5 = new JMenuItem(“蓝色”); JMenuItem item6 = new JMenuItem(“红色”); JMenuItem item7 = new JMenuItem(“黑色”); JMenuItem item8 = new JMenuItem(“绿色”); menu3.add(item5); menu3.add(item6); menu3.add(item7); menu3.add(item8); item5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setForeground(Color.blue); } }); item6.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setForeground(Color.RED); } }); item7.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setForeground(Color.BLACK); } }); item8.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { t.setForeground(Color.GREEN); } }); / * 设置背景颜色 / JMenuItem item9 = new JMenuItem(“蓝色”); JMenuItem item10 = new JMenuItem(“红色”); JMenuItem item11 = new JMenuItem(“黄色”); JMenuItem item12 = new JMenuItem(“绿色”); JMenuItem item13 = new JMenuItem(“粉色”); menu4.add(item9); menu4.add(item10); menu4.add(item11); menu4.add(item12); menu4.add(item13); item9.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { title.setBackground(Color.BLUE); } }); item10.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { title.setBackground(Color.RED); } }); item11.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { title.setBackground(Color.YELLOW); } }); item12.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { title.setBackground(Color.GREEN); } }); item13.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { title.setBackground(Color.PINK); } }); t.setForeground(Color.blue); title.setBorder(BorderFactory.createTitledBorder(“主题”)); title.add(t); add(title,BorderLayout.NORTH); / * 中间部分 * / JPanel operate=new JPanel(); operate.setBorder(BorderFactory.createTitledBorder(“标签按钮”)); operate.setLayout(null); JLabel number=new JLabel(“编号:”);//创建编号的标签 number.setFont(new Font(“楷体”,Font.PLAIN,20)); number.setBounds(20, 20, 60, 60); operate.add(number); JTextField number1=new JTextField(10);//创建编号的文本框 number1.setBounds(70, 20, 100, 60); number1.setFont(new Font(“楷体”,Font.PLAIN,20)); operate.add(number1); JLabel product=new JLabel(“产品:”);//创建编号的标签 product.setFont(new Font(“楷体”,Font.PLAIN,20)); product.setBounds(200, 20, 60, 60); operate.add(product); JTextField product1=new JTextField(10);//创建编号的文本框 product1.setBounds(250, 20, 100, 60); product1.setFont(new Font(“楷体”,Font.PLAIN,20)); operate.add(product1); JButton in=new JButton(“在库”); in.setBounds(70, 100, 80, 60); in.setBackground(Color.pink); operate.add(in); JButton out=new JButton(“出库”); out.setBounds(250, 100, 80, 60); out.setBackground(Color.orange); operate.add(out); add(operate,BorderLayout.CENTER); / * 设置下部 / JPanel wenben=new JPanel(); wenben.setBorder(BorderFactory.createTitledBorder(“产品显示栏”)); JTextArea shu=new JTextArea(20,30); wenben.add(new JScrollPane(shu)); add(wenben,BorderLayout.SOUTH); / * 为出库在库按钮添加事件监听 * shu.append(number1.getText()+product1.getText()+"\n"); */ in.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { addproduct(array); JOptionPane.showMessageDialog(null, “在库成功”); } private void addproduct(ArrayList array) { Product a=new Product(); a.setNumber(number1.getText()); a.setName(product1.getText()); array.add(a); for (int i = 0; i < array.size(); i++) { Product s = array.get(i); shu.append(s.getNumber()+s.getName()+"\n"); } number1.setText(""); product1.setText(""); } }); out.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteProduct(array); JOptionPane.showMessageDialog(null, “出库成功”); } private void deleteProduct(ArrayList array) { String s=JOptionPane.showInputDialog(this,“输入要出库的产品编号”); for (int i = 0; i < array.size(); i++) { Product y = array.get(i); if (s.equals(y.getNumber())) { array.remove(i); shu.append(y.getNumber()+y.getName()); } } shu.setText(""); } }); } public static void main(String[] args) { Management win=new Management(); win.setBounds(500, 0, 600, 800); }}class Product{ String number; String name; public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getName() { return name; } public void setName(String name) { this.name = name;
仓库管理
小涛