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

📄 posframe.java

📁 好的超市源码供大家下载
💻 JAVA
字号:
package view.frame;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import view.com.CenterFrame;
import view.com.GBC;
import view.com.SetFont;
import view.com.calendar.DataPicker;
import view.com.consts.FontConst;
import view.com.getcomponent.menu.GetMenu;
import view.com.systime.Clock;
import view.com.systime.SystemDate;
import view.com.systime.Time;
import action.implementclass.keyaction.PosKeyActionImp;
import action.implementclass.menuaction.PosMenuActionImp;
import action.implementclass.mouseaction.PosTableInfoAction;
import dao.UserPwdDao;

public class PosFrame extends JFrame {

  /**
   * frame pos框架
   * menuBar 菜单栏
   * name 字符串数组名
   * mne 字符数组名
   * menu 菜单
   * menuItem 子菜单
   * splitPane 分割面板
   * product_idText 商品编号文本框
   * product_nameText 商品姓名文本框
   * product_numText 商品数量文本框
   * product_sumText 商品总金额文本框
   * vip_idText 会员编号文本框
   * vip_nameText 会员姓名文本框
   * price_pctText 商品价格文本框
   * phoneText 会员电话文本框
   * billNoText 小票号码
   * posUserText pos用户文本框
   * product_dateBox 商品日期
   * topPanel 上面板
   * bottomPanel 下面板
   * rightPanel 右面板
   * leftPanel 左面板
   * table 表格
   * sp 滚动条面板
   * payButton 付款按钮
   * catchButton 
   * okButton 确定按钮
   * resetButton 重置按钮
   * deleteButton 删除按钮
   * clearButton 清除按钮
   * timeLabel 时间标签
   * dateLabel 时钟标签
   * pay 付款标签
   * vip 会员标签
   * help 帮助标签
   * delete 删除标签
   * end 全清标签
   * change 换班标签
   * exit 退出标签
   * clock 时钟
   * tableData 表格
   * mouseAction 鼠标事件
   * picker 日历
   */
  public static JFrame frame;
  private JMenuBar menuBar;
  private String[] name = { "更换登录", "小票打印", "退货", "帮助文档", "退出" };
  private char[] mne = { 'R', 'P', 'T', 'H', 'Q' };
  private JMenu menu;
  private JMenuItem[] menuItem;
  private JSplitPane splitPane;
  public static JTextField product_idText, product_nameText, product_numText, product_sumText;
  public static JTextField vip_idText, vip_nameText, price_pctText, phoneText,
      billNoText, posUserText;
  public static JComboBox product_dateBox;
  private JPanel topPanel, bottomPanel, rightPanel;
  public static JPanel leftPanel;
  public static JTable table;
  private JScrollPane sp;
  private JButton payButton, catchButton, okButton, resetButton, deleteButton,
      clearButton;
  private JLabel timeLabel, dateLabel;
  private JLabel pay, vip, help, delete, end, change, exit;
  private Clock clock;
  public String[] tableData;
  private MouseAdapter mouseAction;
  private DataPicker picker = new DataPicker();
  private String billNo; 

  /**
   * 构造PosFrame对象
   */
  public PosFrame() {
    frame = new JFrame("超市管理系统前台");
    frame.setJMenuBar(getPosMenuBar());
    frame.add(getSplitPane());
    frame.setSize(1024, 768);
    new CenterFrame().getCenterFrame(frame);
    frame.setForeground(Color.BLACK);
    leftPanel.setFocusable(true);
    leftPanel.addKeyListener(new PosKeyActionImp());
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }

  /**
   * 获得菜单栏
   * @return menuBar 菜单栏
   */
  public JMenuBar getPosMenuBar() {
    menuBar = new JMenuBar();
    menu = new GetMenu().getMenu("系统设置(S)", 'S');
    menuBar.add(menu);
    menuItem = new JMenuItem[name.length];
    for (int i = 0; i < name.length; i++) {
      menuItem[i] = new GetMenu().addMenuItemAction(name[i], mne[i]);
      menu.add(menuItem[i]);
      menuItem[i].addActionListener(new PosMenuActionImp());
    }
    return menuBar;
  }

  /**
   * 获得splitPane分割面板
   * @return splitPane 分割面板
   */
  public JSplitPane getSplitPane() {
    splitPane = new JSplitPane();
    getLeftPanel();
    splitPane.setLeftComponent(leftPanel);
    splitPane.setRightComponent(getRightPanel());
    splitPane.setForeground(Color.BLACK);
    return splitPane;
  }

  public JPanel getRightPanel() {
    rightPanel = new JPanel();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(getTopPanel(), BorderLayout.NORTH);
    rightPanel.add(getScrollPane(), BorderLayout.CENTER);
    rightPanel.add(getBottomPanel(), BorderLayout.SOUTH);
    rightPanel.setForeground(Color.BLACK);
    return rightPanel;
  }

  public JPanel getTopPanel() {
    topPanel = new JPanel();
    FlowLayout fl_top = new FlowLayout();
    JLabel label1 = new JLabel("ChangLI Corporation");
    JLabel label2 = new JLabel("单号:");
    billNoText = new JTextField(14);
    billNoText.setText("");
    billNoText.setText(initialBillNo());
    billNoText.setEditable(false);
    JLabel label3 = new JLabel("收银员:");
    posUserText = new JTextField(10);
    posUserText.setText(LoginFrame.user_tf.getText());
    posUserText.setEditable(false);
    topPanel.setLayout(fl_top);
    topPanel.add(label1);
    topPanel.add(label2);
    topPanel.add(billNoText);
    topPanel.add(label3);
    topPanel.add(posUserText);
    topPanel.setForeground(Color.BLACK);
    topPanel.setBorder(BorderFactory.createTitledBorder("当前营业状态"));
    return topPanel;
  }
  
  public String initialBillNo(){
    billNo = new String("XS080412100817");
    return billNo;
  }

  /**
   * 初始化各种文本框
   */
  public void initialText() {

    product_idText = new JTextField(7);
    product_nameText = new JTextField(7);
    product_nameText.setEditable(false);
    product_numText = new JTextField(7);
    product_sumText = new JTextField(7);
    product_sumText.setEditable(false);

    vip_idText = new JTextField(7);
    vip_nameText = new JTextField(7);
    vip_nameText.setEditable(false);
    
    price_pctText = new JTextField(7);
    price_pctText.setEditable(false);
    phoneText = new JTextField(7);
    phoneText.setEditable(false);
    product_dateBox = picker.getDataPacker();
    product_dateBox.setEnabled(false);
  }

  /**
   * 获得bottomPanel下面板
   * @return bottomPanel 下面板
   */
  public JPanel getBottomPanel() {
    initialText();
    bottomPanel = new JPanel();
    bottomPanel.setLayout(new GridBagLayout());
    payButton = new JButton("结账");
    payButton.addActionListener(new PosMenuActionImp());
    payButton.setFont(new Font("楷体", Font.PLAIN, 20));
    catchButton = new JButton("提取信息");
    catchButton.addActionListener(new PosMenuActionImp());
    catchButton.setFont(new Font("楷体", Font.PLAIN, 20));
    okButton = new JButton("确定");
    okButton.addActionListener(new PosMenuActionImp());
    okButton.setFont(new Font("楷体", Font.PLAIN, 20));
    resetButton = new JButton("重置");
    resetButton.addActionListener(new PosMenuActionImp());
    resetButton.setFont(new Font("楷体", Font.PLAIN, 20));
    deleteButton = new JButton("删除");
    deleteButton.addActionListener(new PosMenuActionImp());
    deleteButton.setFont(new Font("楷体", Font.PLAIN, 20));
    clearButton = new JButton("清空");
    clearButton.addActionListener(new PosMenuActionImp());
    clearButton.setFont(new Font("楷体", Font.PLAIN, 20));

    JLabel sumLabel = new JLabel("总金额");
    sumLabel.setFont(new Font("楷体", Font.BOLD, 20));
    bottomPanel.add(sumLabel, new GBC(0, 0).setAnchor(GBC.EAST));
    bottomPanel.add(product_sumText, new GBC(1, 0).setInset(3).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));
    bottomPanel.add(payButton,new GBC(2,0).setAnchor(GBC.CENTER));
    bottomPanel.add(catchButton, new GBC(3, 0).setAnchor(GBC.CENTER));
    bottomPanel.add(okButton, new GBC(4, 0).setAnchor(GBC.CENTER));
    bottomPanel.add(resetButton, new GBC(5, 0).setAnchor(GBC.CENTER));
    bottomPanel.add(deleteButton, new GBC(6, 0).setAnchor(GBC.CENTER));
    bottomPanel.add(clearButton, new GBC(7, 0).setAnchor(GBC.CENTER));
    bottomPanel.add(new JLabel("商品编号"), new GBC(0, 1).setAnchor(GBC.EAST));
    bottomPanel.add(product_idText, new GBC(1, 1).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));

    bottomPanel.add(new JLabel("商品数量"), new GBC(2, 1).setAnchor(GBC.EAST));
    bottomPanel.add(product_numText, new GBC(3, 1).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));

    bottomPanel.add(new JLabel("会员编号"), new GBC(4, 1).setAnchor(GBC.EAST));
    bottomPanel.add(vip_idText, new GBC(5, 1).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));

    bottomPanel.add(new JLabel("出售日期"), new GBC(6, 1).setAnchor(GBC.EAST));
    bottomPanel.add(product_dateBox, new GBC(7, 1).setInset(3).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));
   
    bottomPanel.add(new JLabel("商品名称"), new GBC(0, 2).setAnchor(GBC.EAST));
    bottomPanel.add(product_nameText, new GBC(1, 2).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));
  
    bottomPanel.add(new JLabel("会员名称"), new GBC(2, 2).setAnchor(GBC.EAST));
    bottomPanel.add(vip_nameText, new GBC(3, 2).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));
   
    bottomPanel.add(new JLabel("打折指数"), new GBC(4, 2).setAnchor(GBC.EAST));
    bottomPanel.add(price_pctText, new GBC(5, 2).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));

    bottomPanel.add(new JLabel("会员电话"), new GBC(6, 2).setAnchor(GBC.EAST));
    bottomPanel.add(phoneText, new GBC(7, 2).setInset(7).setWeight(3, 0)
        .setFill(GBC.HORIZONTAL));
    
    bottomPanel.setBorder(BorderFactory.createTitledBorder("请在每次按确定键前,按一次提取信息键以刷新数据"));
    bottomPanel.setForeground(Color.BLACK);
    return bottomPanel;
  }

  
  /**
   * 初始化各种标签
   */
  public void initialLabel() {
    timeLabel = new JLabel();
    timeLabel.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_12));
    new Time(timeLabel);
    dateLabel = new JLabel();
    dateLabel.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_12));
    new SystemDate(dateLabel);
    clock = new Clock();
    pay = new JLabel("付款: F2");
    pay.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_15));
    vip = new JLabel("会员: F1");
    vip.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_15));
    help = new JLabel("帮助: F11");
    help.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_15));
    delete = new JLabel("删除: Del");
    delete.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_15));
    end = new JLabel("全清: End");
    end.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_15));
    change = new JLabel("换班: F6");
    change.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_15));
    exit = new JLabel("退出: ESC");
    exit.setFont(SetFont.getFont(FontConst.SANSSERIF_ITALIC_15));
  }

  /**
   * 获得左面板
   */
  public void getLeftPanel() {
    initialLabel();
    leftPanel = new JPanel();
    leftPanel.setLayout(new GridBagLayout());
    leftPanel.add(dateLabel, new GBC(0, 0).setAnchor(GBC.CENTER).setInset(5, 0,
        5, 0));
    leftPanel.add(timeLabel, new GBC(0, 1).setAnchor(GBC.CENTER).setInset(5));
    leftPanel.add(clock, new GBC(0, 2).setAnchor(GBC.CENTER).setInset(5, 0, 10,
        0));
    leftPanel.add(pay, new GBC(0, 3).setAnchor(GBC.CENTER)
        .setInset(10, 0, 0, 5));
    leftPanel.add(vip, new GBC(0, 4).setAnchor(GBC.CENTER));
    leftPanel.add(help, new GBC(0, 5).setAnchor(GBC.CENTER));
    leftPanel.add(delete, new GBC(0, 6).setAnchor(GBC.CENTER));
    leftPanel.add(end, new GBC(0, 7).setAnchor(GBC.CENTER));
    leftPanel.add(change, new GBC(0, 8).setAnchor(GBC.CENTER));
    leftPanel.add(exit, new GBC(0, 9).setAnchor(GBC.CENTER));
    leftPanel.setForeground(Color.BLACK);
    leftPanel.setBorder(BorderFactory.createTitledBorder("辅助信息栏"));
  }

  /**
   * 获得滚动条面板
   * @return sp 滚动条面板
   */
  public JScrollPane getScrollPane() {
    if (table == null) {
      Object[][] data = {};
      String[] name = { "序号", "商品编号", "商品名称", "商品类别", "商品价格", "打折", "销售数量",
          "商品金额", "总计金额", "售出日期" };
      DefaultTableModel model = new DefaultTableModel(data, name) {
        public boolean isCellEditable(int row, int column) {
          return false;
        }
      };
      table = new JTable(model);
      table.setForeground(Color.BLACK);
      table.setFont(SetFont.getFont(FontConst.SERIF_BOLD_15));
      mouseAction = new PosTableInfoAction(this);
      table.addMouseListener(mouseAction);
    }
    sp = new JScrollPane(table);
    sp.setBorder(BorderFactory.createTitledBorder("商品信息栏(容纳即将付款的商品)"));
    return sp;
  }
}

⌨️ 快捷键说明

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