소개글
자바로 만든 간단한 도서 관리 프로그램 입니다.주석처리가 되어 있어서 보기가 편합니다.
입력파일도 함께 추가되어 있습니다.
컴파일 실행환경
jdk 1.5.01//eclipse본문내용
import java.awt.*;import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class gui extends JFrame implements ActionListener {
String text1,text2;
JButton[] button;
boolean modify=false; //수정된 곳이 있으면 true
Library library;
public gui(Library l){
library = l;
Dimension dim = getToolkit().getScreenSize();
String[] commands = {"Include a book","Check out","Return book",
"Save","Status","Exit"}; //버튼의 이름
JPanel con = new JPanel(); //버튼을 담을 판넬 생성
con.setLayout(new GridLayout(0,6)); //레이아웃 설정
button = new JButton[commands.length];
for(int a=0;a<commands.length;a++)
{
button[a] = new JButton(commands[a]); //버튼을 생성
button[a].setSize(80,80); //사이즈 정함
button[a].addActionListener(this); //액션리스트 부착
button[a].setRolloverEnabled(true);
con.add(button[a]); //판넬에 버튼 부착
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //exit상태 정함
this.getContentPane().add(con); //프레임에 판넬 부착
this.setSize(800,100); //사이즈 정함
this.setLocation(dim.width/2-this.getWidth()/2,dim.height/2-this.getHeight()/2);
this.setVisible(true); //프레임 그림
}
public static void main(String args[]){
Library lib = new Library();
new gui(lib);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == button[0]){
library.includeBook();
}else if(ae.getSource() == button[1]){
library.checkOutBook();
}else if(ae.getSource() == button[2]){
library.returnBook();
}else if(ae.getSource() == button[3]){
library.save();
JOptionPane.showMessageDialog(null,"Saved"); //저장 메세지 출력
}else if(ae.getSource() == button[4]){
library.status();
}else if(ae.getSource() == button[5]){
if(library.getmodify()){
int a = JOptionPane.showConfirmDialog(null,"저장하시겠습니까?","저장확인",JOptionPane.YES_NO_OPTION);
if(a==0) {library.save();System.exit(0);}
System.exit(0);
}
System.exit(0);
}
}
}
압축파일 내 파일목록
Library.java
state.java
data.txt
gui.java
state.java
data.txt
gui.java