亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SWT(JFace)體驗之ApplicationWindow

 更新時間:2009年06月25日 09:15:33   作者:  
SWT(JFace)體驗之ApplicationWindow
測試代碼如下:
復制代碼 代碼如下:

package swt_jface.demo;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class TemperatureConverterJFace extends ApplicationWindow {
Label fahrenheitLabel;
Label celsiusLabel;
Text fahrenheitValue;
Text celsiusValue;

public TemperatureConverterJFace() {

super(null);

addStatusLine();
}
protected Control createContents(Composite parent) {
getShell().setText("JFace Temperature Converter");

Composite converterComposite = new Composite(parent, SWT.NULL);

converterComposite.setLayout(new GridLayout(4, false));
fahrenheitLabel = new Label(converterComposite, SWT.NULL);
fahrenheitLabel.setText("Fahrenheit: ");
fahrenheitValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER);
celsiusLabel = new Label(converterComposite, SWT.NULL);
celsiusLabel.setText("Celsius: ");
celsiusValue = new Text(converterComposite, SWT.SINGLE | SWT.BORDER);
ModifyListener listener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
valueChanged((Text) e.widget);
}
};
fahrenheitValue.addModifyListener(listener);
celsiusValue.addModifyListener(listener);

return converterComposite;
}
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);
setStatus("Conversion performed successfully.");
} catch (NumberFormatException e) {
celsiusValue.setText("");
setStatus("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);
setStatus("Conversion performed successfully.");
} catch (NumberFormatException e) {
fahrenheitValue.setText("");
setStatus("Invalid number format: " + text.getText());
}
}
}

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

不使用ApplicationWindow(即只是用SWT類)的解決方案:
復制代碼 代碼如下:

package swt_jface.demo;
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();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
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();
}
}

相關文章

  • 詳解如何全注解方式構建SpringMVC項目

    詳解如何全注解方式構建SpringMVC項目

    這篇文章主要介紹了詳解如何全注解方式構建SpringMVC項目,利用Eclipse構建SpringMVC項目,非常具有實用價值,需要的朋友可以參考下
    2018-10-10
  • 解析Java并發(fā)Exchanger的使用

    解析Java并發(fā)Exchanger的使用

    Exchanger是java 5引入的并發(fā)類,Exchanger顧名思義就是用來做交換的。這里主要是兩個線程之間交換持有的對象。當Exchanger在一個線程中調(diào)用exchange方法之后,會等待另外的線程調(diào)用同樣的exchange方法。兩個線程都調(diào)用exchange方法之后,傳入的參數(shù)就會交換。
    2021-06-06
  • Spring Boot無縫集成MongoDB

    Spring Boot無縫集成MongoDB

    這篇文章主要介紹了Spring Boot無縫集成MongoDB的相關知識,本文涉及到MongoDB的概念和nosql的應用場景,需要的朋友可以參考下
    2017-04-04
  • Spring?Boot實現(xiàn)JWT?token自動續(xù)期的實現(xiàn)

    Spring?Boot實現(xiàn)JWT?token自動續(xù)期的實現(xiàn)

    本文主要介紹了Spring?Boot實現(xiàn)JWT?token自動續(xù)期,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • 解決安裝mysqlclient的時候出現(xiàn)Microsoft Visual C++ 14.0 is required報錯

    解決安裝mysqlclient的時候出現(xiàn)Microsoft Visual C++ 14.0 is required報錯

    這篇文章主要介紹了解決安裝mysqlclient的時候出現(xiàn)Microsoft Visual C++ 14.0 is required報錯問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-11-11
  • Java中雙冒號運算符(::)的用法詳解

    Java中雙冒號運算符(::)的用法詳解

    在Java 8引入的Lambda表達式和函數(shù)式接口之后,雙冒號運算符(::)成為了一項重要的功能,下面我們就來學習一下Java中的雙冒號運算符及其常見應用場景吧
    2023-12-12
  • SpringBoot如何優(yōu)雅的處理重復請求

    SpringBoot如何優(yōu)雅的處理重復請求

    對于一些用戶請求,在某些情況下是可能重復發(fā)送的,如果是查詢類操作并無大礙,但其中有些是涉及寫入操作的,一旦重復了,可能會導致很嚴重的后果,所以本文給大家介紹了SpringBoot優(yōu)雅的處理重復請求的方法,需要的朋友可以參考下
    2023-12-12
  • Spring Boot 啟動加載數(shù)據(jù) CommandLineRunner的使用

    Spring Boot 啟動加載數(shù)據(jù) CommandLineRunner的使用

    本篇文章主要介紹了Spring Boot 啟動加載數(shù)據(jù) CommandLineRunner的使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-04-04
  • Windows編寫jar啟動腳本和關閉腳本的操作方法

    Windows編寫jar啟動腳本和關閉腳本的操作方法

    腳本文件,通常放入/bin目錄下,編寫啟動腳本需要保證能夠識別到對應的jar文件,其次需要保證能夠識別到/config中的配置文件信息,這篇文章主要介紹了Windows編寫jar啟動腳本和關閉腳本的操作方法,需要的朋友可以參考下
    2022-12-12
  • java必學必會之this關鍵字

    java必學必會之this關鍵字

    java必學必會之this關鍵字,java中this的用法進行了詳細的分析介紹,感興趣的小伙伴們可以參考一下
    2015-12-12

最新評論