SSISO Community

시소당

SWT 사용하기

swt-3.1-win32-win32-x86

 

swt-win32-3138.dll 를 JAVA_HOME/bin 디렉토리로 복사하고

(이클립스)프로젝트 설정에서 swt.jar 를 불러오도록 하면 된다.

이걸 몰라서 한참 헤맸었다;;

 

SWT를 사용해서 만든 윈도우와 몇가지 컨트롤들의 모습이다.


 
AWT와는 다르게 깔끔하다.
메모리 사용량은 어떨지 모르겠지만ㅋ
 
지금 javaw 프로세스의 메모리 사용량이 120MB를 넘어갔는데(-_-;;) 이클립스 때문이다. 미리 로드해놓은게 있어서 그런지 내가 만든 프로그램을 실행시켜도 메모리 사용량이 100KB 이상 늘어나거나 하지는 않는다.
 
아래는 소스코드.
 
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.*;
public class HelloWorld

 public static void main(String[] args)
 {
  Display display = new Display();
  
  int intvLeft = 20;
  int hlocation = 0;
  
  Shell shell = new Shell(display);
  shell.pack();
 // shell.setLayout(new GridLayout());
  shell.setSize(450, 400);
  shell.setText("This is a window using SWT");
  
  Label label = new Label(shell, SWT.NONE);
  label.setText("Hello World!");
  label.pack();
  label.setLocation(intvLeft, hlocation);
  hlocation += 30;
  
  Button button = new Button(shell, SWT.BUTTON1);
  button.pack();
  button.setText("This is a button");
  button.setLocation(intvLeft, hlocation);
  button.setSize(120, 24);
  hlocation += 40;
  
  Slider slider = new Slider(shell, SWT.HORIZONTAL);
  slider.pack();
  slider.setLocation(intvLeft, hlocation);
  hlocation += 30;
  
  Text text = new Text(shell, SWT.MULTI | SWT.WRAP);
  text.pack();
  text.setText("The quick brown fox jumps over the lazy dog.");
  text.setLocation(intvLeft, hlocation);
  text.setSize(400, 100);
  hlocation += 110;
  
  List list = new List(shell, SWT.MULTI | SWT.V_SCROLL);
  list.pack();
  list.add("State the nature of your medical emergency");
  list.add("What is your major malfunction?");
  list.add("Something on your mind?");
  list.add("Somebody called for an exterminator");
  list.add("Awaing instructions");
  list.setLocation(intvLeft, hlocation);
  list.setSize(400, 50);
  hlocation += 70;
  shell.open();
  
 /* 
  MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION);
  messageBox.setMessage("Message");
  messageBox.setText("Text");
  if (messageBox.open() == SWT.OK)
   System.out.println("Ok is pressed.");
 */
  
 // FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
 // System.out.println(fileDialog.open());
  
  
  while(!shell.isDisposed())
   if(!display.readAndDispatch())
     display.sleep();
         
  display.dispose();
  label.dispose();
 }
}

4141 view

4.0 stars