Swt/jface Getting Started Guide let SWT program Move up

Source: Internet
Author: User

I do not know whether you have such an experience: In fact, the software user requirements are very basic, and now the software is becoming more and more complex, a large part of the software developers put their attention to some additional functions (these features may surprise users, but if not their users are not dissatisfied) on, But the real user's request is not satisfied. So when we design the program, we must understand that sometimes simplicity is a kind of beauty, spend time to really valuable place to go.

OK, back to our topic. In this section, I'll give you an introduction to SWT's event patterns. As we mentioned before, writing an SWT program is just a few steps away. One of the more things to worry about is the layout of the user interface and handling of various events.

Hello,world! with Event handling added

In fact, SWT handling events is very simple, corresponding to various events have a corresponding listener class, if an event is called XYZ, then the corresponding listener class is Xyzlistener. For example, corresponding to the mouse event has mouselistener, corresponding to the keyboard event is keylistener. In each widget, there is a Addxyzlistener method for the events it can handle, so just pass the corresponding listener instance as a parameter to it.

For a clearer explanation, let's take a look at the following procedure:

1 public class Eventdemo {
2
3 private Shell _shell
4
5 public Eventdemo () {
6 Display displ ay = new Display ();
7 Shell shell = new Shell (DISPLAY,SWT. Shell_trim);
8 Setshell (shell);
9 rowlayout layout=new rowlayout ();
Ten shell.setlayout (layout);
One Shell.settext ("Event demo"); The

button button=new button (SHELL,SWT. PUSH | Swt. CENTER);
Button.settext ("click me!");

Button.addselectionlistener (New Selectionlistener () {
M
/public void widgetselected ( Selectionevent event) {
Handleselectionevent ();


public void widgetdefaultselected (Selection Event event) {
}
24});
Shell.setbounds (200,300,100,100);
Shell.open ();

while (!shell.isdisposed ()) {
if (!display.readanddispatch ()) {
Display.sleep ();
to}

Display.dispose ()

()

protected void Handleselectionevent () {
MessageBoxDialog=new MessageBox (Getshell (), SWT. ok| Swt. Icon_information);
Dialog.settext ("Hello");
Dialog.setmessage ("hello,world!");
Dialog.open ();
42}
$
/**
@param args
*/
public static void Main (string[] args) {
+
-Eventdemo Eventdemo=new Eventdemo ();
50}
Wuyi
/**
* @return Returns the _shell.
*/
The public Shell Getshell () {
_shell;}

/**
* @param _shell the _shell to set.
* */
"public void Setshell" (shell shell) { This._shell =shell;
64}
65}
$

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.