언어/기타
2006.09.13 06:05

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

조회 수 597 추천 수 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. 주인공 이름이 마땅한게 없다면~

    Date2006.12.12 Category언어/기타 By네모상자 Views1135
    Read More
  2. 주스는 맛있다.

    Date2006.06.27 Category언어/기타 By비밀소년 Views661
    Read More
  3. 주석제거 프로그램 (수정)

    Date2006.09.13 Category언어/기타 By청연 Views597
    Read More
  4. 죄송합니다!!질문입니다!!!!!!!!!(타일관련;;)

    Date2006.01.25 CategoryRPG Maker By마가미카무이 Views421
    Read More
  5. 좌표대입(ARPG) 사고실험.[이론편]

    Date2005.05.18 CategoryRPG Maker By늑대소년 Views1471
    Read More
  6. 좌표간 거리구하기 알아두면 좋다!

    Date2006.04.22 CategoryRPG Maker By다크아머 Views1075
    Read More
  7. 좌표간 거리 계산법

    Date2005.12.31 CategoryRPG Maker By다크아머 Views1943
    Read More
  8. 좀만변형하면 멋지게될 rgp방식 ^^: 시도하신분들 많이게 계실껀데 ㅋㅋ

    Date2005.11.12 CategoryRPG Maker By*YeNa* Views637
    Read More
  9. 조건분기:***번호의 스위치가 ON

    Date2006.01.07 Category언어/기타 ByCC(虎) Views477
    Read More
  10. 제작노트의 힘! - 게임제작속도를 올려주마!

    Date2006.03.12 Category언어/기타 By『덩키동크』 Views748
    Read More
  11. 제어문자 간편하게 쓰기

    Date2007.02.13 Category언어/기타 ByEverSmileMan Views1202
    Read More
  12. 제글읽고 답좀...

    Date2006.01.09 CategoryRPG Maker ByONEVlN Views400
    Read More
  13. 제곱근의 연산

    Date2006.08.09 Category언어/기타 ByYggdrasil Views597
    Read More
  14. 제가 지금 NPC가 말하는 것을 하려고 하는데 어떻게 하죠?

    Date2006.01.13 Category언어/기타 By게임만들기폐인 Views409
    Read More
  15. 제가 만들어본 전투시스템 예제입니다.

    Date2006.07.22 Category언어/기타 By윈드 Views940
    Read More
  16. 제가 만들어본 온리 100%이벤트trpg 예제 -수정-

    Date2006.07.26 CategoryRPG Maker By*YeNa* Views713
    Read More
  17. 제 2 부 ! 나도 게임을 만들수 있다 !

    Date2006.06.01 Category언어/기타 By다크세이버™ Views584
    Read More
  18. 제 1 부 ! 도전 ! 나도 게임 만들 수 있다!

    Date2006.05.23 Category언어/기타 By다크세이버™ Views990
    Read More
  19. 정신력 시스템

    Date2006.06.28 Category언어/기타 By비밀소년 Views699
    Read More
  20. 정말 쓸모없는 일입니다만 저가 쓰고있는방법...

    Date2006.01.16 Category언어/기타 By無正死人 Views315
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 51 Next
/ 51






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

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