BBS > java

RCP Example

작성자 : 이창우 (x1wins) | 등록일 : 2011-06-03 | 목록
첨부 파일이 없습니다.
첨부 이미지가 없습니다.
package test;

import javax.jws.Oneway;
import javax.swing.plaf.basic.BasicOptionPaneUI.ButtonActionListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TextFieldExample2 {

  Display d;

  Shell s;

  TextFieldExample2() {
    d = new Display();
    s = new Shell(d);
    s.setLayout(new GridLayout(2, true));
    s.setSize(500, 500);
    s.setText("A Text Field Example");
    
    Label ip = new Label(s, SWT.NULL);
    ip.setText("ip");
//    ip.setBounds(30, 50, 50, 20);
    final Text ipText = new Text(s, SWT.SINGLE | SWT.BORDER);
    ipText.setText("61.73.60.51");
//  text1.setBounds(100, 50, 100, 20);
    
   
    Label port = new Label(s, SWT.NULL);
    port.setText("port");
//    port.setBounds(30, 75, 50, 20);
    final Text portText = new Text(s, SWT.SINGLE | SWT.BORDER);
    portText.setText("30000");
//    text2.setBounds(100, 75, 100, 20);
    
    Button resetButton = new Button(s, SWT.BUTTON1);
    resetButton.setText("reset");
    Button connectButton = new Button(s, SWT.BUTTON1);
    connectButton.setText("connecting");
    Button cancelButton = new Button(s, SWT.BUTTON1);
    cancelButton.setText("cancel");
    
    resetButton.addListener(SWT.Selection, new Listener() {
		
		@Override
		public void handleEvent(Event arg0) {
			// TODO Auto-generated method stub
			ipText.setText("");
			portText.setText("");
		}
	});
    
    connectButton.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event event) {
//			Shell shell = new Shell();
//		    NumberInputDialog dialog = new NumberInputDialog(shell);
//			new TemperatureConverter();
//			s.dispose();
		}
	});
    
	cancelButton.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event event) {
			s.dispose();
		}
	});
    
    s.open();
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }

  public static void main(String[] arg) {
    new TextFieldExample2();
    
//    System.out.println("over");
  }

}
package test;

import javax.jws.Oneway;
import javax.swing.plaf.basic.BasicOptionPaneUI.ButtonActionListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TextFieldExample2 {

  Display d;

  Shell s;

  TextFieldExample2() {
    d = new Display();
    s = new Shell(d);
    s.setLayout(new GridLayout(2, true));
    s.setSize(500, 500);
    s.setText("A Text Field Example");
    
    Label ip = new Label(s, SWT.NULL);
    ip.setText("ip");
//    ip.setBounds(30, 50, 50, 20);
    final Text ipText = new Text(s, SWT.SINGLE | SWT.BORDER);
    ipText.setText("61.73.60.51");
//  text1.setBounds(100, 50, 100, 20);
    
   
    Label port = new Label(s, SWT.NULL);
    port.setText("port");
//    port.setBounds(30, 75, 50, 20);
    final Text portText = new Text(s, SWT.SINGLE | SWT.BORDER);
    portText.setText("30000");
//    text2.setBounds(100, 75, 100, 20);
    
    Button resetButton = new Button(s, SWT.BUTTON1);
    resetButton.setText("reset");
    Button connectButton = new Button(s, SWT.BUTTON1);
    connectButton.setText("connecting");
    Button cancelButton = new Button(s, SWT.BUTTON1);
    cancelButton.setText("cancel");
    
    resetButton.addListener(SWT.Selection, new Listener() {
		
		@Override
		public void handleEvent(Event arg0) {
			// TODO Auto-generated method stub
			ipText.setText("");
			portText.setText("");
		}
	});
    
    connectButton.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event event) {
//			Shell shell = new Shell();
//		    NumberInputDialog dialog = new NumberInputDialog(shell);
//			new TemperatureConverter();
//			s.dispose();
		}
	});
    
	cancelButton.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event event) {
			s.dispose();
		}
	});
    
    s.open();
    while (!s.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }

  public static void main(String[] arg) {
    new TextFieldExample2();
    
//    System.out.println("over");
  }

}
package test;

/******************************************************************************
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * All right reserved. 
 * 
 * Created on Jan 16, 2004 1:23:25 AM by JACK
 * $Id$
 * 
 * visit: http://www.asprise.com/swt
 *****************************************************************************/

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class TemperatureConverter {
  Display display = new Display();
  Shell shell = new Shell(display);

  Label fahrenheitLabel;
  Label celsiusLabel;
  Label messageLabel;

  Text fahrenheitValue;
  Text celsiusValue;

  public TemperatureConverter() {
    shell.setText("SWT Temperature Converter");
    shell.setLayout(new GridLayout(4, false));

    fahrenheitLabel = new Label(shell, SWT.NULL);
    fahrenheitLabel.setText("Fahrenheit: ");

    fahrenheitValue = new Text(shell, SWT.SINGLE | SWT.BORDER);

    celsiusLabel = new Label(shell, SWT.NULL);
    celsiusLabel.setText("Celsius: ");

    celsiusValue = new Text(shell, SWT.SINGLE | SWT.BORDER);
    
    messageLabel = new Label(shell, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 4;
    messageLabel.setLayoutData(gridData);

    ModifyListener listener = new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        valueChanged((Text) e.widget);
      }
    };

    fahrenheitValue.addModifyListener(listener);
    celsiusValue.addModifyListener(listener);

    shell.pack();
    shell.open();

    // Set up the event loop.
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        // If no more entries in event queue
        display.sleep();
      }
    }

    display.dispose();
  }

  /**
   * Performs conversion when one of the text fields changes.
   * 
   * @param text
   *            the event source
   */
  public void valueChanged(Text text) {
    if (!text.isFocusControl())
      return;

    if (text == fahrenheitValue) {
      try {
        double fValue = Double.parseDouble(text.getText());
        double cValue = (fValue - 32) / 1.8;
        celsiusValue.setText(Double.toString(cValue));
        System.out.println("F -> C: " + cValue);
        messageLabel.setText("Conversion performed successfully.");
      } catch (NumberFormatException e) {
        celsiusValue.setText("");
        messageLabel.setText("Invalid number format: " + text.getText());
      }
    } else {
      try {
        double cValue = Double.parseDouble(text.getText());
        double fValue = cValue * 1.8 + 32;
        fahrenheitValue.setText(Double.toString(fValue));
        System.out.println("C -> F: " + fValue);
        messageLabel.setText("Conversion performed successfully.");
      } catch (NumberFormatException e) {
        fahrenheitValue.setText("");
        messageLabel.setText("Invalid number format: " + text.getText());
      }
    }
  }

  public static void main(String[] args) {
    new TemperatureConverter();
  }
}
아오 졸려
로그인 하셔야 댓글을 사용하실수 있습니다.
댓글쓰기를 누르면 로그인 페이지로 이동 후 돌아옵니다.
총 댓글 겟수 0
번호 제목 등록일 작성자 조회수
671 struts2 intercept (0) 2014-12-29 이창우 1553
670 Reflection (0) 2014-07-07 이창우 1985
665 Timestamp <-> Date (0) 2014-04-02 이창우 2158
664 변환 date ->java.sql.date (0) 2014-03-24 이창우 2033
663 Unparseable date: "" (0) 2014-03-24 이창우 2952
659 Java Primitive Data Types (0) 2014-02-14 이창우 2421
568 abstract interface 차이점 (0) 2012-09-24 이창우 1349
418 Triple DES & DES JAVA ,C (0) 2011-12-26 이창우 2757
403 HttpClient (0) 2011-12-10 이창우 2599
220 콘솔에서 war 만들기 (0) 2011-07-13 이창우 3114
210 servlet 현재 주소 알아오기 (0) 2011-07-09 이창우 2264
188 A Java Runtime (0) 2011-06-27 이창우 2193
173 file 복사 (0) 2011-06-07 이창우 2045
172 파일 받기 (수정) (0) 2011-06-07 이창우 2293
170 파일 받기 (안됨) (0) 2011-06-07 이창우 1829
169 소켓으로 파일 받기(안됨) (0) 2011-06-07 이창우 2054
-> RCP Example (0) 2011-06-03 이창우 1885
161 rcp 설명 사이트 (1) 2011-06-03 이창우 2123
160 Thread Chatting 프로토 타입 2 (1) 2011-06-02 이창우 1739
158 object heap (0) 2011-06-01 이창우 1969
< 1 2 >
글쓰기 검색