ReportH201562054 전기요금 계산 프로그램 연습

Posted by PeEn
2019. 6. 11. 11:57 Programing/Java

 

package kr.ac.jj.report;


import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;

public class ReportH201562054 extends JFrame implements ActionListener, MouseListener, KeyListener {
	// 전력량 요금 주택용
	final static double FIRSTE = 93.3;
	final static double MIDE = 187.9;
	final static double LASTE = 280.6;

	String name;
	String Rnum;
	int kwh;
	double base_rate;
	double used_rate;
	double elec_rate;
	double rate;
	double sale_price;
	static double amount;

	int padwid = 20; // 가로 여백
	int padhi = 20; // 세로 여백
	int LBwi = 120; // 라벨 가로
	int LBhi = 20; // 라벨 세로

	int row; // 테이블 row
	int col; // 테이블 col
	JLabel lb;
	TextField tfname;
	TextField tfRnum;
	TextField tfkwh;
	TextField tfbaserate;
	TextField tfuse_rate;
	TextField tfeleprice;

	JLabel lbAmount;

	JButton btnSave;
	JButton btnCancel;

	JTable userTable;
	JScrollPane listJs;
	JScrollPane arraylistJs;
	JPanel listPanel;
	DefaultTableModel model;
	Vector userColumn = new Vector();
	Vector useRow;

	String Buf = "";
	JTextArea taBuf;
	JTextArea taH;
	JTextArea taT;

	int count = 0;

	String[][] stdv = { { "길동이", "102호", "150" }, { "길동삼", "103호", "250" }, { "길동사", "201호", "350" },
			{ "길동오", "202호", "500" }, { "길동육", "203호", "440" } };

	public ReportH201562054() {

		Color steelblue = new Color(153, 204, 204);

		// JFrame 설정
		// ================================================
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setSize(885, 460);
		this.setLayout(null);

		// ================================================

		// 버튼 패널
		// ================================================
		JPanel PanelBtn = new JPanel();
		PanelBtn.setLayout(new GridLayout(1, 1));
		PanelBtn.setBounds(padwid, padhi + 310, 320, 50);
		this.add(PanelBtn);
		// ================================================
		// 입력 패널
		// ================================================
		JPanel InputP = new JPanel();
		InputP.setBounds(5, 15, 350, 380);
		InputP.setLayout(null);
		InputP.setBackground(steelblue);
		this.add(InputP);
		// ================================================

		/* ------------------------ 입력패널 ----------------------- */

		// 이름
		// ================================================
		lb = new JLabel("이름");
		lb.setHorizontalAlignment((int) CENTER_ALIGNMENT);
		lb.setBounds(padwid, padhi, LBwi, LBhi);
		lb.setFont(new Font("돋음", Font.BOLD, 20));
		InputP.add(lb);
		// ================================================
		tfname = new TextField();
		tfname.setBounds(padwid + 120, padhi - 5, LBwi + 80, LBhi + 10);
		tfname.addKeyListener(this);
		InputP.add(tfname);
		// ================================================

		// 주소
		lb = new JLabel("호실");
		lb.setBounds(padwid, padhi + 50, LBwi, LBhi);
		lb.setHorizontalAlignment((int) CENTER_ALIGNMENT);
		lb.setFont(new Font("돋음", Font.BOLD, 20));
		InputP.add(lb);
		// ================================================
		tfRnum = new TextField();
		tfRnum.setBounds(padwid + 120, padhi + 45, LBwi + 80, LBhi + 10);
		tfRnum.addKeyListener(this);
		InputP.add(tfRnum);
		// ================================================

		// 사용량
		// ================================================
		lb = new JLabel("사용량");
		lb.setBounds(padwid, padhi + 100, LBwi, LBhi);
		lb.setHorizontalAlignment((int) CENTER_ALIGNMENT);
		lb.setFont(new Font("돋음", Font.BOLD, 20));
		InputP.add(lb);
		// ================================================
		tfkwh = new TextField();
		tfkwh.setBounds(padwid + 120, padhi + 95, LBwi + 80, LBhi + 10);
		tfkwh.addKeyListener(this);
		InputP.add(tfkwh);
		// ================================================

		// 기본요금
		// ================================================
		lb = new JLabel("기본요금");
		lb.setBounds(padwid, padhi + 150, LBwi, LBhi);
		lb.setHorizontalAlignment((int) CENTER_ALIGNMENT);
		lb.setFont(new Font("돋음", Font.BOLD, 20));
		InputP.add(lb);
		// ================================================
		tfbaserate = new TextField();
		tfbaserate.setBounds(padwid + 120, padhi + 145, LBwi + 80, LBhi + 10);
		tfbaserate.setEditable(false);
		InputP.add(tfbaserate);
		// ================================================

		// 전력량요금
		// ================================================
		lb = new JLabel("전력량 요금");
		lb.setBounds(padwid, padhi + 200, LBwi, LBhi);
		lb.setHorizontalAlignment((int) CENTER_ALIGNMENT);
		lb.setFont(new Font("돋음", Font.BOLD, 20));
		InputP.add(lb);
		// ================================================
		tfuse_rate = new TextField();
		tfuse_rate.setBounds(padwid + 120, padhi + 195, LBwi + 80, LBhi + 10);
		tfuse_rate.setEditable(false);
		InputP.add(tfuse_rate);
		// ================================================

		// 전기요금
		// ================================================
		lb = new JLabel("전기 요금");
		lb.setBounds(padwid, padhi + 250, LBwi, LBhi);
		lb.setHorizontalAlignment((int) CENTER_ALIGNMENT);
		lb.setFont(new Font("돋음", Font.BOLD, 20));
		InputP.add(lb);
		// ================================================
		tfeleprice = new TextField();
		tfeleprice.setBounds(padwid + 120, padhi + 245, LBwi + 80, LBhi + 10);
		tfeleprice.setEditable(false);
		InputP.add(tfeleprice);
		// ================================================

		// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//

		/* ------------------------ 버튼 패널 ----------------------- */
		// 저장 버튼
		// ================================================
		btnSave = new JButton("저장");
		btnSave.setFont(new Font("돋음", Font.BOLD, 20));
		btnSave.addActionListener(this);
		PanelBtn.add(btnSave);
		// ================================================

		taH = new JTextArea("");
		taH.setBounds(370, 20, 485, 20);
		taH.setEditable(false);
		this.add(taH);

		taT = new JTextArea("");
		taT.setBounds(370, padhi + 340, 485, 30);
		taT.setEditable(false);
		taT.setFont(new Font("돋음", Font.BOLD, 20));
		this.add(taT);

		// 출력 패널
		// ================================================
		JPanel OutP = new JPanel();
		OutP.setBounds(350, 35, 605, 600);
		OutP.setLayout(null);
		this.add(OutP);
		// ================================================
		/* ------------------------ 출력 패널 ----------------------- */

		taBuf = new JTextArea();
		taBuf.setEditable(false);
		arraylistJs = new JScrollPane(taBuf);
		arraylistJs.setBounds(padwid, padhi - 5, 480, 300);
		OutP.add(arraylistJs);

		// ==================================================
		this.setVisible(true);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new ReportH201562054();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		switch (e.getActionCommand()) {
		case "저장":
			if (count == 0)
				stdvalue();

			ElecCarge201562054 e2 = new ElecCarge201562054(kwh);
			this.base_rate = e2.base_rate;
			this.used_rate = e2.used_rate;
			this.elec_rate = e2.elec_rate;

			tfbaserate.setText(String.format("%.2f", base_rate));
			tfuse_rate.setText(String.format("%.2f", used_rate));
			tfeleprice.setText(String.format("%.2f", elec_rate));

			if (Buf.compareTo("") == 0) {
			} else {
				stdvalue();
				taBuf.setText(Buf);
				taH.setText("이름\t주소\t사용량\t기본요금\t전력양요금\t전기요금");
				taT.setText("전체 요금\t\t\t" + String.format("%.2f", amount));
			}
			break;
		case "str저장":

			break;

		default:
			break;
		}

	}

	public void stdvalue() {
		ElecCarge201562054 e1 = new ElecCarge201562054(kwh);
		this.base_rate = e1.base_rate;
		this.used_rate = e1.used_rate;
		this.elec_rate = e1.elec_rate;
		e1.Calc();

		if (count == 0) {
			for (int i = 0; i < 5; i++) {

				this.name = stdv[i][0];
				this.Rnum = stdv[i][1];
				this.kwh = Integer.parseInt(stdv[i][2]);

				Buf += this.name + "\t" + this.Rnum + "\t" + this.kwh + "\t" + this.base_rate + "\t" + this.used_rate
						+ "\t" + this.elec_rate + "\n";
				amount += elec_rate;
				count += 1;
			}
		} else {
			Buf = this.name + "\t" + this.Rnum + "\t" + this.kwh + "\t" + String.format("%.2f", this.base_rate) + "\t"
					+ String.format("%.2f", this.used_rate) + "\t" + String.format("%.2f", this.elec_rate) + "\n" + Buf;
			amount += elec_rate;
			count += 1;
		}
	}

	@Override
	public void keyTyped(KeyEvent e) {
	}

	@Override
	public void keyPressed(KeyEvent e) {
	}

	@Override
	public void keyReleased(KeyEvent e) {
		try {
			if (e.getExtendedKeyCode() == 10) {
				if (Double.parseDouble(tfkwh.getText()) >= 1)
					btnSave.doClick();
				else {
				}

			}
		} catch (Exception e1) {

		}
	}

	@Override
	public void mouseClicked(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

}


}

'Programing > Java' 카테고리의 다른 글

JAVA DB SQLITE DELETE  (0) 2019.07.30
JAVA DB SQLITE INSERT  (0) 2019.07.30
ReportF201562054 도서 저장 프로그램 연습  (0) 2019.06.11
ReportF, ReportH 파일  (0) 2019.06.08
채팅 프로그램  (0) 2019.05.31