그룹: JAVA

 

JAVA Run

명령: %JAVA_HOME%\bin\java.exe

인수: $(FileNameNoExt)

폴더: $(FileDir)

동작: 출력 내용 캡쳐

 

JAVA Run with Prompt

명령: %JAVA_HOME%\bin\java.exe

인수: $(FileNameNoExt)

폴더: $(FileDir)

동작: 종료시 창 닫기

 

JAVA Compile

명령: %JAVA_HOME%\bin\javac.exe

인수: $(FileName)

폴더: $(FileDir)

동작: 출력 내용 캡쳐

 

JAVA Compile with Xlint

명령: %JAVA_HOME%\bin\javac.exe -Xlint

인수: $(FileName)

폴더: $(FileDir)

동작: 출력 내용 캡쳐

 

JAVA Package Compile

명령: %JAVA_HOME%\bin\javac.exe -d .

인수: $(FileName)

폴더: $(FileDir)

동작: 출력 내용 캡쳐

윈도우 상 내 컴퓨터 > 시스템 속성 > 시스템 변수에 추가..

 

- JAVA 폴더 지정

변수 이름: JAVA_HOME

변수 값: C:\Java\jdk1.7.0_60

 

- JAVA 바이너리 파일들 Path 에 추가

변수 이름: Path

변수 값: ;%JAVA_HOME%\bin

 

- JAVA Classpath 지정

변수 이름: Classpath

변수 값: .;%JAVA_HOME%\lib\tools.jar

 

- 설치확인

 

cmd

 

java -version

javac -version

path

echo %classpath%


 


Note 1.1.. 전보다는 빨리 읽지만 여전히 답답스러운 장난감 메모장..


폰트변경 기능을 시험해보기위해 기존 Note를 수정해봤습니다..
기존 AWT TextArea를 Swing JTextArea로 수정해서 파일을 읽어 반영하는 속도가 빨라졌으나 모냥이 맘에 들지 않아..

getSystemLookAndFeelClassName() 를 사용해, JAVA Swing Look & Feel이 아닌..
현재 사용중인 OS (윈도우, 맥, 리눅스 등) 의 UI를 읽어오는 기능을 추가해서 초기 실행 속도가 느려진점을 빼면 파일반영속도나 스크롤기능과 같은 전반적인 부분들은 모두 개선되었습니다..

몇몇 다듬은 부분외엔 전체 소스에 대단한 변화는 없어 소스는 따로 올리지 않습니다..


운영체제 종류에 관계없이 JAVA VM이 설치된 환경에서 실행가능하며 압축을 풀고 윈도우에서는 Note.exe로 실행하고 다른 OS에서는 Note.class로 실행..


폰트..
----------
Font font=new Font("Serif", Font.PLAIN, 12);
//기본지원 폰트: Serif, SansSerif, Dialog, DialogInput, Monospaced
----------

시스템 UI 적용..
----------
try {
   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //OS에 맞게 기본 UI를 불러옴, 윈도우에선 느림..
   SwingUtilities.updateComponentTreeUI(note);
  }
  catch (UnsupportedLookAndFeelException e) {e.printStackTrace(); }
  catch (ClassNotFoundException e) {e.printStackTrace();}
  catch (InstantiationException e) {e.printStackTrace();}
  catch (IllegalAccessException e) {e.printStackTrace();}
----------


작성자: JK
수정일: 2012. 02. 01.
기 능: 파일 한줄씩 읽는 답답시러운 장난감 메모장..

히스토리:
1.1
추가:
- 글꼴 변경 기능
- 저장 시 파일 확장자 .txt로 붙임
- 사용자 시스템정보 표시 기능

수정:
- 텍스트 표시 방식 변경
- 하단 UI 수정

1.0
- 색상 테마 기능 추가

Note.zip




전체적인 내용은 AWT 프레임 형태가 대부분이고..

메모장 기능을 위해 JAVA 의 스트림 관련 기능과 FileDialog 를 사용해보기 위해 오래전에 연습용으로 만들었던 주석도 없는 썰렁한 코드들 입니다.. ^^;


AWT, Swing 을 지원하는 JVM 환경에서 동작합니다..
윈도우에서만 테스트해봤지만 아마 JVM 이 설치된 OS 에서는 대부분 그럭저럭 동작하리라 예상됩니다.. ^^;


즐거운 하루 되세요..



import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
작성자: JK
작성일: 2007. 11. 26.
기 능: 파일 한줄씩 읽는 답답시러운 장난감 메모장..
*/

 

class Note extends JFrame //단순한 메모장이라 주요 기능에 실제로 쓰이는건 AWT Frame이지만 Swing컴포넌트 추가할 시 사용하기 위해 JFrame을 그냥 로딩함.. 쓸데없어질 경우 Frame로딩..
{
 MenuBar mb;
 Menu file, theme;
 MenuItem mNew, mOpen, mSave, mSColor, mTGray, mTRed, mTBlue, mTWhite, mExit;
 TextArea ta;
 Label lb;
 int tBr=255, tBg=255, tBb=255, tFr=0, tFg=0, tFb=0, lBr=20, lBg=20, lBb=20, lFr=255, lFg=255, lFb=255;

 Colors cr=new Colors();

 /**생성자
 */
 public Note()
 {
  super("Note..");

  mb=new MenuBar();
  setMenuBar(mb);
  file=new Menu("파일");
  mb.add(file);
  mNew=new MenuItem("새 파일", new MenuShortcut('N'));
  mOpen=new MenuItem("열기", new MenuShortcut('O'));
  mSave=new MenuItem("저장", new MenuShortcut('S'));
  mExit=new MenuItem("종료", new MenuShortcut('X', true));

  file.add(mNew);
  file.add(mOpen);
  file.add(mSave);
  file.addSeparator();
  file.add(mExit);

  theme=new Menu("테마");
  mb.add(theme);
  //mSColor=new MenuItem("색 조절");
  mTGray=new MenuItem("dark");
  mTRed=new MenuItem("darkRed");
  mTBlue=new MenuItem("darkBlue");
  mTWhite=new MenuItem("white");

  //theme.add(mSColor);
  //theme.addSeparator();
  theme.add(mTGray);
  theme.add(mTRed);
  theme.add(mTBlue);
  theme.add(mTWhite);

  ta=new TextArea("", 7, 50); //간간히 나오는 Frame설정과 Color와 관련된 소스는 쓰잘데기 없을 수 있으니 이해안될 경우 신경쓰지 말기를..
  //ta.setBackground(new Color(tBr, tBg, tBb));
  //ta.setForeground(new Color(tFr, tFg, tFb));
  add(ta);

  lb=new Label(" Edit..", Label.LEFT);
  //lb.setBackground(new Color(lBr, lBg, lBb));
  //lb.setForeground(new Color(lFr, lFg, lFb));
  add(lb, "South");

  cr.mTBlue();

  MyHandler mh=new MyHandler();
  mNew.addActionListener(mh);
  mOpen.addActionListener(mh);
  mSave.addActionListener(mh);
  mExit.addActionListener(mh);
  mTGray.addActionListener(mh);
  mTRed.addActionListener(mh);
  mTBlue.addActionListener(mh);
  mTWhite.addActionListener(mh);

  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  //addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
 }

 class Colors
 {
  public void mTGray()
  {
   tBr=33; tBg=33; tBb=33; tFr=151; tFg=151; tFb=151; lBr=25; lBg=28; lBb=31; lFr=246; lFg=246; lFb=246;
   ta.setBackground(new Color(tBr, tBg, tBb));
   ta.setForeground(new Color(tFr, tFg, tFb));
   lb.setBackground(new Color(lBr, lBg, lBb));
   lb.setForeground(new Color(lFr, lFg, lFb));
  }
  public void mTRed()
  {
   tBr=102; tBg=0; tBb=0; tFr=241; tFg=41; tFb=56; lBr=32; lBg=8; lBb=9; lFr=255; lFg=204; lFb=204;
   ta.setBackground(new Color(tBr, tBg, tBb));
   ta.setForeground(new Color(tFr, tFg, tFb));
   lb.setBackground(new Color(lBr, lBg, lBb));
   lb.setForeground(new Color(lFr, lFg, lFb));
  }
  public void mTBlue()
  {
   tBr=54; tBg=66; tBb=74; tFr=165; tFg=172; tFb=176; lBr=27; lBg=35; lBb=42; lFr=255; lFg=255; lFb=255;
   ta.setBackground(new Color(tBr, tBg, tBb));
   ta.setForeground(new Color(tFr, tFg, tFb));
   lb.setBackground(new Color(lBr, lBg, lBb));
   lb.setForeground(new Color(lFr, lFg, lFb));
  }
  public void mTWhite()
  {
   tBr=255; tBg=255; tBb=255; tFr=0; tFg=0; tFb=0; lBr=20; lBg=20; lBb=20; lFr=255; lFg=255; lFb=255;
   ta.setBackground(new Color(tBr, tBg, tBb));
   ta.setForeground(new Color(tFr, tFg, tFb));
   lb.setBackground(new Color(lBr, lBg, lBb));
   lb.setForeground(new Color(lFr, lFg, lFb));
  }
 }

 /**이벤트 처리용 이너 클래스
 */
 class MyHandler implements ActionListener
 {
  Colors cr=new Colors();

  public void actionPerformed(ActionEvent e)
  {
   Object o=e.getSource();

   String gf, gd, line="";

   if (o==mNew)
   {
    ta.setText("");
    lb.setText(" Edit..");
   }
   else if (o==mOpen)
   {
    FileDialog fd=new FileDialog(Note.this, "열기");
    fd.setVisible(true);

    gf=fd.getFile(); //파일 다어얼로그를 사용해 파일명과 디렉토리명을 얻어온다.
    gd=fd.getDirectory();

    ta.setText(""); //append()로 한줄씩 출력하는 방식이라 파일을 읽어 들일 시 새로운 내용을 출력하기 위해 초기화.

    try{
     BufferedReader brf=new BufferedReader(new FileReader(gd+gf)); //파일명을 파일리더를 통해 버퍼드리더에 넣는다.
     while ((line=brf.readLine())!=null)
     {
      ta.append(line+"\n"); //한줄씩 TextArea에 출력한다.
     }
     brf.close(); //버퍼드리더를 닫는다.
    } catch (IOException ioe) {ioe.printStackTrace();}

    if (gf==null) lb.setText(" Edit..");
    else lb.setText(" Opened: "+gd+gf);
   }
   else if (o==mSave)
   {
    FileDialog fd=new FileDialog(Note.this, "저장", FileDialog.SAVE);
    fd.setVisible(true);

    gf=fd.getFile();
    gd=fd.getDirectory();

    String bd=ta.getText(); //TextArea에 적힌 내용을 스트링형 변수에 담는다.

    try
    {
     BufferedReader br=new BufferedReader(new StringReader(bd)); //스트링리더로 읽은 내용을 버퍼드리더에 담고 버퍼드라이터를 통해 파일라이터로 연결해서 파일로 출력한다.
     BufferedWriter bw=new BufferedWriter(new FileWriter(gd+gf));
     while ((line=br.readLine())!=null)
     {
      bw.write(line);
      bw.newLine(); //줄바꾸기.
      bw.flush();
     }
     br.close();
     bw.close();
    } catch (IOException ioe) {ioe.printStackTrace();}

    lb.setText(" Saved: "+gd+gf);
   }
   else if (o==mExit)
   {
    lb.setText(" Exit..");
    System.exit(0);
   }
   else if (o==mTGray)
   {
    cr.mTGray();
   }
   else if (o==mTRed)
   {
    cr.mTRed();
   }
   else if (o==mTBlue)
   {
    cr.mTBlue();
   }
   else if (o==mTWhite)
   {
    cr.mTWhite();
   }
  }
 }

 public static void main(String[] args)
 {
  Note note=new Note();
  note.setSize(700, 650);
  note.setVisible(true);
 }
}

Note.java
Note.class




오래전에 연습용으로 만들었던 거라 허접합니다.. ㅎㅎ
참고하실 분들만 참고하세요..


import java.awt.*;
import java.awt.event.*;
/**
작성일: 2007. 11. 6
작성자: JK
기  능: 색깔 세개짜리 어린이 그림판..
*/

 

public class Painter extends Frame
{
 Panel pn, pc;
 Button bto, btr, btb, btp, btm, btw, btc;
 MyCanvas can;
 Color gc=Color.black; //ActionEvent에 사용할 멤버 변수들
 int x, y, h=2, v=2;

 public Painter()
 {
  super("Painter");
  addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}}); //종료 시키는 WindowAdapter 생성

  setBackground(new Color(50, 50, 50));
  pn=new Panel();
  pc=new Panel();
  add(pn, "North");
  add(pc, "Center");
  pn.setLayout(new FlowLayout());
  pn.setBackground(Color.black);
  pc.setLayout(new FlowLayout());

  pn.add(bto=new Button("Orange"));
  bto.setForeground(Color.white);
  bto.setBackground(Color.orange);
  pn.add(btr=new Button("Red"));
  btr.setForeground(Color.white);
  btr.setBackground(Color.red);
  pn.add(btb=new Button("Black"));
  btb.setForeground(Color.white);
  btb.setBackground(Color.black);
  pn.add(btp=new Button("크게"));
  btp.setForeground(Color.white);
  btp.setBackground(new Color(50, 50, 50));
  pn.add(btm=new Button("작게"));
  btm.setForeground(Color.white);
  btm.setBackground(new Color(50, 50, 50));
  pn.add(btw=new Button("지우개"));
  btw.setForeground(Color.white);
  btw.setBackground(Color.darkGray);
  pn.add(btc=new Button("리셋"));
  btc.setForeground(Color.white);
  btc.setBackground(new Color(50, 50, 50));

  can=new MyCanvas();
  can.setSize(370, 300);
  pc.add(can);
  can.setBackground(Color.white);
  MyHandler mh=new MyHandler();
  can.addMouseMotionListener(mh);
  bto.addActionListener(mh);
  btr.addActionListener(mh);
  btb.addActionListener(mh);
  btp.addActionListener(mh);
  btm.addActionListener(mh);
  btw.addActionListener(mh);
  btc.addActionListener(mh);
 }

 class MyHandler extends MouseMotionAdapter implements ActionListener
 {
  public void mouseDragged(MouseEvent e)
  {
   x=e.getX();
   y=e.getY();
   can.repaint();
  }

  public void actionPerformed(ActionEvent e)
  {
   Object obj=e.getSource();

   if (obj.equals(bto))
   {
    //h=2; v=2;
    gc=Color.orange;
   }
   else if (obj.equals(btr))
   {
    //h=2; v=2;
    gc=Color.red;
   }
   else if (obj.equals(btb))
   {
    //h=2; v=2;
    gc=Color.black;
   }
   else if (obj.equals(btp))
   {
    h+=3;
    v+=3;
    if (h>=32) {h=32; v=32;} //브러쉬 크기를 잡아준다
   }
   else if (obj.equals(btm))
   {
    h-=3;
    v-=3;
    if (h<=2) {h=2; v=2;}
   }
   else if (obj.equals(btw))
   {
    //h=32; v=32;
    gc=Color.white;
   }
   else if (obj.equals(btc))
   {
    //pc.add(can);
    Graphics gg=can.getGraphics(); //현종이 덕에 알게된 Canvas 초기화법..
    gg.setColor(Color.white);
    gg.fillRect(0, 0, 370, 300);
   }
   setTitle("Painter [Brush Size "+h+"]"); //브러쉬 크기는 귀찮아서 그냥 타이틀에 출력
  }
 }

 class MyCanvas extends Canvas
 {
  public void update(Graphics g)
  {
   g.setColor(gc);
   g.fillOval(x, y, h, v);
  }
 }

 public static void main(String[] args)
 {
  Painter p=new Painter();
  p.setSize(400, 380);
  p.setVisible(true);
 }
}

Painter.java




장난 삼아 만들었습니다.. ㅡ.ㅡ..


/*
우리 Java형님의 말씀은 하늘인거다.
우리 1조는 형님께 절대복종하고 셧더마우스상태에서
조용히 형이 먹으라는거 먹고오면 아무문제 없는거다.
형이 메뉴추가나 변경은 약간 수정해도 된다고 하더라...
월요일부터 java형이 먹으라는거 먹으면 되는거다..

Special Thanks to 용국..
*/

 

import java.awt.*;
import java.awt.event.*;

public class LunchRoulette extends Frame implements ActionListener
{
 Panel pn;
 Label lb0, lb1, lb2, lb3, lb4, lb5;
 Button bt;
 TextField tf;

 public LunchRoulette()
 {
  super("우리 java형님의 말씀은 하늘인거다.");
  setLayout(new GridLayout(8, 1, 7, 7));
  setBackground(Color.darkGray);

  //형이 정해준 메뉴 5가지..
  lb0=new Label("아래는 점심메뉴인거다.");
  lb0.setForeground(Color.white);
  lb1=new Label("1 은 백반이다");
  lb1.setForeground(Color.white);
  lb2=new Label("2 는 짱깨다");
  lb2.setForeground(Color.white);
  lb3=new Label("3 은 뼈다귀해장국이다");
  lb3.setForeground(Color.white);
  lb4=new Label("4 는 햄버거다");
  lb4.setForeground(Color.white);
  lb5=new Label("5 는 설렁탕이다");
  lb5.setForeground(Color.white);

  bt=new Button("눌러라.");
  bt.setBackground(Color.orange);

  tf=new TextField("", 50);

  add(lb0);
  add(lb1);
  add(lb2);
  add(lb3);
  add(lb4);
  add(lb5);

  add(bt);

  add(tf);

  tf.addActionListener(this);
  bt.addActionListener(this);

  addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
 }

 public void Roulette()
 {
  //형이 랜덤으로 뽑아준 메뉴
  String mr=(String)(Math.random()*5+1+"");
  if (mr.startsWith("1"))
  {
   //형의 절대적인 명령..
   tf.setText("메뉴는 백반이 당첨된거다!!! 오늘은 닥치고 백반 먹는거다!");
   tf.setForeground(Color.black);
  }
  else if (mr.startsWith("2"))
  {
   tf.setText("메뉴는 짱개가 당첨된거다!!! 오늘은 닥치고 짱개 먹는거다!");
   tf.setForeground(new Color(133, 91, 39));
  }
  else if (mr.startsWith("3"))
  {
   tf.setText("메뉴는 뼈다귀가 당첨된거다!!! 오늘은 닥치고 해장국에 쏘주반주 하는거다!");
   tf.setForeground(Color.orange);
  }
  else if (mr.startsWith("4"))
  {
   tf.setText("메뉴는 햄버거가 당첨된거다!!! 오늘은 닥치고 맥도날드 가는거다!");
   tf.setForeground(Color.red);
  }
  else if (mr.startsWith("5"))
  {
   tf.setText("메뉴는 설렁탕이 당첨된거다!!! 오늘은 닥치고 설렁탕 먹으러간다!");
   tf.setForeground(new Color(110, 110, 110));
  }
 }

 public void actionPerformed(ActionEvent e)
 {
  Object obj=e.getSource();

  if (obj==bt)
  {
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
   tf.setText("");
   Roulette();
  }
 }

 public Insets getInsets()
 {
  return new Insets(70, 70, 70, 70);
 }

 public static void main(String[] args)
 {
  LunchRoulette lr=new LunchRoulette();
  lr.setSize(550, 400);
  lr.setVisible(true);
 }
}

LunchRoulette.java

블로그 이미지