jasu's blog
블로그 메뉴글
ImagePuzzle Game Project
어 플리케이션으로서 그럴듯 하게 디자인도 해서 넣어보고 게임의 순위도 사용자 컴퓨터에 저장할 수 있도록 하였고, 무엇보다도 이미지는 프로그램상에 존재하는 것이 아니라 사용자 컴퓨터에서 이미지를 검색하여 그 이미지를 사용하여 게임을 진행할 수 있도록 한 점이 특징이다, 이때 이미지만을 축출하여 리스트로 표현하는 로직을 구현할 때 재귀함수를 사용하여 하위 디렉토리를 탐색하는 방식을 사용했는데 그때 아마도 재귀함수의 짧은 코드로서의 단순성에 반해 엄청난 결과를 창출한다는 것을 알게 되었는데 속도 면에서는 영 마음에 들지 않았던 기억이다.
아무튼 이 게임 하나 만든다고 학과 컴퓨터실에서 알바를 하며 밤 늦게까지 혼자만의 재미에 푹 빠져 살았던 시절이 그립기도 하다. 물론 지금도 그런 놀이속에 살고는 있지만...
뭐.. 누가 그랬던가 돈이 있어도 지하철을 타는 것과 돈이 없어서 지하철을 타는 것은 모두 지하철을 탄다는 것은 같으나 그 마음은 다르다고.... 아마도 그 재미는 비슷하나 그때의 젊음속에서 느꼈던 것과는 다른 것 같은 생각이 든다. 아무래도 돈과 관련이 있는 것과 나이와 관련이 있는, 이 두가지 때문이 아닐까...쿠쿠
프로젝트 프리젠테이션
게임 인스톨 파일
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import sun.audio.*;
import java.io.*;
import java.util.*;
import java.applet.*;
public final class ImagePuzzle extends Frame implements ItemListener{
ImagePuzzle imagepuzzle;
JPanel p_main,p_board;
jpanel p[];
JPanel p_center;
P_up p_up;
File file;
File dir;
ImageSam_1 image_rect;
P_down p_down;
P_west p_west;
P_east p_east;
final String col[]={"Rank","Name","Score"};
String data[][];
String user_name;
Best_Record br;
Tab_3 tab3;
Tab_5 tab5;
Tab_7 tab7;
Tab_9 tab9;
Remove_Check remove_check;
Image_state button_set1_image;
int point_count;
Image_Setting open;
int i_font=1;
java.awt.List list1,list2;
String file_name;
String file_name_ready;
String item;
String list[];
String list_list[];
int list_count;
TextField file_textfield;
Color cc142;
JButton start_button;
JButton next_button;
jpanel pp;
boolean box;
String str;
String path_root;
static CheckboxMenuItem sound_check;
static CheckboxMenuItem number_check;
Choice root_choice,dir_choice;
User user_view;
InputStream in_back;
InputStream in_replay;
InputStream in_start;
JTextField display_file; //오른쪽 위에 나오는 그림 이미지 파일 이름 표시
About about;
AudioStream sound_back;
AudioStream sound_replay;
AudioStream sound_start;
static boolean num_check;
Image state_back_ground;
ImageSam image_sam; //비교할 이미지 샘플사진 판넬
Image sample;
JLabel Title;
state p_state;
Image image_state;
Color color=new Color(204,204,204);
int check[];
static int block_check=9;Color c;
int intcheck=0,isize=0,jsize=0;
actionhandler ahandler;
BevelBorder bevelborder;
EtchedBorder etchborder;
Key_handler key_event;
ImagePuzzle(String name,CheckboxMenuItem sound_check,String file_name,int list_count,String path_root,String user_name){
super(name);
this.file_name=file_name;
this.list_count=list_count;
this.path_root=path_root;
data=new String[9][3];
for(int i=1;i<=9;i++)
data[i-1][0]="No "+i;
this.user_name=user_name;
user_view=new User("User name");
point_count=0;
tab3=new Tab_3();
image_state=Toolkit.getDefaultToolkit().getImage(file_name);
key_event=new Key_handler();
addKeyListener(key_event);
cc142=new Color(142,142,142);
list1 = new java.awt.List(2, false);
list2 = new java.awt.List(2, false);
sound_set();
read("score/tab3.ser");
tab3.tab3_proc();
start_button=new JButton("Start");
next_button=new JButton("Next");
next_button.addActionListener(new actionhandler_button());
start_button.addActionListener(new actionhandler_button());
start_button.setVisible(true);
num_check=false;
image_sam=new ImageSam();
image_sam.setSize(250,250);
bevelborder=new BevelBorder(BevelBorder.RAISED);
etchborder=new EtchedBorder(EtchedBorder.RAISED);
ahandler=new actionhandler();
Title=new JLabel("=====================");
Title.setBackground(new Color(204,204,204));
MenuBar mb=new MenuBar();
Menu gameMenu=new Menu("Game");
itemAdd("New Game",gameMenu);
gameMenu.addSeparator();
itemAdd("Best Record",gameMenu);
gameMenu.addSeparator();
itemAdd("Record Remove",gameMenu);
itemAdd("Exit",gameMenu);
Menu optionMenu=new Menu("Option");
Menu matrixMenu=new Menu("Matrix");
optionMenu.add(matrixMenu);
itemAdd("3 X 3",matrixMenu);
itemAdd("4 X 4",matrixMenu);
itemAdd("5 X 5",matrixMenu);
itemAdd("6 X 6",matrixMenu);
itemAdd("7 X 7",matrixMenu);
itemAdd("8 X 8",matrixMenu);
itemAdd("9 X 9",matrixMenu);
optionMenu.addSeparator();
this.sound_check=sound_check;
optionMenu.add(sound_check);
number_check=new CheckboxMenuItem("Number");
optionMenu.add(number_check);
optionMenu.addSeparator();
itemAdd("User Change",optionMenu);
itemAdd("Image Setting",optionMenu);
Menu helpMenu=new Menu("Help");
MenuItem mi=new MenuItem("Homepage...");
mi.addActionListener(new homepage_actionhandler());
helpMenu.add(mi);
helpMenu.addSeparator();
itemAdd("About Image...",helpMenu);
Color block_color=new Color(92,112,139);
mb.add(gameMenu);
mb.add(optionMenu);
mb.add(helpMenu);
setMenuBar(mb);
p_up=new P_up();
p_down=new P_down(); //메인 화면에서의 테두리
p_east=new P_east();
p_west=new P_west();
p_up.setBackground(block_color);
p_down.setBackground(block_color);
p_east.setBackground(block_color);
p_west.setBackground(block_color);
p_center=new JPanel();
p_center.setSize(550,400);
p_board=new JPanel();
p_main=new JPanel();
p_state=new state();
p_state.setSize(150,400); //p_state 는 오른쪽 샘플 그림과 아하 버튼
p_state.setLayout(new GridLayout(3,2));
p_state.add(image_sam);
display_file=new JTextField(20);
display_file.setEnabled(false);
JPanel button_set1=new JPanel();
JPanel button_set2=new JPanel();
button_set1.setLayout(new BorderLayout());
button_set1.setBorder(bevelborder);
button_set2.setLayout(new BorderLayout());
button_set1_image=new Image_state("background/state.jpg");
Panel button_set1_button=new Panel();
Panel button_set1_uplabel=new Panel();
button_set1_image.setSize(200,200);
button_set1_button.setLayout(new GridLayout(1,2));
button_set1.add(start_button);
button_set1.add(next_button); //button_set1 은 가운데 판넬
button_set1_uplabel.add(display_file);
button_set1_button.add(start_button);
button_set1_button.add(next_button);
button_set1.add(button_set1_uplabel,BorderLayout.NORTH);
button_set1.add(button_set1_image,BorderLayout.CENTER);
button_set2.add(button_set1_button,BorderLayout.NORTH);
p_state.add(button_set1);
p_state.add(button_set2);
number_check.addItemListener(this);
p_main.setBorder(bevelborder);
check=new int[block_check];
p=new jpanel[block_check];
p_board.setLayout(new BorderLayout());
p_board.add(p_main,BorderLayout.CENTER);
p_center.setLayout(new BorderLayout());
p_center.add(p_board,BorderLayout.CENTER);
p_center.add(p_state,BorderLayout.EAST);
add(p_up,BorderLayout.NORTH);
add(p_center,BorderLayout.CENTER);
add(p_down,BorderLayout.SOUTH);
add(p_west,BorderLayout.WEST);
add(p_east,BorderLayout.EAST);
addWindowListener(new windowhandler());
file_find();
proc();
}
public void itemStateChanged(ItemEvent ie){
for(int i=0;i<block_check;i++)
p[i].repaint();
}
final class Key_handler implements KeyListener{
public void keyPressed(KeyEvent ke){
}
public void keyReleased(KeyEvent ke){
}
public void keyTyped(KeyEvent ke){
}
}
public void sound_set(){
try{
in_replay=new FileInputStream("sound/replay.wav");
in_start=new FileInputStream("sound/start.wav");
sound_back=new AudioStream(in_back);
sound_replay=new AudioStream(in_replay);
sound_start=new AudioStream(in_start);
}catch(Exception e){}
}
public void proc(){
try{ in_replay.close();
in_replay=new FileInputStream("sound/replay.wav");
sound_replay=new AudioStream(in_replay);
if(sound_check.getState())
AudioPlayer.player.start(sound_replay);
}catch(Exception e){}
int k=0;
int i,j;
for(i=0;i<check.length;i++)
check[i]=i;
check[check.length-1]=check.length-1;
if(p.length==9){
intcheck=3;
p_main.setLayout(new GridLayout(3,3));
read("score/tab3.ser");
}else if(p.length==16){
intcheck=4;
p_main.setLayout(new GridLayout(4,4));
read("score/tab4.ser");
}else if(p.length==25){
intcheck=5;
p_main.setLayout(new GridLayout(5,5));
read("score/tab5.ser");
}else if(p.length==36){
intcheck=6;
p_main.setLayout(new GridLayout(6,6));
read("score/tab6.ser");
}else if(p.length==49){
intcheck=7;
p_main.setLayout(new GridLayout(7,7));
read("score/tab7.ser");
}else if(p.length==64){
intcheck=8;
p_main.setLayout(new GridLayout(8,8));
read("score/tab8.ser");
}else if(p.length==81){
intcheck=9;
p_main.setLayout(new GridLayout(9,9));
read("score/tab9.ser");
}
Color out_side=new Color(203,203,203);
for(i=0;i<p.length;i++){
p[i]=new jpanel(i);
if(i<p.length-1)
p[i].setBackground(out_side);
else p[i].setBackground(color);
p[i].addMouseListener(new mousehandler());
p_main.add(p[i]);
}
for(i=0;i<p.length;i++)
p[i].setEnabled(false);
item=file_name;
replay_proc();
}
final class homepage_actionhandler implements ActionListener{
public void actionPerformed(ActionEvent e) {
Runtime run = Runtime.getRuntime();
try{
run.exec("c:/Program Files/Internet Explorer/Iexplore.exe http://www.n-collection.com");
}
catch(Exception ioe) {System.out.println(ioe+"Connecting Error.");}
}
}
private void itemAdd(String title,Menu m){
MenuItem mi=new MenuItem(title);
mi.addActionListener(ahandler);
m.add(mi);
}
final class state extends JPanel{
state(){
}
}
final class P_up extends Panel{
}
final class P_down extends Panel{
}
final class P_west extends Panel{
}
final class P_east extends Panel{
}
final class ImageSam extends Panel{ // 오른쪽 이미지 그리는 루틴
public void paint(Graphics g){
g.drawImage(
image_state,
6,
7,
getWidth()-6,
getHeight()-7,
0,
0,
(image_state.getWidth(this)),
(image_state.getHeight(this)),
this);
g.setColor(Color.white);
for(int j=0;j<6;j++){
g.drawLine(j,j,this.getWidth()-j,j);
g.drawLine(j,j,j,this.getHeight()-j);
}
g.setColor(cc142);
for(int j=0;j<7;j++){
g.drawLine(this.getWidth()-j,j,this.getWidth()-j,this.getHeight()-j);
g.drawLine(j,this.getHeight()-j,this.getWidth()-j,this.getHeight()-j);
}
}
}
final class jpanel extends Panel{ //블럭 각각을 그리는 루틴
private int cont;
int i;
public int isize_loc;
public int jsize_loc;
Font font;
Color cc100;
jpanel(int i){
font=new Font("SansSerif",Font.BOLD,17);
cc100=new Color(100,100,100);
isize_loc=9;
jsize_loc=9;
this.i=i;
this.cont=i_font++;
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
if(isize_loc==9)
isize_loc=isize;
if((i!=block_check-1)&&(getBackground()!=color)){
if(jsize_loc==9)
if((isize)%(intcheck)==0){
if(isize!=0){
jsize++;
if(jsize_loc==9)
jsize_loc=jsize;
}
isize_loc=isize=0;
if(jsize_loc==9)
jsize_loc=jsize;
if(isize_loc==9)
isize_loc=0;
}
if(jsize_loc==9){
jsize_loc=jsize;}
g.drawImage(
image_state,
0,
0,
getWidth(),
getHeight(),
(image_state.getWidth(this)/intcheck)*isize_loc,
(image_state.getHeight(this)/intcheck)*jsize_loc,
(image_state.getWidth(this)/intcheck)*isize_loc+(image_state.getWidth(this)/intcheck),
(image_state.getHeight(this)/intcheck)*jsize_loc+(image_state.getHeight(this)/intcheck),
this);
isize++;
}else{ isize=0;jsize=0;}
g.setFont(font);
if(cont!=block_check)
if(number_check.getState()){
g.drawString(String.valueOf(cont),(getWidth()/2)-3,(getHeight()/2)+5);
}
g.setColor(Color.white);
for(int j=0;j<1;j++){
g.drawLine(j,j,this.getWidth()-j,j);
g.drawLine(j,j,j,this.getHeight()-j);
}
g.setColor(cc100);
for(int j=0;j<2;j++){
g.drawLine(this.getWidth()-j,j,this.getWidth()-j,this.getHeight()-j);
g.drawLine(j,this.getHeight()-j,this.getWidth()-j,this.getHeight()-j);
}
}
}
final class actionhandler implements ActionListener{
public void actionPerformed(ActionEvent ae){
MenuItem mi=(MenuItem)ae.getSource();
if(mi.getLabel()=="3 X 3"){
block_check=9;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}else if(mi.getLabel()=="4 X 4"){
block_check=16;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}else if(mi.getLabel()=="5 X 5"){
block_check=25;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}else if(mi.getLabel()=="6 X 6"){
block_check=36;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}else if(mi.getLabel()=="7 X 7"){
block_check=49;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}else if(mi.getLabel()=="8 X 8"){
block_check=64;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}else if(mi.getLabel()=="9 X 9"){
block_check=81;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}
if(mi.getLabel()=="New Game"){
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}
if(mi.getLabel()=="Record Remove"){
remove_check=new Remove_Check("Record Remove Check");
remove_check.setBounds(300,300,250,200);
remove_check.show();
}
if(mi.getLabel()=="Best Record"){
br=new Best_Record("Best Record");
br.setBounds(250,260,400,220);
br.addWindowListener(new Best_windowhandler());
br.show();
}
if(mi.getLabel()=="Exit"){
System.exit(0);
}
if(mi.getLabel()=="Number"){
num_check=true;
dispose();
System.gc();
imagepuzzle=new ImagePuzzle("Image Puzzle",sound_check,file_name,list_count,path_root,user_name);
imagepuzzle.setBounds(65,65,900,600);
imagepuzzle.show();
}
if(mi.getLabel()=="User Change"){
user_view.view();
}
if(mi.getLabel()=="Image Setting"){
open=new Image_Setting();
open.addWindowListener(new Open_windowhandler());
open.setBounds(79,118,638,553);
open.show();
}
if (mi.getLabel()=="About Image..."){
about=new About("Image Puzzle Info");
about.addWindowListener(new About_windowhandler());
about.setBounds(300,230,400,300);
about.show();
}
}
}
final class About_windowhandler extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
about.dispose();
}
}
final class About extends Frame // About 이미지 그리는 루틴
{
About(String name)
{
super(name);
}
public void paint(Graphics g){
sample=Toolkit.getDefaultToolkit().getImage("background/about.jpg");
g.drawImage(
sample,
0,
0,
getWidth(),
getHeight(),
0,
0,
(sample.getWidth(this)),
(sample.getHeight(this)),
this);
g.setColor(Color.white);
for(int j=0;j<5;j++){
g.drawLine(j,j,this.getWidth()-j,j);
g.drawLine(j,j,j,this.getHeight()-j);
}
g.setColor(cc142);
for(int j=0;j<5;j++){
g.drawLine(this.getWidth()-j,j,this.getWidth()-j,this.getHeight()-j);
g.drawLine(j,this.getHeight()-j,this.getWidth()-j,this.getHeight()-j);
}
}
}
final class ImageSam_1 extends Panel{
//왼쪽 블럭 그림 그리는 루틴
public void paint(Graphics g){
sample=Toolkit.getDefaultToolkit().getImage(item);
g.drawImage(
sample,
50,
60,
getWidth()-50,
getHeight()-60,
0,
0,
(sample.getWidth(this)),
(sample.getHeight(this)),
this);
g.setColor(Color.white);
for(int j=50;j<54;j++){
g.drawLine(j,j+5,this.getWidth()-j,j+5);
g.drawLine(j,j+5,j,this.getHeight()-j-6);
}
g.setColor(cc142);
for(int j=50;j<54;j++){
g.drawLine(this.getWidth()-j,j+5,this.getWidth()-j,this.getHeight()-j-7);
g.drawLine(j,this.getHeight()-j-7,this.getWidth()-j,this.getHeight()-j-7);
}
}
}
final class Image_state extends Panel{
Graphics g;
String item;
Image_state(String item){
this.item=item;
}
public void paint(Graphics g){
this.g=g;
sample=Toolkit.getDefaultToolkit().getImage(item);
g.drawImage(
sample,
0,
0,
getWidth(),
getHeight(),
0,
0,
(sample.getWidth(this)),
(sample.getHeight(this)),
this);
g.setColor(Color.white);
for(int j=0;j<3;j++){
g.drawLine(j,j,this.getWidth()-j,j);
g.drawLine(j,j,j,this.getHeight()-j);
}
g.setColor(cc142);
for(int j=0;j<3;j++){
g.drawLine(this.getWidth()-j,j,this.getWidth()-j,this.getHeight()-j);
g.drawLine(j,this.getHeight()-j,this.getWidth()-j,this.getHeight()-j);
}
point();
}
public void point(){ // 최대 점수와 사용자 점수를 보여주는 화면
g.setFont(new Font("SansSerif",Font.PLAIN,22));
Color back_color=new Color(183,211,186);
Color font_color=new Color(25,52,118);
g.setColor(font_color);
g.drawString(data[0][2],((this.getWidth()/2)-95),(this.getHeight()/2)-20);
g.drawString(String.valueOf(point_count),((this.getWidth()/2)-95),(this.getHeight()/2)+29);
g.setColor(back_color);
}
}
final class list1handler implements ItemListener{ //디렉토리 리스트
public void itemStateChanged(ItemEvent ie){
String item=list1.getSelectedItem();
path_root=(file.getAbsolutePath()+"/"+item);
list_count=0;
list1.removeAll();
list2.removeAll();
file_textfield.setText("");
file_find();
}
}
final class list2handler implements ItemListener{ //파일 리스트
public void itemStateChanged(ItemEvent ie){
item=file.getAbsolutePath()+"/"+list2.getSelectedItem();
list_count=0;
file_textfield.setText(list2.getSelectedItem());
file_name_ready=item;
sample=Toolkit.getDefaultToolkit().getImage(item);
image_rect.repaint();
}
}
final class root_choice_handler implements ItemListener{
public void itemStateChanged(ItemEvent ie){
if(root_choice.getSelectedItem()=="A:/ 플로피 디스크"){
path_root="a:/";
file_find();
}
if(root_choice.getSelectedItem()=="C:/ 로컬 디스크"){
path_root="c:/";
file_find();
}
if(root_choice.getSelectedItem()=="D:/ 로컬 디스크"){
path_root="d:/";
file_find();
}
if(root_choice.getSelectedItem()=="E:/ 로컬 디스크"){
path_root="e:/";
file_find();
}
list1.removeAll();
list2.removeAll();
file_textfield.setText("");
file_find();
}
}
final class mousehandler extends MouseAdapter{
int itemp;
int count;
int i,j;
public void mousePressed(MouseEvent me){
pp=(jpanel)me.getSource();
count=0;
itemp=0;
i=j=0;
for(i=0;i<p.length;i++){
if(pp.equals(p[i])){
c=(Color)p[i].getBackground();
break;
}
}
for(j=0;j<p.length;j++){
if(color.equals((Color)p[j].getBackground()))
if(j==i-1||j==i+1||j==i+intcheck||j==i-intcheck)
if(!(((i%intcheck)==0)&&(j==(i-1))))
if(!(((j%intcheck)==0)&&(j==(i+1)))){
if(pp.getBackground()!=color){
point_count++;
button_set1_image.repaint();
}
itemp=check[i];
check[i]=check[j];
check[j]=itemp;
itemp=p[i].jsize_loc;
p[i].jsize_loc=p[j].jsize_loc;
p[j].jsize_loc=itemp;
itemp=p[i].isize_loc;
p[i].isize_loc=p[j].isize_loc;
p[j].isize_loc=itemp;
itemp=p[i].cont;
p[i].cont=p[j].cont;
p[j].cont=itemp;
p[j].setBackground(c);
p[i].setBackground(color);
p[i].i=block_check-1;
p[i].repaint();
p[j].i=block_check;
p[j].repaint();
for(int k=0;k<check.length;k++){
if(check[k]==count) {
count++;
}else {count=0;}
}
if(count==p.length){ // 답을 얻었을 때
count=0;
try{
InputStream in_winner=new FileInputStream("sound/winner.wav");
AudioStream sound_winner=new AudioStream(in_winner);
if(sound_check.getState())
AudioPlayer.player.start(sound_winner);
}catch(Exception e){}
int level;
for(level=0;level<9;level++)
if(data[level][2]==null) break;
if(level==0){ //처음 자료를 등록할 때
data[level][2]=String.valueOf(point_count);
data[level][1]=user_name;
}else{
for(int z=0;z<=level-1;z++){
if(Integer.parseInt(data[z][2])>point_count){
for(int y=level;y>z;y--){ //순위에 따라 레코드를 바꿔줌
if(y<=8){
data[y][1]=data[y-1][1];
data[y][2]=data[y-1][2];
}else{
data[y-1][1]=data[y-2][1];
data[y-1][2]=data[y-2][2];
}
}
data[z][2]=String.valueOf(point_count);
data[z][1]=user_name;
break;
}else{
if(level<9){
data[level][2]=String.valueOf(point_count);
data[level][1]=user_name;
}
}
}
}
if(intcheck==3){
write("score/tab3.ser");
read("score/tab3.ser");
}else if(intcheck==4){
write("score/tab4.ser");
read("score/tab4.ser");
}else if(intcheck==5){
write("score/tab5.ser");
read("score/tab5.ser");
}else if(intcheck==6){
write("score/tab6.ser");
read("score/tab6.ser");
}else if(intcheck==7){
write("score/tab7.ser");
read("score/tab7.ser");
}else if(intcheck==8){
write("score/tab8.ser");
read("score/tab8.ser");
}else if(intcheck==9){
write("score/tab9.ser");
read("score/tab9.ser");
}
start_button.setEnabled(true);
next_button.setEnabled(true);
break;
}else count=0;
}
}
}
}
public void write(String f_name){
try{
FileOutputStream f_out=new FileOutputStream(f_name);
ObjectOutputStream objectout=new ObjectOutputStream(f_out);
objectout.writeObject(data);
objectout.close();
}
catch(Exception e){e.printStackTrace();}
}
public void read(String f_name){
try{
FileInputStream f_in=new FileInputStream(f_name);
ObjectInputStream objectin=new ObjectInputStream(f_in);
data=(String[][])objectin.readObject();
}
catch(Exception e){e.printStackTrace();}
}
final class User extends Frame implements ActionListener{
TextField user_text;
JButton user_ok;
JPanel down;
user_image image;
User(String name){
super(name);
setLayout(new BorderLayout());
down=new JPanel();
user_text=new TextField();
user_ok=new JButton("OK");
image=new user_image();
down.setLayout(new BorderLayout());
down.add(user_text,BorderLayout.CENTER);
down.add(user_ok,BorderLayout.EAST);
add(image,BorderLayout.CENTER);
add(down,BorderLayout.SOUTH);
user_ok.addActionListener(this);
addWindowListener(new user_windowhandler());
user_ok.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
JButton ok=(JButton)ae.getSource();
if(ok.getLabel()=="OK"){
user_name=user_text.getText();
dispose();
}
}
public void view(){
setBounds(350,270,300,200);
show();
}
final class user_image extends JPanel{
user_image(){
}
public void paint(Graphics g){
sample=Toolkit.getDefaultToolkit().getImage("background/user.jpg");
g.drawImage(
sample,
0,
0,
getWidth(),
getHeight(),
0,
0,
(sample.getWidth(this)),
(sample.getHeight(this)),
this);
g.setColor(Color.white);
for(int j=0;j<2;j++){
g.drawLine(j,j,this.getWidth()-j,j);
g.drawLine(j,j,j,this.getHeight()-j);
}
g.setColor(cc142);
for(int j=0;j<2;j++){
g.drawLine(this.getWidth()-j,j,this.getWidth()-j,this.getHeight()-j);
g.drawLine(j,this.getHeight()-j,this.getWidth()-j,this.getHeight()-j);
}
}
}
final class user_windowhandler extends WindowAdapter{
public void windowClosing(WindowEvent we){
dispose();
}
}
}
final class windowhandler extends WindowAdapter{
public void windowClosing(WindowEvent we){
System.exit(0);
}
}
public static void main(String args[]){
CheckboxMenuItem sound_check=new CheckboxMenuItem("Sound",true);
String file_name="image/image12.jpg";
String path_root="image/";
String user_name="사용자1";
ImagePuzzle ip=new ImagePuzzle("Image Puzzle",sound_check,file_name,0,path_root,user_name);
ip.setBackground(Color.blue);
ip.setBounds(65,65,900,600);
ip.show();
}
}