欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SWT(JFace)體驗(yàn)之ApplicationWindow

 更新時(shí)間:2009年06月25日 09:15:33   作者:  
SWT(JFace)體驗(yàn)之ApplicationWindow
測(cè)試代碼如下:
復(fù)制代碼 代碼如下:

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類)的解決方案:
復(fù)制代碼 代碼如下:

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();
}
}

相關(guān)文章

  • 詳解如何全注解方式構(gòu)建SpringMVC項(xiàng)目

    詳解如何全注解方式構(gòu)建SpringMVC項(xiàng)目

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

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

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

    Spring Boot無縫集成MongoDB

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

    Spring?Boot實(shí)現(xiàn)JWT?token自動(dòng)續(xù)期的實(shí)現(xiàn)

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

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

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

    Java中雙冒號(hào)運(yùn)算符(::)的用法詳解

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

    SpringBoot如何優(yōu)雅的處理重復(fù)請(qǐng)求

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

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

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

    Windows編寫jar啟動(dòng)腳本和關(guān)閉腳本的操作方法

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

    java必學(xué)必會(huì)之this關(guān)鍵字

    java必學(xué)必會(huì)之this關(guān)鍵字,java中this的用法進(jìn)行了詳細(xì)的分析介紹,感興趣的小伙伴們可以參考一下
    2015-12-12

最新評(píng)論