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

📄 checkoutdialog.java

📁 网吧管理系统. 实现了网吧收费的管理.每小时设置2元,不足1小时扣除2元,1小时5分内扣除2元,以后扣除两小时的4元.
💻 JAVA
字号:
package com.liu.view;

import java.awt.*;
import javax.swing.*;

import com.liu.Cortrol.SelectNet;

import Bean.*;

import java.awt.event.*;
import java.text.*;
import java.util.ArrayList;
import java.util.Iterator;


/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author Michael Luo
 * @version 1.0
 */

public class CheckOutDialog extends JDialog {
	
	SelectNet sn = new SelectNet();
	Computer computer = new Computer();
	Card card = new Card();
	Record record = new Record();
	int computer_id;
	int computer_id1;
	float time;
	
  JPanel panel1 = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  JLabel computerIdLabel = new JLabel();
  JLabel checkOutTimeLabel = new JLabel();
  JTextField checkOutTimeTextField = new JTextField();
  JButton confirmButton = new JButton();
  JButton resetButton = new JButton();
  JComboBox computerIdCombox = new JComboBox();
  java.util.Date nowTime;
  public CheckOutDialog(NetBarFeeMangementFrame frame, String title,
                        boolean modal) {
    super(frame, title, modal);
    mainFrame = frame;
    this.setLocation(250, 200);
    try {
      jbInit();
      pack();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public CheckOutDialog() {
    this(null, "", false);
  }

  private void jbInit() throws Exception {
    this.getContentPane().setLayout(borderLayout1);
    panel1.setPreferredSize(new Dimension(300, 200));
    panel1.setLayout(null);

    computerIdLabel.setFont(new java.awt.Font("Serif", 0, 16));
    computerIdLabel.setText("机  器  号:");
    computerIdLabel.setBounds(new Rectangle(50, 30, 80, 25));

    computerIdCombox.setBounds(new Rectangle(130, 30, 100, 25));

    checkOutTimeLabel.setFont(new java.awt.Font("Serif", 0, 16));
    checkOutTimeLabel.setText("结束时间:");
    checkOutTimeLabel.setBounds(new Rectangle(50, 100, 80, 25));

    nowTime = new java.util.Date();
    SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    String strNowTime = HMFromat.format(nowTime);
    checkOutTimeTextField.setText(strNowTime);
    checkOutTimeTextField.setBounds(new Rectangle(130, 100, 100, 25));
    checkOutTimeTextField.setEditable(false);

    confirmButton.setBounds(new Rectangle(60, 150, 70, 25));
    confirmButton.setText("确定");
    confirmButton.addActionListener(new CheckOutDialog_ConfirmButton_ActionAdapter(this));
    resetButton.setBounds(new Rectangle(150, 150, 70, 25));
    resetButton.setText("重置");
    resetButton.addActionListener(new CheckOutDialog_ResetButton_ActionAdapter(this));

    panel1.add(computerIdLabel, null);
    panel1.add(checkOutTimeLabel, null);
    panel1.add(checkOutTimeTextField, null);
    panel1.add(confirmButton, null);
    panel1.add(resetButton, null);
    panel1.add(computerIdCombox, null);
    this.getContentPane().add(panel1, BorderLayout.CENTER);

    ArrayList al = sn.getComputer2();
	Iterator iter = al.iterator();
	     while(iter.hasNext()){
	     computer = (Computer)iter.next();
	     computerIdCombox.addItem(computer.getComputer_id());
	     }

  }

  void resetButton_actionPerformed(ActionEvent e) {
    computerIdCombox.setSelectedIndex(0);
    checkOutTimeTextField.setText("");
  }

  void confirmButton_actionPerformed(ActionEvent e) {
	  
    String stopTime = checkOutTimeTextField.getText() + ":00";
    String computerId = computerIdCombox.getSelectedItem().toString().trim();
    if (computerId == null || computerId.length() == 0) {
      return;
    }
    
    computer_id1 = Integer.parseInt(computerId);
    record.setComputer_id(computer_id1);
    
    SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    	long l = 0;
	    try{
			l=simple.parse(checkOutTimeTextField.getText()).getTime();
		}catch(Exception e1){
			e1.printStackTrace();
		}
	record.setEndt(checkOutTimeTextField.getText());	
	record.setEndtime(l);
	sn.setRecord2(record);
	sn.updateComputer2(record.getComputer_id());
//扣除钱的方法
	time = sn.getRecord(record.getComputer_id());

	System.out.println(time);
	int cost = 0;
	if(time/(1000*60*60)<1){
		cost = 2;
	}else{
	if((time/(1000*60))%60>5){
		cost = (int) time/(1000*60*60)*2+2;
	}
	if((time/(1000*60))%60<5){
		cost = (int) time/(1000*60*60)*2;
	}
	}
	record.setCost(cost);
	sn.setCost(record);
	computer_id = sn.getRecord2(record.getComputer_id());
	int money =sn.getCard2(computer_id);
	System.out.println("钱是"+money);
	money = money - cost;
	System.out.println("剩余钱是"+money);
	
	sn.updateCard(money,computer_id);
	
    this.hide();
    
  }
  public int getComputer_id(){
	return computer_id1;
  }

  private NetBarFeeMangementFrame mainFrame;

}

class CheckOutDialog_ResetButton_ActionAdapter
    implements java.awt.event.ActionListener {
  CheckOutDialog adaptee;

  CheckOutDialog_ResetButton_ActionAdapter(CheckOutDialog adaptee) {
    this.adaptee = adaptee;
  }

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

class CheckOutDialog_ConfirmButton_ActionAdapter
    implements java.awt.event.ActionListener {
  CheckOutDialog adaptee;

  CheckOutDialog_ConfirmButton_ActionAdapter(CheckOutDialog adaptee) {
    this.adaptee = adaptee;
    
  }

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

⌨️ 快捷键说明

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