最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2009年06月25日 09:15:33   作者:  
SWT(JFace)體驗(yàn)之ApplicationWindow
測試代碼如下:
復(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)文章

  • Java實(shí)現(xiàn)一個簡單的文件上傳案例示例代碼

    Java實(shí)現(xiàn)一個簡單的文件上傳案例示例代碼

    這篇文章主要介紹了Java實(shí)現(xiàn)一個簡單的文件上傳案例,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-07-07
  • spring聲明式事務(wù)@Transactional底層工作原理

    spring聲明式事務(wù)@Transactional底層工作原理

    這篇文章主要為大家介紹分析spring聲明式事務(wù)@Transactional底層工作原理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2022-02-02
  • SpringBoot中的@EnableConfigurationProperties注解詳細(xì)解析

    SpringBoot中的@EnableConfigurationProperties注解詳細(xì)解析

    這篇文章主要介紹了SpringBoot中的@EnableConfigurationProperties注解詳細(xì)解析,如果一個配置類只配置@ConfigurationProperties注解,而沒有使用@Component或者實(shí)現(xiàn)了@Component的其他注解,那么在IOC容器中是獲取不到properties 配置文件轉(zhuǎn)化的bean,需要的朋友可以參考下
    2024-01-01
  • Spring Boot Admin 進(jìn)行項目監(jiān)控管理的方法

    Spring Boot Admin 進(jìn)行項目監(jiān)控管理的方法

    Spring Boot Admin是一個開源社區(qū)項目,用于管理和監(jiān)控SpringBoot應(yīng)用程序。 這篇文章主要介紹了 Spring Boot Admin 進(jìn)行項目監(jiān)控管理的方法,需要的朋友可以參考下
    2020-07-07
  • Java多線程按指定順序同步執(zhí)行

    Java多線程按指定順序同步執(zhí)行

    這篇文章主要介紹了java多線程如何按指定順序同步執(zhí)行,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • @Data注解在Boolean類型屬性上的大坑及解決

    @Data注解在Boolean類型屬性上的大坑及解決

    在使用@Data注解時,如果類中存在Boolean類型的屬性,且屬性名不是以"is"開頭,那么@Data注解生成的get方法名會默認(rèn)加上"is",導(dǎo)致屬性值無法成功拷貝,解決方法是手動添加get方法,覆蓋@Data注解生成的方法
    2024-10-10
  • 完全解析Java編程中finally語句的執(zhí)行原理

    完全解析Java編程中finally語句的執(zhí)行原理

    這篇文章主要深度介紹了Java編程中finally語句的執(zhí)行原理,細(xì)致講解了finally在異常處理中的流程控制作用,需要的朋友可以參考下
    2015-11-11
  • Java Flink與kafka實(shí)現(xiàn)實(shí)時告警功能過程

    Java Flink與kafka實(shí)現(xiàn)實(shí)時告警功能過程

    這篇文章主要介紹了Java Flink與kafka實(shí)現(xiàn)實(shí)時告警功能,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-01-01
  • JAVA Stack詳細(xì)介紹和示例學(xué)習(xí)

    JAVA Stack詳細(xì)介紹和示例學(xué)習(xí)

    JAVA Stack是棧。它的特性是:先進(jìn)后出(FILO, First In Last Out)。
    2013-11-11
  • Java8如何優(yōu)雅的記錄代碼運(yùn)行時間

    Java8如何優(yōu)雅的記錄代碼運(yùn)行時間

    這篇文章主要為大家詳細(xì)介紹了 Java 8 中幾種記錄代碼運(yùn)行時間的優(yōu)雅方式,并附上實(shí)用工具類與建議,希望可以幫助大家提高大家的代碼可讀性與復(fù)用性
    2025-04-04

最新評論

贵州省| 论坛| 洪江市| 瓦房店市| 南雄市| 年辖:市辖区| 渝北区| 罗田县| 闽清县| 宜阳县| 明水县| 江城| 曲松县| 台江县| 三亚市| 闽清县| 旅游| 屏山县| 云浮市| 静安区| 彭阳县| 浠水县| 陵川县| 田阳县| 石景山区| 扎囊县| 铁岭市| 江津市| 冀州市| 宁乡县| 鹿泉市| 缙云县| 鲁甸县| 泊头市| 永定县| 西昌市| 吐鲁番市| 汕尾市| 永仁县| 清徐县| 五莲县|