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

📄 frame2.java

📁 java
💻 JAVA
字号:
package kucunguanli;

import javax.swing.*;
import java.awt.*;
import  java.io.*;
import java.awt.event.*;
import java.util.*;
import java.util.Hashtable;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class Frame2 extends JFrame {
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JLabel jLabel2 = new JLabel();
  JTextField jTextField2 = new JTextField();
  JLabel jLabel3 = new JLabel();
  JTextField jTextField3 = new JTextField();
  JLabel jLabel4 = new JLabel();
  JTextField jTextField4 = new JTextField();
  JLabel jLabel5 = new JLabel();
  JTextField jTextField5 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  FileInputStream inone = null;
  ObjectInputStream intwo = null;
  FileOutputStream outone = null;
  ObjectOutputStream outtwo = null;
  public Frame2() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    jLabel1.setFont(new java.awt.Font("SansSerif", 0, 15));
    jLabel1.setToolTipText("");
    jLabel1.setText("产品编号");
    jLabel1.setBounds(new Rectangle(51, 26, 75, 29));
    this.getContentPane().setBackground(Color.cyan);
    this.setTitle("库存信息的录入");
    this.getContentPane().setLayout(null);
    jTextField1.setBorder(BorderFactory.createLineBorder(Color.black));    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(149, 26, 121, 25));
    jLabel2.setFont(new java.awt.Font("SansSerif", 0, 15));
    jLabel2.setText("产品名称");
    jLabel2.setBounds(new Rectangle(49, 69, 81, 26));
    jTextField2.setBorder(BorderFactory.createLineBorder(Color.black));    jTextField2.setText("");
    jTextField2.setBounds(new Rectangle(147, 68, 124, 24));
    jLabel3.setFont(new java.awt.Font("SansSerif", 0, 15));
    jLabel3.setText("产品价格");
    jLabel3.setBounds(new Rectangle(50, 110, 74, 30));
    jTextField3.setBorder(BorderFactory.createLineBorder(Color.black));    jTextField3.setText("");
    jTextField3.setBounds(new Rectangle(146, 109, 126, 26));
    jLabel4.setFont(new java.awt.Font("SansSerif", 0, 15));
    jLabel4.setText("仓库代号");
    jLabel4.setBounds(new Rectangle(51, 154, 74, 30));
    jTextField4.setBorder(BorderFactory.createLineBorder(Color.black));    jTextField4.setBounds(new Rectangle(145, 154, 125, 26));
    jLabel5.setFont(new java.awt.Font("SansSerif", 0, 15));
    jLabel5.setText("产品类型");
    jLabel5.setBounds(new Rectangle(48, 202, 72, 31));
    jTextField5.setBorder(BorderFactory.createLineBorder(Color.black));    jTextField5.setBounds(new Rectangle(143, 202, 129, 28));
    jButton1.setBounds(new Rectangle(68, 273, 78, 32));
    jButton1.setFont(new java.awt.Font("SansSerif", 0, 15));
    jButton1.setBorder(BorderFactory.createLineBorder(Color.black));
    jButton1.setText("录入");
    jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
    //jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
    //jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
    //jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
    jButton2.setBounds(new Rectangle(219, 270, 90, 33));
    jButton2.setFont(new java.awt.Font("SansSerif", 0, 15));
    jButton2.setBorder(BorderFactory.createLineBorder(Color.black));
    jButton2.setDebugGraphicsOptions(0);
    jButton2.setHorizontalAlignment(SwingConstants.CENTER);
    jButton2.setText("退出");
    jButton2.addActionListener(new Frame2_jButton2_actionAdapter(this));
    jButton2.addActionListener(new Frame2_jButton2_actionAdapter(this));
    jButton2.addActionListener(new Frame2_jButton2_actionAdapter(this));
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jLabel2, null);
    this.getContentPane().add(jTextField2, null);
    this.getContentPane().add(jLabel3, null);
    this.getContentPane().add(jTextField3, null);
    this.getContentPane().add(jLabel4, null);
    this.getContentPane().add(jTextField4, null);
    this.getContentPane().add(jLabel5, null);
    this.getContentPane().add(jTextField5, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton2, null);
  }

  void jButton2_actionPerformed(ActionEvent e) {
  this.hide();
  }
  void jButton1_actionPerformed(ActionEvent e) {
    Hashtable 数据库 = new Hashtable();
    File file = new File("数据库.txt");
    luru l=new luru();
    FileInputStream inOne = null;
    ObjectInputStream inTwo = null;
    FileOutputStream outOne = null;
    ObjectOutputStream outTwo = null;
    String number = "";
    number = jTextField1.getText();
    if(number.length()>0)
          {
            try {
              inOne = new FileInputStream(file);
              inTwo = new ObjectInputStream(inOne);
              数据库 = (Hashtable) inTwo.readObject();
              inOne.close();
              inTwo.close();
            }
            catch (Exception ee) {
            }

            if (数据库.containsKey(number)) {
              String warning = "该生基本信息已存在,请到修改页面修改!";

              JOptionPane.showMessageDialog(this, warning, "警告",
                                            JOptionPane.WARNING_MESSAGE);
            }
            else {
              String m = "基本信息将被录入!";
              int ok = JOptionPane.showConfirmDialog(this, m, "确认",
                                                     JOptionPane.YES_NO_OPTION,
                                                     JOptionPane.INFORMATION_MESSAGE);
              if (ok == JOptionPane.YES_OPTION)
              {
                   String bianhao=jTextField1.getText();
                     String name=jTextField2.getText();
                     String leixing=jTextField3.getText();
                     String price=jTextField4.getText();
                     String ckdh=jTextField5.getText();
                     l=new luru();
                     l.getbianhao(bianhao);
                     l.getname(name);
                     l.getleixing(leixing) ;
                     l.getprice(price) ;
                     l.getckdh(ckdh) ;
                try{
                           outOne=new FileOutputStream(file);
                           outTwo=new ObjectOutputStream(outOne);
                           数据库.put(number,l);
                           //数据库.put(name,l);
                          // 数据库.put(leixing,l);
                           //数据库.put(price,l);
                           outTwo.writeObject(数据库);
                           outTwo.close();
                           outOne.close();
                      }
                              catch(Exception ee)
                                 {
                                  System.out.println(ee);
                                 }


              }
            }
          }
            else
             {
               String warning="必须要输入产品编号!";
               JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
              }

  }
class Frame2_jButton2_actionAdapter implements java.awt.event.ActionListener {
 Frame2 adaptee;

  Frame2_jButton2_actionAdapter(Frame2 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class Frame2_jButton1_actionAdapter implements java.awt.event.ActionListener
{
    Frame2 adaptee;
    Frame2_jButton1_actionAdapter(Frame2 adaptee)
    {
      this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
      adaptee.jButton1_actionPerformed(e);
    }
}


  }

class Frame2_jButton1_actionAdapter implements java.awt.event.ActionListener {
  Frame2 adaptee;

  Frame2_jButton1_actionAdapter(Frame2 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class Frame2_jButton2_actionAdapter implements java.awt.event.ActionListener {
  Frame2 adaptee;

  Frame2_jButton2_actionAdapter(Frame2 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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