언어/기타
2006.09.13 06:05

주석제거 프로그램 (수정)

조회 수 625 추천 수 1 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 수정 삭제
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 수정 삭제
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

class NotePad extends Frame implements WindowListener, ActionListener
{
Menu file, edit, sub, comment;
MenuBar mb;
MenuItem it[] = new MenuItem[17];
TextArea txtP;
FunctionMemo memo;

public NotePad()
{
super("메모장");
mb = new MenuBar();
file = new Menu("파일(F)");
edit = new Menu("편집(E)");
comment = new Menu("주석제거");
txtP = new TextArea();
memo = new FunctionMemo(txtP,this);

/////////////////////////////////////////////////////file

file.add(it[0] = new MenuItem("새로만들기(N)", new MenuShortcut(KeyEvent.VK_N)));
file.add(it[1] = new MenuItem("열기(O)...",new MenuShortcut(KeyEvent.VK_O)));
file.add(it[2] = new MenuItem("저장(S)",new MenuShortcut(KeyEvent.VK_S)));
file.add(it[3] = new MenuItem("다른이름으로저정(A)..."));
file.addSeparator();
file.add(it[4] = new MenuItem("끝내기(X)"));

/////////////////////////////////////////////////////edit

edit.add(it[5] = new MenuItem("실행취소(U)",new MenuShortcut(KeyEvent.VK_U)));
edit.addSeparator();
edit.add(it[6] = new MenuItem("잘라내기(X)",new MenuShortcut(KeyEvent.VK_X)));
edit.add(it[7] = new MenuItem("복사(C)",new MenuShortcut(KeyEvent.VK_C)));
edit.add(it[8] = new MenuItem("붙여넣기(V)",new MenuShortcut(KeyEvent.VK_V)));
edit.add(it[9] = new MenuItem("삭제(D)",new MenuShortcut(KeyEvent.VK_D)));
edit.addSeparator();
edit.add(it[10] = new MenuItem("찾기(F)...",new MenuShortcut(KeyEvent.VK_F)));
edit.add(it[11] = new MenuItem("다음찾기(N)",new MenuShortcut(KeyEvent.VK_N)));

CheckboxMenuItem c1 = new CheckboxMenuItem("바꾸기(R)...",true);
CheckboxMenuItem c2 = new CheckboxMenuItem("이동(G)...",true);
edit.add(c1);
edit.add(c2);
edit.addSeparator();
edit.add(it[12] = new MenuItem("모두선택",new MenuShortcut(KeyEvent.VK_A)));
edit.add(it[13] = new MenuItem("시간/날짜"));

/////////////////////////////////////////////////

sub = new Menu("제작노트");
sub.add(it[14] = new MenuItem("소스보기"));
sub.add(it[15] = new MenuItem("제 작 자"));
comment.add(it[16] = new MenuItem("주석 제거"));

for(int i=0; iaddWindowListener(this);

edit.add(sub);
mb.add(file);
mb.add(edit);
mb.add(comment);

setMenuBar(mb);
add("Center",txtP);

setSize(600,600);
setVisible(true);
}


public void actionPerformed(ActionEvent e){

java.lang.Object Mname = e.getSource();

if (Mname == it[0]) memo.Newf();
else if(Mname == it[1]) memo.Open();
else if(Mname == it[2]) memo.Save();
else if(Mname == it[3]) memo.OSave();
else if(Mname == it[4]) memo.End();
else if(Mname == it[5]) ;
else if(Mname == it[6]) ;
else if(Mname == it[7]) ;
else if(Mname == it[8]) ;
else if(Mname == it[9]) ;
else if(Mname == it[10]) ;
else if(Mname == it[11]) ;
else if(Mname == it[12]) ;
else if(Mname == it[13]) memo.TimeDate();
else if(Mname == it[14]) memo.Source();
else if(Mname == it[15]) memo.JungGu();
else if(Mname == it[16]) {
commDel skip = new commDel();
txtP.setText(skip.commprt(txtP.getText()));
}
}

public void windowClosing(WindowEvent e){
if(memo.ONs == true) memo.AlterPr(2);
System.exit(0);
}
public void windowClosed (WindowEvent e){}
public void windowDeactivated (WindowEvent e){}
public void windowDeiconified (WindowEvent e){}
public void windowIconified (WindowEvent e){}
public void windowOpened (WindowEvent e){}
public void windowActivated (WindowEvent e){}

public static void main(String[] args){
new NotePad();
}
}

/**************************************************************************************
///////////////////////////////////////////////////////////////////////////////////////

메모장 메뉴 실행 클래스

///////////////////////////////////////////////////////////////////////////////////////
**************************************************************************************/
class FunctionMemo implements MouseListener, TextListener{


TextArea TA;
FileDialog file_o, file_s;
Frame FR;
Dialog junggu, junggu2;
Button d, d2, d3, d4;
boolean ONs = false;
int indexs =0, openNew=2;

static String name = ""; // 처음 프로그램 시작 부터 저장명령을 사용할때를 대비해서..


public FunctionMemo(TextArea TA,Frame FR){

this.TA = TA;
this.FR = FR;
this.TA.addTextListener(this);
}

/********************************************
/////////////////////////////////////////////

새파일 만들기 명령 함수

/////////////////////////////////////////////
********************************************/
void Newf(){

if(ONs == true){ // 문서에 변경여부를 판단한다.
AlterPr(1); // 변경 되었다면 true 이다.
ONs = false;
}else{
TA.setText("");

FunctionMemo.name = "";
FR.setTitle("noname.txt");
openNew = 1; // 처음 파일이 열릴때도 문서가 변경된걸로
// 알기 때문에 처음 열리는 파일에서는 막아줘야한다.
}
}

/********************************************
/////////////////////////////////////////////

파일열기 명령 함수

/////////////////////////////////////////////
********************************************/
void Open(){

if(ONs == true){
AlterPr(2);
ONs = false;
}else{
file_o = new FileDialog(FR,"파일 열기",FileDialog.LOAD);
file_o.setVisible(true);

String na = file_o.getDirectory();
String me = file_o.getFile();

if (na != null && me != null){ // 파일 다이얼로그를 연다음 취소 버튼을 눌를 경우
// 경로와 이름이 널값이 된다.
FunctionMemo.name = na+me;

FunctionFile op = new FunctionFile(na+me,1); // FunctionFile(파일경로/파일명, mode);
FR.setTitle(me); // 파일 전체경로명과 파일명을 붙여서 써준다. 1은 읽기,2는 쓰기 모드
TA.setText(op.FileRead()+""); // FileRead() 파일을 읽어옴.. 한방에 몽땅
openNew = 1;

}
}
}

/********************************************
/////////////////////////////////////////////

파일저장 명령 함수

/////////////////////////////////////////////
********************************************/
void Save(){

FunctionFile op;

if(FunctionMemo.name.equals("") || FunctionMemo.name == null){ // 기존에 열어논 파일을 그냥 저장 시킬경우와
// 그렇지 않고 새로 저장 하는 경우
file_s = new FileDialog(FR,"파일 저장",FileDialog.SAVE);
file_s.setVisible(true);

String na = file_s.getDirectory();
String me = file_s.getFile();

if (na != null && me != null){

FunctionMemo.name = na + me;

op = new FunctionFile(na+me,2);
FR.setTitle(me);
op.FileWrite(TA.getText());
}

}else{

op = new FunctionFile(FunctionMemo.name,2); // FunctionFile(파일경로/파일명, mode);
op.FileWrite(TA.getText()); // FileWrite(TextArea t); 파일을 한방에 만들어줌..
}

ONs = false;

}

/********************************************
/////////////////////////////////////////////

다른 이름으로 파일저장 명령 함수

/////////////////////////////////////////////
********************************************/
void OSave(){

String imsi_name = FunctionMemo.name;
FunctionMemo.name = "";

file_s = new FileDialog(FR,"다른 이름으로 파일 저장",FileDialog.SAVE);
file_s.setVisible(true);

String na = file_s.getDirectory();
String me = file_s.getFile();

if (na != null && me != null){

FunctionMemo.name = na+me;

FunctionFile op = new FunctionFile(FunctionMemo.name,2);

FR.setTitle(me);
op.FileWrite(TA.getText());
}else{

FunctionMemo.name = imsi_name;
}

ONs = false;

}

/********************************************
/////////////////////////////////////////////

소스보기 명령 함수

/////////////////////////////////////////////
********************************************/
void Source(){

FunctionFile op = new FunctionFile("NotePad.java",1);
TA.setText(op.FileRead()+"");
FR.setTitle("소스보기");
}


/********************************************
/////////////////////////////////////////////

제작자 보기 명령 함수

/////////////////////////////////////////////
********************************************/
void JungGu(){

junggu = new Dialog(FR,"제작자",false);

Label a,b,c,e;

a = new Label("제작한놈 : 문정구");
b = new Label("제작날짜 : 2002년 6월 19일 인가?");
e = new Label("Version : M0.5v");
c = new Label("제작장소 : 집 한쪽 귀탱이");
d = new Button(" 확 인 ");

junggu.setLayout(new GridLayout(5,1));

d.addMouseListener(this);

junggu.add(a);
junggu.add(b);
junggu.add(c);
junggu.add(e);
junggu.add(d);

junggu.setSize(225,160);
junggu.show();
}

void End(){ if(ONs == true)AlterPr(2); System.out.println(ONs); System.exit(0); }

void TimeDate(){

times start = new times();
start.timedate();
}

/********************************************
/////////////////////////////////////////////

파일관리 명령 함수

/////////////////////////////////////////////
********************************************/
void AlterPr(int indexs_sub){

junggu2 = new Dialog(FR,"경고창",false);
indexs = indexs_sub;

Label a2;

a2 = new Label("저장 하시겠습니까?");
d2 = new Button(" 예 ");
d3 = new Button("아니요");
d4 = new Button("취 소");

junggu2.setLayout(new FlowLayout());

d2.addMouseListener(this);
d3.addMouseListener(this);
d4.addMouseListener(this);

junggu2.add(a2);
junggu2.add(d2);
junggu2.add(d3);
junggu2.add(d4);

junggu2.setSize(170,100);
junggu2.show();
}

public void mouseClicked (MouseEvent e){

java.lang.Object sara = e.getSource();

if(sara == d ){

junggu.dispose();

}else if(sara == d2){

junggu2.dispose();
Save();

}else if(sara == d3){

junggu2.dispose();

if (indexs == 2){ Open(); }
else if (indexs == 1){ Newf(); }

}else if(sara == d4){

junggu2.dispose();
ONs = true;

}
}

public void mouseEntered (MouseEvent e){}
public void mouseExited (MouseEvent e){}
public void mousePressed (MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void textValueChanged (TextEvent e){

if(openNew != 1) ONs = true;
else openNew = 2;

}

}

/**************************************************************************************
///////////////////////////////////////////////////////////////////////////////////////

파일 다루는 클래스

///////////////////////////////////////////////////////////////////////////////////////
**************************************************************************************/
class FunctionFile{

String addimsi;
String imsi;
FileReader out;
BufferedReader bis;
FileWriter ins;

public FunctionFile(String filename,int rw){

addimsi = "";
imsi = "";

try {
if(rw == 1){

out = new FileReader(filename);
bis = new BufferedReader(out);

}else if(rw == 2){

ins = new FileWriter(filename);

}

}catch(IOException err){ ;}
}

/********************************
파일읽기 함수
********************************/
String FileRead(){

try{
int i=1;

while((imsi = bis.readLine()) != null) {

addimsi += imsi+"n";
// i++;
}

}catch(IOException err){ ;}

return addimsi;

}

/********************************
파일저장 함수
********************************/
void FileWrite(String s){

try{

ins.write(s);
ins.close();

}catch(IOException err){ ;}
}

}

/**************************************************************************************
///////////////////////////////////////////////////////////////////////////////////////

시간,날짜 다루는 클래스

///////////////////////////////////////////////////////////////////////////////////////
**************************************************************************************/

class times extends Frame{

String s;
GregorianCalendar time_;
Label ti = new Label("잠시 기다려 주세요");
Dialog junggu;

public times(){

junggu = new Dialog(this,"시간",false);

junggu.add(ti);
junggu.setSize(130,60);
junggu.show();

junggu.addWindowListener(new close());
}

public void timedate(){

time_ = new GregorianCalendar();

s=time_.get(GregorianCalendar.MONTH)+"월 "+time_.get(GregorianCalendar.DAY_OF_MONTH)+"일 "+time_.get(10)+ " : " +time_.get(12)+ " : "+time_.get(13);

try{
Thread.sleep(1000);
}catch(Exception e){ System.out.println("에러메세지: "+e);}

ti.setText(s+"");

this.timedate();
}

}

class close extends WindowAdapter{

public void windowClosing(WindowEvent e){

// this.dispose();

}
}


/**************************************************************************************
///////////////////////////////////////////////////////////////////////////////////////

주석을 제거하기 위한 클래스

///////////////////////////////////////////////////////////////////////////////////////
**************************************************************************************/
class commDel{

/********************************************
/////////////////////////////////////////////

들어온 문자열에서 파일명만 가져오는 함수

/////////////////////////////////////////////
********************************************/

protected String filesearch(String St){

int num = St.length();

char realfile[] = new char[num];
int i=0, j =0 ;
String s="";
System.out.println(num);

for(i = num-1; i >= 0; i--){

if(St.charAt(i) == '\' || St.charAt(i) == '/') break;
realfile[i] = St.charAt(i);
j++;
}

s = String.valueOf(realfile,(i+1),j);
return s+".txt";
}

/********************************************
/////////////////////////////////////////////

문자열을 나눠서 첫번째 문자만 리턴하는 함수

/////////////////////////////////////////////
********************************************/

protected String commit(String bon, String ti){

StringTokenizer su = new StringTokenizer(bon, ti);
su.hasMoreElements();

try{
String ko = su.nextToken().trim();
return (ko.equals("")) ? ko : ko+"n";
}catch(NoSuchElementException err){
return "";
}
}

/********************************************
/////////////////////////////////////////////

주석 제거 함수

/////////////////////////////////////////////
********************************************/

public String commprt(String comm){

String addimsi="";

try {
StringTokenizer su = new StringTokenizer(comm,"n");
char ch;
boolean lock = false ;
String imsi="";
String front="";
int start = 1;

/****************첫째 와일문 시작***************/
while(su.hasMoreElements()){

imsi = su.nextToken();
int num = imsi.length();
int var=0;
int i =0;

// System.out.println(imsi); // 버그 찾기위해서.. 넣어둠

/****************첫번째 이프문 시작***************/
if(num > 1){ // 아무것도 없는 빈줄 가리기
// 밑에 while문에서 빈줄은 값이 없기때문에
// 스트링 인덱스 ,길이 0 이란 에러가 난다.

/****************두번째 와일문 시작***************/
while((ch = imsi.charAt(i)) != ''){

// for(i=0; num>i; i++){

// ch = imsi.charAt(i);

// lock값을 같이 꼭 비교해줘야 스트링 인덱스 에러가 안나다.
// 이유는 / 문자가 마지막에 발견되면 뒤에 +1은 에러가 나고
// /문자가 처음에 발견될 경우는 -1이 에러가 생긴다.

/****************두번째 이프문 시작***************/
if(lock == false && ch == '/' && imsi.charAt(i+1) == '*'){

// 밑에 같은 주석이 나올경우 앞에 문자열 더하기
// data = new int[3] /* 주석
front = commit(imsi,"/*");
if(!(front.equals(""))){ addimsi += front; front = ""; }

// 밑에 같은 주석이 나올경우 한라인 끝내기
// /* 주석 */

imsi.trim();
if(imsi.charAt(num-2) == '*' && imsi.charAt(num-1) == '/'){ var = 1; break; }

lock = true;
break;

}else if(lock == true && imsi.charAt(num-1) == '*'){

var = 1;
break;

}else if(lock == true && ch == '*' && imsi.charAt(i+1) == '/'){

lock = false;
var = 1;
break;

// 주석문 앞에 소스가 있을경우와 밑에 같이 //주석처리를 문자로 할경우
// 한문장이 다 지워지지 않게 하기 위해서..

}else if(lock == false && ch == '/' && imsi.charAt(i+1) == '/'){
if(imsi.charAt(i+2) == ''' || imsi.charAt(i+2) == '"'){ }
else{
var = 1;
front = commit(imsi,"//");
addimsi += front;
front = "";
break;
}
}
/*******************두번째 이프문 끝********************/


if(num-1 == i) break; i++; // while문 쓸때..

}
/*******************첫번째 와일문 끝********************/

}else{ ; } /*******************첫번째 이프문 끝********************/

if(lock != true && var != 1) { addimsi += start+"t"+imsi+"n"; start++;}
var = 0;


} /*******************두번째 와일문 끝********************/


}catch(Exception err){ addimsi = "파일이 없습니다."; }

return addimsi;
}
}
?

  1. 물체 밀어서 움직이는 이벤트 조금 더 쉽게 하는 법

    Date2018.01.02 CategoryRPG Maker Byzero? Views644
    Read More
  2. [마지막 3명 모집] [취업연계무료교육] VR/AR 게임 콘텐츠 전문가 양성 과정 교육생 모집

    Date2017.07.14 Category언어/기타 By황금상자 Views702
    Read More
  3. rpg vxa 로 겜만들때 데미지 설정 공식[링크]

    Date2017.06.08 CategoryRPG Maker By준E Views740
    Read More
  4. [꿀팁] 간단하게 만들 수 있는 실시간 전투 시스템

    Date2017.03.31 CategoryRPG Maker By준E Views2019
    Read More
  5. JSON parser 변환데이터 저장시 생기는 Object Too Deep 해결하기

    Date2016.12.24 Category언어/기타 Bytitle: 댓글러lklslel Views851
    Read More
  6. 앙뜨프리너십에서 해커톤 부트캠프 모집중이네요

    Date2016.11.08 Category언어/기타 By마나님이 Views908
    Read More
  7. RPG MV에서 플러그인 오류의 원인에 대하여

    Date2016.07.08 CategoryRPG Maker Bytitle: 댓글러lklslel Views2359
    Read More
  8. RPG MV 게임 도중에 윈도우 스킨 파일 자체를 통째로 바꿔버리는 방법 (출처: HIME)

    Date2016.07.08 CategoryRPG Maker By최저 Views1627
    Read More
  9. 게임의 버전을 짜 보자! - 유의적 버전 2.0.0

    Date2016.06.07 Category언어/기타 ByYanggaeng Views1123
    Read More
  10. 텍스트 대화 도중 메뉴 여는 방법을 알아냈습니다!

    Date2016.03.12 CategoryRPG Maker By정궈니 Views2938
    Read More
  11. rpgmv 마우스 지원과 터치 지원이 되니.

    Date2015.10.25 CategoryRPG Maker By팡소리 Views1011
    Read More
  12. RPG Maker MV 와 AJAX를 이용한 웹통신 관련 영상.

    Date2015.10.25 CategoryRPG Maker ByHT9MAN Views2246
    Read More
  13. RPG게임 뻔한요소들.

    Date2015.10.05 Category언어/기타 Bytitle: 천무천무 Views1644
    Read More
  14. 자바스크립트와 관련해서 참고할 만한 사이트들

    Date2015.10.04 Category언어/기타 ByMARCO Views921
    Read More
  15. 꿀잼이군요!

    Date2015.05.20 Category언어/기타 By사람님[대회참가] Views873
    Read More
  16. [RPG2000/3 팁] 간편한 이벤트 단축키

    Date2015.04.06 CategoryRPG Maker Bytitle: 자게이하앵 Views1833
    Read More
  17. [RPG2000/3 팁] 간편한 이벤트 단축키

    Date2015.04.05 CategoryRPG Maker Bytitle: 자게이하앵 Views748
    Read More
  18. [강의링크] 대비법칙-색상대비-밀당의 재미 약한 반대색 설계

    Date2015.04.02 Category언어/기타 Bytitle: 천무천무 Views636
    Read More
  19. 오다 주웠습니다.

    Date2015.03.30 Category언어/기타 By사람님[대회참가] Views917
    Read More
  20. 무료 이미지 사이트 Pixabay!

    Date2015.03.28 Category언어/기타 By나작소 Views909
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 51 Next
/ 51


[개인정보취급방침] | [이용약관] | [제휴문의] | [후원창구] | [인디사이드연혁]

Copyright © 1999 - 2016 INdiSide.com/(주)씨엘쓰리디 All Rights Reserved.
인디사이드 운영자 : 천무(이지선) | kernys(김원배) | 사신지(김병국)