ReportF201562054 도서 저장 프로그램 연습

Posted by PeEn
2019. 6. 11. 11:49 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.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.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;

public class ReportF201562054 extends JFrame implements ActionListener, MouseListener, KeyListener {
	JTextArea taH;
	JTextArea taT;
	String Bname;
	String writher;
	String publisher;
	int year;
	int price;
	double rate;
	double sale_price;
	static double amount;

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

	int row; // 테이블 row
	int col; // 테이블 col
	JLabel lb;
	TextField tfBname;
	TextField tfBwriter;
	TextField tfBpubl;
	TextField tfyear;
	TextField tfprice;

	JLabel lbAmount;

	JButton btnSave;
	JButton btnCancel;

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

	String Buf = "";
	JTextArea taBuf;

	public ReportF201562054() {

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

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

		// 버튼 패널
		// ================================================
		JPanel PanelBtn = new JPanel();
		PanelBtn.setLayout(new GridLayout(1, 1));
		PanelBtn.setBounds(padwid, padhi + 270, 290, 70);
		this.add(PanelBtn);
		// ================================================
		// 입력 패널
		// ================================================
		JPanel InputP = new JPanel();
		InputP.setBounds(5, 15, 300, 390);
		InputP.setLayout(null);
		InputP.setBackground(steelblue);
		this.add(InputP);
		// ================================================

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

		// 책 제목
		// ================================================
		lb = new JLabel("책제목");
		lb.setBounds(padwid, padhi, LBwi, LBhi);
		lb.setHorizontalAlignment((int) CENTER_ALIGNMENT);
		lb.setFont(new Font("돋음", Font.BOLD, 20));
		InputP.add(lb);
		// ================================================
		tfBname = new TextField();
		tfBname.setBounds(padwid + 95, padhi - 5, LBwi + 80, LBhi + 10);
		tfBname.addKeyListener(this);
		InputP.add(tfBname);
		// ================================================

		// 책 저자
		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);
		// ================================================
		tfBwriter = new TextField();
		tfBwriter.setBounds(padwid + 95, padhi + 45, LBwi + 80, LBhi + 10);
		tfBwriter.addKeyListener(this);
		InputP.add(tfBwriter);
		// ================================================

		// 출판사
		// ================================================
		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);
		// ================================================
		tfBpubl = new TextField();
		tfBpubl.setBounds(padwid + 95, padhi + 95, LBwi + 80, LBhi + 10);
		tfBpubl.addKeyListener(this);
		InputP.add(tfBpubl);
		// ================================================

		// 출판년도
		// ================================================
		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);
		// ================================================
		tfyear = new TextField();
		tfyear.setBounds(padwid + 95, padhi + 145, LBwi + 80, LBhi + 10);
		tfyear.addKeyListener(this);
		InputP.add(tfyear);
		// ================================================

		// 가격
		// ================================================
		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);
		// ================================================
		tfprice = new TextField();
		tfprice.setBounds(padwid + 95, padhi + 195, LBwi + 80, LBhi + 10);
		tfprice.addKeyListener(this);
		InputP.add(tfprice);
		// ================================================
		// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//

		/* ------------------------ 버튼 패널 ----------------------- */

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

		// 머릿말
		// ===============================================
		JPanel HeadP = new JPanel();
		HeadP.setBounds(310, 10, 700, LBhi + 30);
		HeadP.setLayout(null);
		this.add(HeadP);
		// ==============================================

		// 출력 패널
		// ================================================
		JPanel OutP = new JPanel();
		OutP.setBounds(310, 10, 700, 800);
		OutP.setLayout(null);
		this.add(OutP);
		// ================================================

		/* ------------------------ 출력 패널 ----------------------- */

		taH = new JTextArea();
		taH.setBounds(8, 5, 580, 30);
		taH.setEditable(false);
		HeadP.add(taH);

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

		// 전체 가격
		taT = new JTextArea();
		taT.setBounds(padwid, padhi + 15 + 300, 580, 30);
		taT.setFont(new Font("돋음", Font.BOLD, 20));
		taT.setEditable(false);
		OutP.add(taT);

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

		taBuf = new JTextArea();
		taBuf.setEditable(false);
		taBuf.setBackground(Color.white);

		JScrollPane js = new JScrollPane(taBuf);
		js.setBounds(320, padhi + 5, 585, 310);
		this.add(js);

		this.setVisible(true);
	}

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

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		switch (e.getActionCommand()) {
		case "저장":
			this.Bname = tfBname.getText();
			this.writher = tfBwriter.getText();
			this.publisher = tfBpubl.getText();
			this.year = Integer.parseInt(tfyear.getText());
			this.price = Integer.parseInt(tfprice.getText());

			Book201562054 b1 = new Book201562054(year, price);
			this.rate = b1.rate * 100;
			this.sale_price = b1.sale_price;
			this.amount = b1.amount;
			if (Buf.compareTo("") == 0) {
				Buf = this.Bname + "\t" + this.writher + "\t" + this.publisher + "\t" + this.year + "\t" + this.price
						+ "\t" + String.format("%.0f", this.rate) + "%" + "\t" + String.format("%.2f", this.sale_price);
				taBuf.setText(Buf);
			} else {
				Buf = Buf + "\n" + this.Bname + "\t" + this.writher + "\t" + this.publisher + "\t" + this.year + "\t"
						+ this.price + "\t" + String.format("%.0f", this.rate) + "%" + "\t"
						+ String.format("%.2f", this.sale_price);
				taBuf.setText(Buf);
			}
			if (Buf.compareTo("") == 0) {
			} else
				taH.setText("책제목\t저자\t출판사\t출판년도\t가격\t할인율\t할인금액");
			taT.setText("전체 가격\t\t\t" + String.format("%.2f", amount));

			break;
		case "str저장":

			break;

		default:
			break;
		}

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		JTable tb = (JTable) e.getSource();
		row = tb.getSelectedRow();
		col = tb.getSelectedColumn();

		System.out.print(e.getPoint() + " " + row + " " + col);
	}

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

	@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(tfyear.getText()) >= 1 && Double.parseDouble(tfprice.getText()) >= 1)
					btnSave.doClick();
				else {
				}

			}
		} catch (Exception e1) {

		}
	}

}



}

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

JAVA DB SQLITE INSERT  (0) 2019.07.30
ReportH201562054 전기요금 계산 프로그램 연습  (0) 2019.06.11
ReportF, ReportH 파일  (0) 2019.06.08
채팅 프로그램  (0) 2019.05.31
레이아웃 생성자로 만들기  (0) 2019.05.31