下面是我做的一个登录框的小程序,当输入用户名(123)和密码(123)的时候会跳转到一个界面,用户名和密码错误的话会弹出一个提示对话框。
开发环境:eclipse3.1 插件SWT-Designer。
程序还有很多不完善的地方,请大家多多指正。
本来想把截图一起放在上面,可是不知道为什么图片贴不上来,谁能告诉我“编辑插入图像具体“怎么用啊,为什么我上传的图都是红XX
本来想把截图一起放在上面,可是不知道为什么图片贴不上来,谁能告诉我“编辑插入图像具体“怎么用啊,为什么我上传的图都是红XX,在这里先谢谢拉o(∩_∩)o...。
登陆框LoginSwt.java的代码:
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
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 LoginSwt ...{
public static void main(String[] args) ...{
Display display = Display.getDefault();
final Shell shell = new Shell(display,SWT.CLOSE|SWT.SYSTEM_MODAL);
//shell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
shell.setSize(357, 218);
shell.setText("SWT Application");
shell.open();
final Label label = new Label(shell, SWT.NONE);
//label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
//label.setAlignment(SWT.CENTER);
label.setText("登陆名:");
label.setBounds(68, 47, 51, 19);
final Label label_1 = new Label(shell, SWT.NONE);
//label_1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
//label_1.setAlignment(SWT.CENTER);
label_1.setText("密 码:");
label_1.setBounds(68, 72, 51, 16);
final Text name = new Text(shell, SWT.BORDER);
name.setBounds(136, 44, 131, 20);
final Text password = new Text(shell, SWT.PASSWORD | SWT.BORDER);
password.setBounds(136, 69, 131, 19);
Button button = new Button(shell, SWT.NONE);
button.setText("登陆");
button.setBounds(105, 126, 40, 25);
button.addSelectionListener(new SelectionAdapter() ...{
public void widgetSelected(SelectionEvent arg0) ...{
if(name.getText().equals("123")&&password.getText().equals("123"))...{
try...{
ChildShell window = new ChildShell();
window.open();
}catch (Exception e) ...{
e.printStackTrace();
}
}else...{
MessageDialog.openWarning(shell,null, "用户名或密码错误");
}
}
});
//button.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
button.addMouseListener(new MouseAdapter() ...{
public void mouseDoubleClick(MouseEvent arg0) ...{
name.setText("鼠标双击事件");
}
});
Button button_1 = new Button(shell, SWT.NONE);
button_1.setText("取消");
button_1.setBounds(202, 127, 44, 23);
//button_1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
button_1.addMouseListener(new MouseAdapter() ...{
public void mouseDown(MouseEvent arg0) ...{
MessageDialog.openWarning(shell,null, "没有此项功能");
}
});
shell.layout();
while (!shell.isDisposed()) ...{
if (!display.readAndDispatch())
display.sleep();
}
}
}
恢复被注掉的代码可以显示界面和控件的颜色。
button.addSelectionListener(new SelectionAdapter() ...{
public void widgetSelected(SelectionEvent arg0) ...{
if(name.getText().equals("123")&&password.getText().equals("123"))...{
try...{
ChildShell window = new ChildShell();
window.open();
}catch (Exception e) ...{
e.printStackTrace();
}
}else...{
MessageDialog.openWarning(shell,null, "用户名或密码错误");
}
}
});
这段代码是给“登录”按钮添加一个事件,if(name.getText().equals("123")&&password.getText().equals("123"))
是建立用户名和密码是123,并判断,如果输入的用户名和密码都是123,则跳转到try里面内容所指向的界面及ChildShell.java,如果错误则弹出一个Dialog,显示"用户名或密码错误"。
ChildShell.java的代码:
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class ChildShell ...{
public static void main(String[] args) ...{
try ...{
ChildShell window = new ChildShell();
window.open();
} catch (Exception e) ...{
e.printStackTrace();
}
}
/** *//**
* Open the window
*/
public void open() ...{
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
shell.open();
分享到:
相关推荐
SWT/Jface API 3.4 SWT/Jface API 3.4 SWT/Jface API 3.4 SWT/Jface API 3.4
SWT/JFACE API,是关于SWT/JFACE开发所用的API
swt/Jface用到的最基本的jar包
Eclipse SWT/JFace SWT JFace 实例 Eclipse SWT/JFace 书中 全部实例
Eclipse SWT/JFace 核心应用光盘源码下载,解压后即可使用
Eclipse SWT/JFace 核心应用 带书签 Eclipse SWT/JFace
Eclipse SWT/JFace核心应用
SWT/JFace开发实例
本文档为swt/jface的api中文帮助文档。
SWT/Jface 开发入门指南 介绍以下方面的内容: ? 设定 swt 以及 JFace 的开发环境 ? swt 的一些简单部件(widget)介绍 ? JFace 的一些入门性介绍 ? swt 和 JFace 的事件模式 ? 通过一些简单的例子说明如何利用 swt ...
发现网上没有传类似的例子,特传个简单的例子,希望能帮助需要的人。
eclipse swt/jface核心应用源代码 带视频,找了好久,希望可以帮到大家,跟书匹配
eclipse swt/jface核心应用 这本书的源代码
NULL 博文链接:https://niub.iteye.com/blog/1806580
《Eclipse SWT/Jface核心应用》全面介绍了SWT、JFace和RCP的相关知识。全书共分5篇,第1篇介绍了SWT产生的背景以及SWT的一些基本概念和基础知识。第2篇介绍了SWT基本控件的使用,以及事件处理、布局等SWT基本知识的...
SWT/JFace 3.5 版本的 API,HTML格式,方便开发人员查阅。
SWT/JFace是本人在学习SWT/JFace时从不同的文档中整理出来的一些比较基础的内容,希望对大家有所帮助.
基于 Java 桌面程序开发的图形库...本书主要讲解了如何使用 SWT 和 JFace 进行应用程序的开发,通过本书系统而全面的 SWT/JFace 知识学习,将帮助读者快 速开发出完美、实用的 GUI 程序,轻松完成繁琐的界面、菜单编程.
swt/jface in action 中英文 pdf格式 + 源码下载,包含书中的所有源码,有需要的朋友可以下载,为正在学习swt、jface的朋友提供一些好资源。