Search

'Programming/JAVA,JSP'에 해당되는 글 97건

  1. 2014.01.20 JAVA 채팅 예제 #2
  2. 2014.01.20 JAVA 채팅 Server 예제 #1
  3. 2014.01.20 JAVA 채팅 Client 예제 #1
  4. 2014.01.17 JAVA FIle 실습 #1
  5. 2014.01.17 JAVA File 실습
  6. 2014.01.16 JAVA 공던지기 게임 완성
  7. 2014.01.16 JAVA 공던지기 게임
  8. 2014.01.14 JAVA 가계부 #2
  9. 2014.01.14 JAVA 가계부
  10. 2014.01.09 JAVA 쿵쿵따 게임 #2 중복 탐지

JAVA 채팅 예제 #2

Programming/JAVA,JSP 2014. 1. 20. 17:48 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.IOException;

import java.io.ObjectInputStream;

import java.net.ServerSocket;

import java.net.Socket;


public class Server {

public static void main(String[] args) {

try {

ServerSocket ss = new ServerSocket(5555);

Socket s;

while (true) {


s = ss.accept();


System.out.println("입장 : " + s.getInetAddress());

PerClientThread pc = new PerClientThread();

pc.s = s;

pc.start();


}


} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}

}







import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

public class PerClientThread extends Thread {
public static ArrayList<PrintWriter> printWriterList = new ArrayList<PrintWriter>();
public Socket s;

@Override
public void run() {
PrintWriter out = null;
BufferedReader in = null;
try {
out = new PrintWriter(s.getOutputStream(), true);

printWriterList.add(out);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null)
{
System.out.println( s.getInetAddress() + " : " +  inputLine);
for( int i = 0 ; i < printWriterList.size() ; i++ )
{
printWriterList.get(i).println(inputLine);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println("발생자 : " + s.getInetAddress());
e.printStackTrace();
}
}

}









import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Client {
static JTextField textField;
static JTextArea textArea;
static PrintWriter out;
static BufferedReader in;

public static void main(String[] args) {
try {
Socket s = new Socket("115.20.247.170", 5555);

out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
JFrame f = new JFrame("채팅");
f.setSize(600, 400);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
textArea = new JTextArea();
textField = new JTextField(10);
textField.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
out.println(textField.getText());
textField.setText("");
}
}

);
f.add(textField, BorderLayout.SOUTH);
f.add(textArea, BorderLayout.CENTER);
f.setVisible(true);
ReceiveMSG rMSG = new ReceiveMSG();
rMSG.textArea = textArea;
rMSG.in = in;
rMSG.start();

} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}







import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JTextArea;

public class ReceiveMSG extends Thread {
public JTextArea textArea;

public BufferedReader in;

@Override
public void run() {

while (true) {
try {
String msg;
msg = in.readLine();
textArea.setText(textArea.getText()+ "\n" + msg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

}


'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA DML  (0) 2014.01.22
JAVA 채팅 프로그램  (0) 2014.01.21
JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA 채팅 Client 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17

JAVA 채팅 Server 예제 #1

Programming/JAVA,JSP 2014. 1. 20. 17:28 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.IOException;

import java.io.ObjectInputStream;

import java.net.ServerSocket;

import java.net.Socket;


public class Server {

public static void main(String[] args) {

try {

ServerSocket ss = new ServerSocket(5555);

Socket s;

while (true) {


s = ss.accept();


System.out.println("입장 : " + s.getInetAddress());

PerClientThread pc = new PerClientThread();

pc.s = s;

pc.start();


}


} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}

}



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class PerClientThread extends Thread {
public Socket s;

@Override
public void run() {
PrintWriter out = null;
BufferedReader in = null;
try {
out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null)
{
System.out.println( s.getInetAddress() + " : " +  inputLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}


'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 프로그램  (0) 2014.01.21
JAVA 채팅 예제 #2  (0) 2014.01.20
JAVA 채팅 Client 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17
JAVA File 실습  (0) 2014.01.17

JAVA 채팅 Client 예제 #1

Programming/JAVA,JSP 2014. 1. 20. 17:27 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import java.io.PrintWriter;

import java.net.Socket;

import java.net.UnknownHostException;

import java.util.Scanner;


import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;




public class Client {

static JTextField textField;

static JTextArea textArea;

static PrintWriter out;

public static void main(String[] args) {

try {

Socket s = new Socket("115.20.247.170",5555);


out = new PrintWriter(s.getOutputStream(), true);


JFrame f = new JFrame("채팅");

f.setSize(600, 400);

f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);

textArea = new JTextArea();

textField = new JTextField(10);

textField.addActionListener(


new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

out.println(textField.getText());

}

}

);

f.add(textField, BorderLayout.SOUTH);

f.add(textArea , BorderLayout.CENTER);

f.setVisible(true);

} catch (UnknownHostException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}



'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 예제 #2  (0) 2014.01.20
JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17
JAVA File 실습  (0) 2014.01.17
JAVA 공던지기 게임 완성  (0) 2014.01.16

JAVA FIle 실습 #1

Programming/JAVA,JSP 2014. 1. 17. 17:36 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.tistory.tansanc;


import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;


import javax.swing.JButton;

import javax.swing.JColorChooser;

import javax.swing.JFrame;

import javax.swing.JPanel;


class MyFrame extends JFrame {

private JButton button1;

private JButton button2;

private JPanel panel;


public MyFrame() {

this.setSize(300, 200);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setTitle("이벤트 예제");

panel = new JPanel();

button1 = new JButton("색상선택");

button1.addActionListener(new MyListener());

panel.add(button1);

this.add(panel);

LoadFile();

this.setVisible(true);

}


private void LoadFile() {

// TODO Auto-generated method stub

ObjectInputStream oos = null;

try {

oos = new ObjectInputStream(

new FileInputStream("Color.bin"));

Color newColor = (Color)oos.readObject();

panel.setBackground(newColor);

oos.close();

} catch ( IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}


private class MyListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

if (e.getSource() == button1) {

JColorChooser colorChooser = 

new JColorChooser();

Color newColor =

colorChooser.showDialog(MyFrame.this,

"Hello",Color.red);

System.out.println(newColor);

panel.setBackground(newColor);

ObjectOutputStream oos = null;

try {

oos = new ObjectOutputStream(

new FileOutputStream("Color.bin"));

oos.writeObject(newColor);

oos.close();

} catch ( IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

}


public class MyFrameTest2 {

public static void main(String[] args) {

MyFrame t = new MyFrame();

}

}



'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA 채팅 Client 예제 #1  (0) 2014.01.20
JAVA File 실습  (0) 2014.01.17
JAVA 공던지기 게임 완성  (0) 2014.01.16
JAVA 공던지기 게임  (0) 2014.01.16

JAVA File 실습

Programming/JAVA,JSP 2014. 1. 17. 16:52 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1. ColorChooser를 활용한

Panel Background Color 변경

및 파일이용하여 변경사항 저장


2. 암호화된 파일저장 & 암호화된 파일 읽기기능


3. 파일에서 찾고자하는 문자열을 갖고 있는지 검색하는 프로그램


4. 특정 폴더 내부에서 찾고자하는 문자열을 갖고 있는 파일을 검색하는 프로그램

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 Client 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17
JAVA 공던지기 게임 완성  (0) 2014.01.16
JAVA 공던지기 게임  (0) 2014.01.16
JAVA 가계부 #2  (0) 2014.01.14

JAVA 공던지기 게임 완성

Programming/JAVA,JSP 2014. 1. 16. 17:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.tistory.tansanc;

 

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

 

import javax.swing.JButton;

import javax.swing.JComponent;

import javax.swing.JFrame;

 

// 그림이 그려지는 컴포넌트를 정의

class MyComponent extends JComponent {

 

   public int x = 30;

   public int y = 420;

 

   public boolean wire = true;

 

   public void paint(Graphics g) {

       g.setColor(new Color(167, 114, 48));

       g.drawLine(100, 500, 100, 450);

       g.drawLine(100, 450, 75, 400);

       g.drawLine(100, 450, 125, 400);

 

       if (wire) {

          g.setColor(new Color(0, 255, 0));

          g.drawLine(75, 400, x + 25, y + 25);

         g.drawLine(125, 400, x + 25, y + 25);

       }

       g.setColor(new Color(255, 0, 0));

       g.fillOval(x, y, 50, 50);

 

       g.setColor(new Color(0, 0, 255));

       g.drawOval(400, 150, 100, 50);

       // x : 400 ~ 500

       // y : 150 ~ 200

       g.drawLine(500, 150, 500, 600);

 

       g.setFont(new Font("Monospaced", Font.BOLD, 20));

      g.drawString("점수 : " + point, 10, 100);

       if (x + 25 > 400 && x + 25 < 500 && y + 25 > 150 && y + 25 < 200) {

          pointBool = true;

       } else {

          if (pointBool == true) {

             point++;

 

          }

          pointBool = false;

       }

       Image image;

       try {

          //image = ImageIO.read(this.getClass().getResource("angry.png"));

          image= Toolkit.getDefaultToolkit().getImage("angry.png");

          int w = image.getWidth(null);

          int h = image.getHeight(null);

          g.drawImage(image, x, y, 50, 50, null);

       } catch (Exception e) {

          // TODO Auto-generated catch block

          e.printStackTrace();

       }

 

      

   }

 

   boolean pointBool = false;

   int point = 0;

}

 

// 프레임 컴포넌트를 상속받아서 정의

public class StarFrame extends JFrame implements ActionListener,

       MouseMotionListener, MouseListener {

   public static final int WIDTH = 800;

   public static final int HEIGHT = 600;

 

   JButton next = new JButton("Next");

   MyComponent c;

 

   public StarFrame() {

       setTitle("MyFrame");

       setSize(WIDTH, HEIGHT);

   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       setVisible(true);

 

       // MyComponent 객체 생성하여 프레임에 추가

       c = new MyComponent();

       next.addActionListener(this);

 

       add(c, BorderLayout.CENTER);

       add(next, BorderLayout.SOUTH);

 

       addMouseMotionListener(this);

       addMouseListener(this);

   }

 

   public static void main(String[] args) {

       StarFrame frame = new StarFrame();

   }

 

   @Override

   public void actionPerformed(ActionEvent arg0) {

       // TODO Auto-generated method stub

   }

 

   @Override

   public void mouseDragged(MouseEvent arg0) {

       // TODO Auto-generated method stub

       if (arg0.getX() < 140 && arg0.getY() > 400) {

 

          c.x = arg0.getX() - 30;

          c.y = arg0.getY() - 60;

          c.repaint();

       }

 

   }

 

   @Override

   public void mouseMoved(MouseEvent arg0) {

       // TODO Auto-generated method stub

 

   }

 

   @Override

   public void mouseClicked(MouseEvent arg0) {

       // TODO Auto-generated method stub

 

   }

 

   @Override

   public void mouseEntered(MouseEvent arg0) {

       // TODO Auto-generated method stub

 

   }

 

   @Override

   public void mouseExited(MouseEvent arg0) {

       // TODO Auto-generated method stub

 

   }

 

   boolean mouse = false;

   int startX;

   int startY;

   int endX;

   int endY;

 

   @Override

   public void mousePressed(MouseEvent arg0) {

       // TODO Auto-generated method stub

       if (arg0.getX() < 140 && arg0.getY() > 400) {

          if (mouse == false) {

 

             c.wire = true;

             c.x = arg0.getX() - 30;

             c.y = arg0.getY() - 60;

             c.repaint();

             startX = arg0.getX();

             startY = arg0.getY();

             mouse = true;

 

          }

       }

   }

 

   @Override

   public void mouseReleased(MouseEvent arg0) {

       // TODO Auto-generated method stub

 

       if (mouse == true) {

          endX = arg0.getX();

          endY = arg0.getY();

          System.out.println("power X : " + (startX - endX));

          System.out.println("power Y : " + (startY - endY));

          mouse = false;

          c.wire = false;

          if (ft != null) {

             ft.stop();

          }

          ft = new FlyThread((startX - endX), (startY - endY));

          ft.start();

       }

   }

 

   FlyThread ft;

 

   class FlyThread extends Thread {

       int powerX;

       int powerY;

 

       FlyThread(int powerX, int powerY) {

          this.powerX = powerX;

          this.powerY = powerY;

       }

 

       @Override

       public void run() {

          while (true) {

             if (c.x > 800 || c.x < -50) {

                 break;

             }

             if (c.y > 600 || c.y < -50) {

                 break;

             }

             c.x += powerX / 10;

             c.y += powerY / 10;

             powerY += 1;

             try {

                 sleep(10);

             } catch (InterruptedException e) {

                 // TODO Auto-generated catch block

                 e.printStackTrace();

             }

             c.repaint();

 

          }

       }

   }

 

}

 

 

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA FIle 실습 #1  (0) 2014.01.17
JAVA File 실습  (0) 2014.01.17
JAVA 공던지기 게임  (0) 2014.01.16
JAVA 가계부 #2  (0) 2014.01.14
JAVA 가계부  (0) 2014.01.14

JAVA 공던지기 게임

Programming/JAVA,JSP 2014. 1. 16. 16:49 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.tistory.tansanc;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.*;

// 그림이 그려지는 컴포넌트를 정의
class MyComponent extends JComponent {

 public int x = 30;
 public int y = 420;
 
 public boolean wire = true;

 public void paint(Graphics g) {
  g.setColor(new Color(167, 114, 48));
  g.drawLine(100, 500, 100, 450);
  g.drawLine(100, 450, 75, 400);
  g.drawLine(100, 450, 125, 400);

  if( wire )
  {
   g.setColor(new Color(0, 255, 0));
   g.drawLine(75, 400, x + 25, y + 25);
   g.drawLine(125, 400, x + 25, y + 25);
  }
  g.setColor(new Color(255, 0, 0));
  g.fillOval(x, y, 50, 50);
 }
}

// 프레임 컴포넌트를 상속받아서 정의
public class StarFrame extends JFrame implements ActionListener,
  MouseMotionListener, MouseListener {
 public static final int WIDTH = 800;
 public static final int HEIGHT = 600;

 JButton next = new JButton("Next");
 MyComponent c;

 public StarFrame() {
  setTitle("MyFrame");
  setSize(WIDTH, HEIGHT);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setVisible(true);

  // MyComponent 객체 생성하여 프레임에 추가
  c = new MyComponent();
  next.addActionListener(this);

  add(c, BorderLayout.CENTER);
  add(next, BorderLayout.SOUTH);

  addMouseMotionListener(this);
  addMouseListener(this);
 }

 public static void main(String[] args) {
  StarFrame frame = new StarFrame();
 }

 @Override
 public void actionPerformed(ActionEvent arg0) {
  // TODO Auto-generated method stub
 }

 @Override
 public void mouseDragged(MouseEvent arg0) {
  // TODO Auto-generated method stub
  if (arg0.getX() < 140 && arg0.getY() > 400) {

   c.x = arg0.getX()-30;
   c.y = arg0.getY()-60;
   c.repaint();
  }

 }

 @Override
 public void mouseMoved(MouseEvent arg0) {
  // TODO Auto-generated method stub

 }

 @Override
 public void mouseClicked(MouseEvent arg0) {
  // TODO Auto-generated method stub

 }

 @Override
 public void mouseEntered(MouseEvent arg0) {
  // TODO Auto-generated method stub

 }

 @Override
 public void mouseExited(MouseEvent arg0) {
  // TODO Auto-generated method stub

 }

 boolean mouse = false;
 int startX;
 int startY;
 int endX;
 int endY;

 @Override
 public void mousePressed(MouseEvent arg0) {
  // TODO Auto-generated method stub
  if (arg0.getX() < 140 && arg0.getY() > 400) {
   if (mouse == false) {

    c.wire = true;
    c.x = arg0.getX()-30;
    c.y = arg0.getY()-60;
    c.repaint();
    startX = arg0.getX();
    startY = arg0.getY();
    mouse = true;
    
   }
  }
 }

 @Override
 public void mouseReleased(MouseEvent arg0) {
  // TODO Auto-generated method stub

  if (mouse == true) {
   endX = arg0.getX();
   endY = arg0.getY();
   System.out.println("power X : " + (startX - endX));
   System.out.println("power Y : " + (startY - endY));
   mouse = false;
   c.wire = false;
   if( ft != null)
   {
    ft.stop();
   }
   ft = new FlyThread((startX - endX), (startY - endY));
   ft.start();
  }
 }
 FlyThread ft;
 class FlyThread extends Thread
 {
  int powerX;
  int powerY;
  FlyThread(int powerX, int powerY)
  {
   this.powerX = powerX;
   this.powerY = powerY;
  }
  @Override
  public void run() {
   while(true)
   {
    if( c.x > 800)
    {
     break;
    }
    if( c.y > 600)
    {
     break;
    }
    c.x += powerX/10;
    c.y += powerY/10;
    powerY += 1;
    try {
     sleep(10);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
    c.repaint();
    
   }
  }
 }

}

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA File 실습  (0) 2014.01.17
JAVA 공던지기 게임 완성  (0) 2014.01.16
JAVA 가계부 #2  (0) 2014.01.14
JAVA 가계부  (0) 2014.01.14
JAVA 쿵쿵따 게임 #2 중복 탐지  (0) 2014.01.09

JAVA 가계부 #2

Programming/JAVA,JSP 2014. 1. 14. 20:15 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.FileWriter;

import java.util.StringTokenizer;

 

import javax.swing.JComboBox;

import javax.swing.RowSorter;

import javax.swing.table.TableModel;

import javax.swing.table.TableRowSorter;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author Suser

 */

public class NewJFrame extends javax.swing.JFrame implements ActionListener {

 

    /**

     * Creates new form NewJFrame

     */

    public NewJFrame() {

       initComponents();

    }

 

    /**

     * This method is called from within the constructor to initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is always

     * regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed"

    // desc="Generated Code">//GEN-BEGIN:initComponents

    private void initComponents() {

 

       jLabel1 = new javax.swing.JLabel();

      String[] monthArray = { "1", "2", "3", "4", "5", "6", "7", "8",

              "9", "10", "11", "12" };

       jComboBox1 = new JComboBox(monthArray);

       jComboBox1.addActionListener(this);

 

       jScrollPane1 = new javax.swing.JScrollPane();

       jTable1 = new javax.swing.JTable();

       jScrollPane2 = new javax.swing.JScrollPane();

       jTable2 = new javax.swing.JTable();

       jLabel2 = new javax.swing.JLabel();

       jButton1 = new javax.swing.JButton();

       jButton2 = new javax.swing.JButton();

       jButton3 = new javax.swing.JButton();

       jButton4 = new javax.swing.JButton();

       jButton5 = new javax.swing.JButton();

       jButton6 = new javax.swing.JButton();

       jButton7 = new javax.swing.JButton();

       jButton8 = new javax.swing.JButton();

       jButton9 = new javax.swing.JButton();

 

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 

      jLabel1.setFont(new java.awt.Font("바탕", 1, 24)); // NOI18N

       jLabel1.setForeground(new java.awt.Color(255, 153, 153));

      jLabel1.setText("2014 월별 MoneyBook");

 

       int i = 1;

       jTable1.setModel(new javax.swing.table.DefaultTableModel(

              new Object[][] {

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null } },

              new String[] { "날짜", "수입 항목", "내용", "금액", "지출 항목", "내용", "금액" }));

       jScrollPane1.setViewportView(jTable1);

       // jTable1.getColumnModel().getColumn(0).setCellEditor(new

       // DatePickerCellEditor());

 

       RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(

              jTable1.getModel());

       jTable1.setRowSorter(sorter);

 

        jTable1.setAutoCreateColumnsFromModel(true);

 

       loadFile();

 

       jTable2.setModel(new javax.swing.table.DefaultTableModel(

             new Object[][] { { null, null, null, null, null } },

              new String[] { "전월 이월금", "수입 합계", "지출 합계", " 합계", "잔액" }));

       jScrollPane2.setViewportView(jTable2);

 

       jButton1.setText("항목검색");

       jButton1.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              jButton1ActionPerformed(evt);

           }

       });

 

       jButton2.setText("오랜순 정렬");

 

       jButton3.setText("낮은금액순정렬");

 

       jButton4.setText("잔액고침");

       jButton4.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              loadFile();

           }

 

       });

 

       jButton5.setText("사용방법");

 

       jButton6.setText("내보내기");

       jButton6.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              saveFile();

           }

 

       });

 

       jButton7.setText("항목검색");

       jButton7.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              jButton7ActionPerformed(evt);

           }

       });

 

       jButton8.setText("높은금액순정렬");

       jButton8.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              jButton8ActionPerformed(evt);

           }

       });

 

       jButton9.setText("최신순 정렬");

 

       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(

              getContentPane());

       getContentPane().setLayout(layout);

       layout.setHorizontalGroup(layout

           .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

              .addGroup(

                      layout.createSequentialGroup()

                            .addContainerGap()

                            .addGroup(

                                    layout.createParallelGroup(

                                           javax.swing.GroupLayout.Alignment.LEADING)

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addComponent(

                                                               jComboBox1,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE,

                                                               102,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE)

                                                        .addContainerGap(

                                                                javax.swing.GroupLayout.DEFAULT_SIZE,

                                                               Short.MAX_VALUE))

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addGroup(

                                                               layout.createParallelGroup(

                                                                       javax.swing.GroupLayout.Alignment.TRAILING,

                                                                      false)

                                                                      .addGroup(

                                                                              layout.createSequentialGroup()

                                                                                    .addGap(10,

                                                                                           10,

                                                                                            10)

                                                                                    .addComponent(

                                                                                           jLabel1,

                                                                                            javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                                            javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                                            Short.MAX_VALUE))

                                                                      .addComponent(

                                                                             jScrollPane2,

                                                                              javax.swing.GroupLayout.Alignment.LEADING)

                                                                      .addComponent(

                                                                             jScrollPane1,

                                                                              javax.swing.GroupLayout.Alignment.LEADING,

                                                                              javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                             518,

                                                                             Short.MAX_VALUE))

                                                        .addGroup(

                                                               layout.createParallelGroup(

                                                                       javax.swing.GroupLayout.Alignment.LEADING)

                                                                      .addGroup(

                                                                              layout.createSequentialGroup()

                                                                                    .addGap(65,

                                                                                           65,

                                                                                           65)

                                                                                    .addComponent(

                                                                                            jLabel2))

                                                                      .addGroup(

                                                                              layout.createSequentialGroup()

                                                                                    .addGap(18,

                                                                                           18,

                                                                                           18)

                                                                                     .addGroup(

                                                                                            layout.createParallelGroup(

                                                                                                   javax.swing.GroupLayout.Alignment.LEADING)

                                                                                                   .addComponent(

                                                                                                         jButton5)

                                                                                                   .addComponent(

                                                                                                         jButton2)

                                                                                                   .addComponent(

                                                                                                         jButton1)

                                                                                                   .addComponent(

                                                                                                         jButton3)

                                                                                                    .addComponent(

                                                                                                         jButton4)

                                                                                                   .addComponent(

                                                                                                         jButton7)

                                                                                                   .addComponent(

                                                                                                         jButton8)

                                                                                                   .addComponent(

                                                                                                         jButton9)

                                                                                                   .addComponent(

                                                                                                         jButton6))))

                                                        .addGap(0,

                                                               38,

                                                               Short.MAX_VALUE)))));

       layout.setVerticalGroup(layout

           .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

              .addGroup(

                      layout.createSequentialGroup()

                             .addComponent(jComboBox1)

                            .addGap(4, 4, 4)

                            .addComponent(jLabel1,

                                    javax.swing.GroupLayout.PREFERRED_SIZE,

                                   33,

                                    javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addPreferredGap(

                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,

                                    javax.swing.GroupLayout.DEFAULT_SIZE,

                                    Short.MAX_VALUE)

                            .addGroup(

                                    layout.createParallelGroup(

                                           javax.swing.GroupLayout.Alignment.LEADING,

                                          false)

                                           .addComponent(

                                                  jButton5,

                                                  javax.swing.GroupLayout.DEFAULT_SIZE,

                                                  javax.swing.GroupLayout.DEFAULT_SIZE,

                                                  Short.MAX_VALUE)

                                           .addComponent(

                                                  jScrollPane2,

                                                  javax.swing.GroupLayout.DEFAULT_SIZE,

                                                  59, Short.MAX_VALUE))

                            .addGroup(

                                    layout.createParallelGroup(

                                           javax.swing.GroupLayout.Alignment.LEADING,

                                          false)

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addGap(42, 42,

                                                               42)

                                                        .addComponent(

                                                               jLabel2)

                                                        .addPreferredGap(

                                                            javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

                                                        .addComponent(

                                                               jButton1)

                                                        .addGap(14, 14,

                                                               14)

                                                        .addComponent(

                                                               jButton2)

                                                        .addGap(14, 14,

                                                               14)

                                                        .addComponent(

                                                               jButton9)

                                                        .addGap(18, 18,

                                                               18)

                                                        .addComponent(

                                                               jButton7)

                                                        .addGap(18, 18,

                                                               18)

                                                        .addComponent(

                                                               jButton8)

                                                        .addGap(18, 18,

                                                               18)

                                                        .addComponent(

                                                               jButton3)

                                                         .addGap(40, 40,

                                                               40)

                                                        .addComponent(

                                                               jButton4)

                                                        .addPreferredGap(

                                                            javax.swing.LayoutStyle.ComponentPlacement.RELATED,

                                                                javax.swing.GroupLayout.DEFAULT_SIZE,

                                                               Short.MAX_VALUE)

                                                        .addComponent(

                                                               jButton6))

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addGap(18, 18,

                                                                18)

                                                        .addComponent(

                                                               jScrollPane1,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE,

                                                                javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))

                            .addContainerGap(

                                    javax.swing.GroupLayout.DEFAULT_SIZE,

                                    Short.MAX_VALUE)));

 

       pack();

    }// </editor-fold>//GEN-END:initComponents

 

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jComboBox1ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jComboBox1ActionPerformed

 

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jButton1ActionPerformed

 

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton7ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jButton7ActionPerformed

 

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton8ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jButton8ActionPerformed

 

    /**

     * @param args

     *            the command line arguments

     */

    public static void main(String args[]) {

       /* Set the Nimbus look and feel */

       // <editor-fold defaultstate="collapsed"

       // desc=" Look and feel setting code (optional) ">

       /*

        * If Nimbus (introduced in Java SE 6) is not available, stay with the

        * default look and feel. For details see

        * http://download.oracle.com/javase

        * /tutorial/uiswing/lookandfeel/plaf.html

        */

       try {

           for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager

                  .getInstalledLookAndFeels()) {

             if ("Nimbus".equals(info.getName())) {

              javax.swing.UIManager.setLookAndFeel(info.getClassName());

                  break;

              }

           }

       } catch (ClassNotFoundException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       } catch (InstantiationException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       } catch (IllegalAccessException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       } catch (javax.swing.UnsupportedLookAndFeelException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       }

       // </editor-fold>

 

       /* Create and display the form */

       java.awt.EventQueue.invokeLater(new Runnable() {

           public void run() {

              new NewJFrame().setVisible(true);

           }

       });

    }

 

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton2;

    private javax.swing.JButton jButton3;

    private javax.swing.JButton jButton4;

    private javax.swing.JButton jButton5;

    private javax.swing.JButton jButton6;

    private javax.swing.JButton jButton7;

    private javax.swing.JButton jButton8;

    private javax.swing.JButton jButton9;

    private javax.swing.JComboBox jComboBox1;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JScrollPane jScrollPane1;

    private javax.swing.JScrollPane jScrollPane2;

    private javax.swing.JTable jTable1;

    private javax.swing.JTable jTable2;

    // End of variables declaration//GEN-END:variables

    int thisMonth = 1;

 

    @Override

    public void actionPerformed(ActionEvent arg0) {

       // TODO Auto-generated method stub

       if (arg0.getSource() == jComboBox1) {

           String str = (String) jComboBox1.getSelectedItem();

           jLabel1.setText("2014 " + str + " MoneyBook");

           // "1"

           // "1"

           thisMonth = Integer.parseInt(str.charAt(0) + "");

       }

 

    }

 

    private void saveFile() {

       try {

           FileWriter out = null;

           out = new FileWriter(thisMonth + ".txt");

           String str = "";

           for (int i = 0; i < 31; i++) {

              str += (String) jTable1.getModel().getValueAt(i, 0);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 1);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 2);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 3);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 4);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 5);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 6);

              str += "\n";

           }

           out.write(str);

           out.flush();

           out.close();

       } catch (Exception e) {

 

       }

    }

 

    private void loadFile() {

       // TODO Auto-generated method stub

 

       try {

           FileReader in = new FileReader(thisMonth + ".txt");

           BufferedReader br = new BufferedReader(in);

           String thisLine;

           int rowIndex = 0;

           while ((thisLine = br.readLine()) != null) { // while loop begins

 

              int columnIndex = 0;

              StringTokenizer tokenizer = new StringTokenizer(thisLine, "\t"); // 설정

              while (tokenizer.hasMoreTokens()) {

                  String token = tokenizer.nextToken();

                  System.out.println(token + " columnIndex " + columnIndex

                         + " rowIndex " + rowIndex);

                  if (token.equals("null")) {

                     token = " ";

                  }

                  jTable1.getModel().setValueAt(token, rowIndex, columnIndex);

 

                  columnIndex++;

              }

 

              rowIndex++;

           }

       } catch (Exception e) {

           e.printStackTrace();

       }

    }

}

 

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 공던지기 게임 완성  (0) 2014.01.16
JAVA 공던지기 게임  (0) 2014.01.16
JAVA 가계부  (0) 2014.01.14
JAVA 쿵쿵따 게임 #2 중복 탐지  (0) 2014.01.09
JAVA 쿵쿵따 게임  (0) 2014.01.09

JAVA 가계부

Programming/JAVA,JSP 2014. 1. 14. 19:34 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.FileOutputStream;

import java.io.FileWriter;

 

import javax.swing.JComboBox;

import javax.swing.RowSorter;

import javax.swing.table.TableModel;

import javax.swing.table.TableRowSorter;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author Suser

 */

public class NewJFrame extends javax.swing.JFrame implements ActionListener {

 

    /**

     * Creates new form NewJFrame

     */

    public NewJFrame() {

       initComponents();

    }

 

    /**

     * This method is called from within the constructor to initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is always

     * regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed"

    // desc="Generated Code">//GEN-BEGIN:initComponents

    private void initComponents() {

 

       jLabel1 = new javax.swing.JLabel();

      String[] monthArray = { "1", "2", "3", "4", "5", "6", "7", "8",

              "9", "10", "11", "12" };

       jComboBox1 = new JComboBox(monthArray);

       jComboBox1.addActionListener(this);

 

       jScrollPane1 = new javax.swing.JScrollPane();

       jTable1 = new javax.swing.JTable();

       jScrollPane2 = new javax.swing.JScrollPane();

       jTable2 = new javax.swing.JTable();

       jLabel2 = new javax.swing.JLabel();

       jButton1 = new javax.swing.JButton();

       jButton2 = new javax.swing.JButton();

       jButton3 = new javax.swing.JButton();

       jButton4 = new javax.swing.JButton();

       jButton5 = new javax.swing.JButton();

       jButton6 = new javax.swing.JButton();

       jButton7 = new javax.swing.JButton();

       jButton8 = new javax.swing.JButton();

       jButton9 = new javax.swing.JButton();

 

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 

      jLabel1.setFont(new java.awt.Font("바탕", 1, 24)); // NOI18N

       jLabel1.setForeground(new java.awt.Color(255, 153, 153));

      jLabel1.setText("2014 월별 MoneyBook");

 

       int i = 1;

       jTable1.setModel(new javax.swing.table.DefaultTableModel(

              new Object[][] {

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null },

                     { (i++) + "", null, null, null, null, null, null } },

              new String[] { "날짜", "수입 항목", "내용", "금액", "지출 항목", "내용", "금액" }));

       jScrollPane1.setViewportView(jTable1);

       // jTable1.getColumnModel().getColumn(0).setCellEditor(new

       // DatePickerCellEditor());

 

       RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(

              jTable1.getModel());

       jTable1.setRowSorter(sorter);

 

        jTable1.setAutoCreateColumnsFromModel(true);

 

       jTable2.setModel(new javax.swing.table.DefaultTableModel(

             new Object[][] { { null, null, null, null, null } },

              new String[] { "전월 이월금", "수입 합계", "지출 합계", " 합계", "잔액" }));

       jScrollPane2.setViewportView(jTable2);

 

       jButton1.setText("항목검색");

       jButton1.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              jButton1ActionPerformed(evt);

           }

       });

 

       jButton2.setText("오랜순 정렬");

 

       jButton3.setText("낮은금액순정렬");

 

       jButton4.setText("잔액고침");

 

       jButton5.setText("사용방법");

 

       jButton6.setText("내보내기");

       jButton6.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              saveFile();

           }

 

       });

 

       jButton7.setText("항목검색");

       jButton7.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              jButton7ActionPerformed(evt);

           }

       });

 

       jButton8.setText("높은금액순정렬");

       jButton8.addActionListener(new java.awt.event.ActionListener() {

           public void actionPerformed(java.awt.event.ActionEvent evt) {

              jButton8ActionPerformed(evt);

           }

       });

 

       jButton9.setText("최신순 정렬");

 

       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(

              getContentPane());

       getContentPane().setLayout(layout);

       layout.setHorizontalGroup(layout

           .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

              .addGroup(

                      layout.createSequentialGroup()

                            .addContainerGap()

                            .addGroup(

                                    layout.createParallelGroup(

                                           javax.swing.GroupLayout.Alignment.LEADING)

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addComponent(

                                                               jComboBox1,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE,

                                                               102,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE)

                                                        .addContainerGap(

                                                                javax.swing.GroupLayout.DEFAULT_SIZE,

                                                               Short.MAX_VALUE))

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addGroup(

                                                               layout.createParallelGroup(

                                                                       javax.swing.GroupLayout.Alignment.TRAILING,

                                                                      false)

                                                                      .addGroup(

                                                                              layout.createSequentialGroup()

                                                                                    .addGap(10,

                                                                                           10,

                                                                                           10)

                                                                                    .addComponent(

                                                                                           jLabel1,

                                                                                            javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                                            javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                                            Short.MAX_VALUE))

                                                                      .addComponent(

                                                                             jScrollPane2,

                                                                              javax.swing.GroupLayout.Alignment.LEADING)

                                                                      .addComponent(

                                                                             jScrollPane1,

                                                                              javax.swing.GroupLayout.Alignment.LEADING,

                                                                              javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                             518,

                                                                             Short.MAX_VALUE))

                                                        .addGroup(

                                                               layout.createParallelGroup(

                                                                       javax.swing.GroupLayout.Alignment.LEADING)

                                                                      .addGroup(

                                                                              layout.createSequentialGroup()

                                                                                    .addGap(65,

                                                                                           65,

                                                                                           65)

                                                                                    .addComponent(

                                                                                            jLabel2))

                                                                      .addGroup(

                                                                               layout.createSequentialGroup()

                                                                                    .addGap(18,

                                                                                           18,

                                                                                           18)

                                                                                    .addGroup(

                                                                                            layout.createParallelGroup(

                                                                                                   javax.swing.GroupLayout.Alignment.LEADING)

                                                                                                   .addComponent(

                                                                                                         jButton5)

                                                                                                   .addComponent(

                                                                                                         jButton2)

                                                                                                   .addComponent(

                                                                                                         jButton1)

                                                                                                   .addComponent(

                                                                                                         jButton3)

                                                                                                   .addComponent(

                                                                                                         jButton4)

                                                                                                   .addComponent(

                                                                                                         jButton7)

                                                                                                   .addComponent(

                                                                                                         jButton8)

                                                                                                   .addComponent(

                                                                                                         jButton9)

                                                                                                   .addComponent(

                                                                                                          jButton6))))

                                                        .addGap(0,

                                                               38,

                                                               Short.MAX_VALUE)))));

       layout.setVerticalGroup(layout

           .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

              .addGroup(

                      layout.createSequentialGroup()

                             .addComponent(jComboBox1)

                            .addGap(4, 4, 4)

                            .addComponent(jLabel1,

                                    javax.swing.GroupLayout.PREFERRED_SIZE,

                                   33,

                                    javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addPreferredGap(

                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,

                                    javax.swing.GroupLayout.DEFAULT_SIZE,

                                    Short.MAX_VALUE)

                            .addGroup(

                                    layout.createParallelGroup(

                                           javax.swing.GroupLayout.Alignment.LEADING,

                                          false)

                                           .addComponent(

                                                  jButton5,

                                                  javax.swing.GroupLayout.DEFAULT_SIZE,

                                                  javax.swing.GroupLayout.DEFAULT_SIZE,

                                                  Short.MAX_VALUE)

                                           .addComponent(

                                                  jScrollPane2,

                                                  javax.swing.GroupLayout.DEFAULT_SIZE,

                                                  59, Short.MAX_VALUE))

                            .addGroup(

                                    layout.createParallelGroup(

                                           javax.swing.GroupLayout.Alignment.LEADING,

                                          false)

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addGap(42, 42,

                                                               42)

                                                        .addComponent(

                                                               jLabel2)

                                                        .addPreferredGap(

                                                            javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

                                                        .addComponent(

                                                               jButton1)

                                                        .addGap(14, 14,

                                                               14)

                                                        .addComponent(

                                                               jButton2)

                                                        .addGap(14, 14,

                                                               14)

                                                        .addComponent(

                                                               jButton9)

                                                        .addGap(18, 18,

                                                               18)

                                                        .addComponent(

                                                               jButton7)

                                                        .addGap(18, 18,

                                                               18)

                                                        .addComponent(

                                                               jButton8)

                                                        .addGap(18, 18,

                                                               18)

                                                        .addComponent(

                                                               jButton3)

                                                        .addGap(40, 40,

                                                               40)

                                                        .addComponent(

                                                               jButton4)

                                                         .addPreferredGap(

                                                            javax.swing.LayoutStyle.ComponentPlacement.RELATED,

                                                                javax.swing.GroupLayout.DEFAULT_SIZE,

                                                               Short.MAX_VALUE)

                                                        .addComponent(

                                                               jButton6))

                                           .addGroup(

                                                  layout.createSequentialGroup()

                                                        .addGap(18, 18,

                                                               18)

                                                        .addComponent(

                                                               jScrollPane1,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE,

                                                                javax.swing.GroupLayout.DEFAULT_SIZE,

                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))

                            .addContainerGap(

                                    javax.swing.GroupLayout.DEFAULT_SIZE,

                                    Short.MAX_VALUE)));

 

       pack();

    }// </editor-fold>//GEN-END:initComponents

 

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jComboBox1ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jComboBox1ActionPerformed

 

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jButton1ActionPerformed

 

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton7ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jButton7ActionPerformed

 

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton8ActionPerformed

       // TODO add your handling code here:

    }// GEN-LAST:event_jButton8ActionPerformed

 

    /**

     * @param args

     *            the command line arguments

     */

    public static void main(String args[]) {

       /* Set the Nimbus look and feel */

       // <editor-fold defaultstate="collapsed"

       // desc=" Look and feel setting code (optional) ">

       /*

        * If Nimbus (introduced in Java SE 6) is not available, stay with the

        * default look and feel. For details see

        * http://download.oracle.com/javase

        * /tutorial/uiswing/lookandfeel/plaf.html

        */

       try {

           for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager

                  .getInstalledLookAndFeels()) {

             if ("Nimbus".equals(info.getName())) {

              javax.swing.UIManager.setLookAndFeel(info.getClassName());

                  break;

              }

           }

       } catch (ClassNotFoundException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       } catch (InstantiationException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       } catch (IllegalAccessException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       } catch (javax.swing.UnsupportedLookAndFeelException ex) {

       java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(

                  java.util.logging.Level.SEVERE, null, ex);

       }

       // </editor-fold>

 

       /* Create and display the form */

       java.awt.EventQueue.invokeLater(new Runnable() {

           public void run() {

              new NewJFrame().setVisible(true);

           }

       });

    }

 

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton2;

    private javax.swing.JButton jButton3;

    private javax.swing.JButton jButton4;

    private javax.swing.JButton jButton5;

    private javax.swing.JButton jButton6;

    private javax.swing.JButton jButton7;

    private javax.swing.JButton jButton8;

    private javax.swing.JButton jButton9;

    private javax.swing.JComboBox jComboBox1;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JScrollPane jScrollPane1;

    private javax.swing.JScrollPane jScrollPane2;

    private javax.swing.JTable jTable1;

    private javax.swing.JTable jTable2;

    // End of variables declaration//GEN-END:variables

    int thisMonth;

 

    @Override

    public void actionPerformed(ActionEvent arg0) {

       // TODO Auto-generated method stub

       if (arg0.getSource() == jComboBox1) {

           String str = (String) jComboBox1.getSelectedItem();

           jLabel1.setText("2014 " + str + " MoneyBook");

           // "1"

           // "1"

           thisMonth = Integer.parseInt(str.charAt(0) + "");

       }

 

    }

 

    private void saveFile() {

       try {

           FileWriter out = null;

           out = new FileWriter(thisMonth+".txt");

           String str = "";

           for (int i = 0; i < 31; i++) {            

              str += (String) jTable1.getModel().getValueAt(i, 0);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 1);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 2);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 3);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 4);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 5);

              str += "\t";

              str += (String) jTable1.getModel().getValueAt(i, 6);

              str += "\n";

           }

           out.write(str);

           out.flush();

           out.close();

       } catch (Exception e) {

 

       }

    }

 

    private void loadFile() {

       // TODO Auto-generated method stub

 

       try {

           FileOutputStream out = null;

           out = new FileOutputStream("data.txt", false);

           // out.write();

       } catch (Exception e) {

 

       }

    }

}

 

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 공던지기 게임  (0) 2014.01.16
JAVA 가계부 #2  (0) 2014.01.14
JAVA 쿵쿵따 게임 #2 중복 탐지  (0) 2014.01.09
JAVA 쿵쿵따 게임  (0) 2014.01.09
JAVA 제네릭 컬렉션 실습  (1) 2014.01.09

JAVA 쿵쿵따 게임 #2 중복 탐지

Programming/JAVA,JSP 2014. 1. 9. 17:12 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.tistory.tansanc;

 

import java.util.HashSet;

import java.util.Scanner;

 

public class User {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       String[] word = {"기러기", "기차표","스피커"};

       String oldWord = word[

                         (int)(Math.random()*3)  ];

       HashSet<String> hs = new HashSet<String>();

      

       hs.add(oldWord);

      

       System.out.println("제시어 : " + oldWord);   

       String newWord = sc.nextLine();

      

       if( ! hs.add(newWord) )

       {

          System.err.println("중복 발생!");

       }

      

       if( oldWord.charAt(2) ==

             newWord.charAt(0) )

       {

          System.out.println("OK");

       }

       else

       {

          System.err.println("ERROR");

       }

       while(true)

       {

          oldWord = newWord;

          newWord = sc.nextLine();

         

          if( ! hs.add(newWord) )

          {

             System.err.println("중복 발생!");

          }

         

          if( oldWord.charAt(2) ==

                 newWord.charAt(0) )

          {

             System.out.println("OK");

          }

          else

          {

             System.out.println("ERROR");

          }

       }        

   }

}

 

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 가계부 #2  (0) 2014.01.14
JAVA 가계부  (0) 2014.01.14
JAVA 쿵쿵따 게임  (0) 2014.01.09
JAVA 제네릭 컬렉션 실습  (1) 2014.01.09
JAVA 객체지향 핵심 이론  (0) 2014.01.07