String으로 선언한 변수사용
딸기향
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.Shell;
import java.net.*;
import java.io.*;
import java.awt.event.*;
public class FileSendClient{
String directory=;
String file=;public static void main(String args[]){final Display display = new Display();
//Image image = display.getSystemImage(SWT.ICON_QUESTION);
final Shell shell = new Shell(display);
shell.setLayout (new GridLayout());
shell.open();
final FileDialog dialog = new FileDialog(shell, SWT.MULTI);
Button button1 = new Button(shell, SWT.PUSH);
button1.setText(파일선택);
button1.pack();
button1.setLocation(30, 30);
Button button2 = new Button(shell, SWT.PUSH);
button2.setText(파일전송);
button2.pack();
button2.setLocation(30, 90);
final Text text1 = new Text(shell, SWT.PUSH);
text1.pack();
text1.setSize(120, 10);
text1.setLocation(30, 60);
button1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
dialog.setFilterPath (c:\\); //Windows path
dialog.open();
directory=dialog.getFilterPath();
file=dialog.getFileName();
text1.setText(directory+file);
}
});Socket s = new Socket(127.0.0.1, 3333); /* 소켓으로부터 OutputStream 얻어서 파일명을 먼저 보냄 */
/* 서버측에서 파일 객체 생성시 이용할 것임 */
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
//System.out.println(파일명 : +file);
bw.write(file+\n);
bw.flush();
/* 선택한 파일로 부터 스트림을 읽어들여서 얻어놓은 OutputStream에 연결 */
DataInputStream dis=new DataInputStream(new FileInputStream(new File(text1.getText())));
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
/* 바이트단위로 읽어서 스트림으로 쓰기 */
int b=0;
while( (b=dis.read()) != -1 ){
dos.writeByte(b); dos.flush();
}
/* 자원정리 */
dis.close(); dos.close(); s.close();
dis=null; dos=null; s=null;
System.exit(1);
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}버튼을 클릭하면 파일다이얼로그가 떠서 선택한 파일을 전송하는 프로그램을 작성하였습니다.
String으로 선언한 변수를 메인안에서, 그리고 이벤트 클릭을 다루는 메소드 안에서 사용하고 싶은데
어떻게 선언해야 쓸수 있는지 잘 모르겠습니다.
-
개굴츼
static
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2701151 | 사이트작업시 inputbox 가 readonly 형태표시 어떻게 하시나요? (1) | 찬내 | 2025-07-11 |
2701123 | 간단한 select 질문입니다 (3) | 천사의눈물 | 2025-07-11 |
2701061 | 비베질문.. | 똘끼 | 2025-07-10 |
2701034 | 메일폼 내 script 삽입가능한 방법 없을까요.. (2) | 마음새 | 2025-07-10 |
2701008 | 분명히 버튼을 만들었는데 액션이 안걸립니다. (3) | 재찬 | 2025-07-10 |
2700923 | 전체중앙정렬&독타입&쿼크모드 ㅜㅠ (8) | 푸른들 | 2025-07-09 |
2700893 | 질문드리겠습니다. | 도도한 | 2025-07-09 |
2700793 | 무비클립에 마우스 오버시 랜덤으로 효과음 나기는 어떻게 ;; (1) | 바닐라 | 2025-07-08 |
2700741 | 웹전송? (2) | 연와인 | 2025-07-07 |
2700686 | 카테고리 호버시 세부카테고리 보이게하는 것, css로만 가능할까요?? (3) | 다힘 | 2025-07-07 |
2700658 | 메타태그 질문드립니다..ㅠㅠ;;; | 모해 | 2025-07-07 |
2700632 | 외부에서 이미지 파일을 불러와야 합니다. 도와주세요. (4) | 에일린 | 2025-07-06 |
2700579 | (air + as3) smtp 이용해서 첨부파일 포함해서 메일 보내기 | 물보라 | 2025-07-06 |
2700524 | 클릭시 밑에 메뉴 나오게 (4) | 새솔 | 2025-07-05 |
2700505 | activex를 비쥬얼6.0으로 만들었는데요 비스타 배포시에 안되서 질문드립니다 (3) | 참이 | 2025-07-05 |
2700452 | c언어에서... 자료형 구분.... (3) | 시내 | 2025-07-05 |
2700422 | 버전에 관해 질문 | 라온제나 | 2025-07-04 |
2700393 | mysql이 갑자기!!!!!!!!!!!!!!!에러가;; (2) | 소미 | 2025-07-04 |
2700359 | 3.0 ) SimpleButton 상태 강제 변경 (3) | 희선 | 2025-07-04 |
2700304 | ie8 전용핵 문의 (3) | 여자 | 2025-07-03 |