'swt'에 해당되는 글 2건

  1. 2007.09.06 swt/jface 에서 예외 처리
  2. 2007.08.08 이클립스 실전 플러그인 개발
swt 와 jface 로 만든 프로그램에서 예외가 발생했을 때 프로그래머가 이에 대한 처리를 제대로 하지 않으면 어떻게 될까?


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class SwtMain {

/**
* @param args
*/
public static void main(String[] args) {
Display d = new Display() ;
Shell s = new Shell(d) ;

Button btn = new Button(s , SWT.PUSH) ;

btn.setText("throw") ;

btn.addSelectionListener(
new SelectionListener() {

public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub

}

public void widgetSelected(SelectionEvent arg0) {
throw new RuntimeException("clicked") ;

}

}) ;


btn.pack() ;
s.pack() ;
s.open() ;

while( !s.isDisposed() ) {
if(!d.readAndDispatch()) {
d.sleep() ;
}
}
d.dispose() ;


}

}


import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class JFaceMain extends ApplicationWindow {

public JFaceMain() {
super(null);
}

@Override
protected Control createContents(Composite parent) {

Button btn = new Button(parent , SWT.PUSH) ;

btn.setText("throw") ;

btn.addSelectionListener(
new SelectionListener() {

public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub

}

public void widgetSelected(SelectionEvent arg0) {
throw new RuntimeException("clicked") ;

}

}) ;
btn.pack() ;

return parent ;
}

public static void main(String [] args) {
JFaceMain win = new JFaceMain() ;
win.setBlockOnOpen(true) ;
win.open() ;
Display.getCurrent().dispose() ;
}
}


두 프로그램 모두 버튼을 하나 만든 후 버튼을 클릭하면 예외가 발생한다. swt 버전은 버튼을 클릭하면 커맨드창에 예외 트레이스가 표시되고 프로그램이 죽는다. 반면에 jface 버전은 예외 트레이스는 표시되지만 프로그램이 죽지는 않는다. 버튼을 또 눌러보면 정상적으로 동작한다. jface 는 내부적으로 뭔가를 더 처리해주는듯하다.
Posted by lispholic
,
사용자 삽입 이미지

에이콘출판사

Eclipse: Building Commercial-Quality Plug-ins 의 한글판이 출간되었다. 사봐야 할지 고민중이다.
어째서 에이콘은 샘플챕터를 제공하지 않는 것인지...

출판사페이지
Posted by lispholic
,