source: trunk/tests/SWT/java/SWT008_01.java

Last change on this file was 12, checked in by lpino, 18 years ago
  • Initial commit
File size: 3.7 KB
Line 
1/*
2* SWT008_01.java
3*/
4
5/*
6* Copyright (c) 2002, 2004 EclipseOS2 Team.
7* This file is made available under the terms of the Common Public License v1.0
8* which accompanies this distribution, and is available at
9* http://www.eclipse.org/legal/cpl-v10.html
10*/
11
12import org.eclipse.swt.*;
13import org.eclipse.swt.widgets.*;
14import org.eclipse.swt.events.*;
15import org.eclipse.swt.graphics.*;
16import org.eclipse.swt.layout.*;
17
18/**
19* A simple testcase that listents for key press and key release events
20* (SWT.KeyEvent) ant prints the event info to the console.
21*/
22
23public class SWT008_01 extends SWTTestCase {
24
25 static {
26 STEP = "008";
27 TEST = "01";
28 DESC = "Message Dialog";
29 }
30
31 public static void main (String [] args) {
32 go (new SWT008_01 ());
33 }
34
35 Shell createTopShell (Display display) {
36 return new Shell (display,SWT.SHELL_TRIM | SWT.NO_REDRAW_RESIZE);
37 }
38
39 void initComponents () {
40 super.initComponents();
41 //Warning button
42 Button button = new Button(shell, SWT.PUSH);
43 button.addListener(SWT.Selection, new Listener() {
44 public void handleEvent(Event event) {
45 MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
46 messageBox.setText("Warning");
47 messageBox.setMessage("Save the changes before exiting?");
48 int buttonID = messageBox.open();
49 System.out.println(buttonID);
50 }
51 });
52 button.setText("Warning!");
53 button.setBounds(0, 10, 80, 30);
54
55 //Error button
56 Button buttonError = new Button(shell, SWT.PUSH);
57 buttonError.addListener(SWT.Selection, new Listener() {
58 public void handleEvent(Event event) {
59 MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK | SWT.CANCEL);
60 messageBox.setText("Error");
61 messageBox.setMessage("The program is not working!");
62 int buttonID = messageBox.open();
63 System.out.println(buttonID);
64 }
65 });
66 buttonError.setText("Error!");
67 buttonError.setBounds(0, 50, 80, 30);
68
69 //Information button
70 Button buttonInfo = new Button(shell, SWT.PUSH);
71 buttonInfo.addListener(SWT.Selection, new Listener() {
72 public void handleEvent(Event event) {
73 MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.YES | SWT.NO);
74 messageBox.setText("Information");
75 messageBox.setMessage("You have a bug in your code");
76 int buttonID = messageBox.open();
77 System.out.println(buttonID);
78 }
79 });
80 buttonInfo.setText("Information!");
81 buttonInfo.setBounds(0, 90, 80, 30);
82
83 //Question button
84 Button buttonQ = new Button(shell, SWT.PUSH);
85 buttonQ.addListener(SWT.Selection, new Listener() {
86 public void handleEvent(Event event) {
87 MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
88 messageBox.setText("Question");
89 messageBox.setMessage("Did you sleep enough?");
90 int buttonID = messageBox.open();
91 System.out.println(buttonID);
92 }
93 });
94 buttonQ.setText("Question!");
95 buttonQ.setBounds(0, 130, 80, 30);
96
97 //Working button
98 Button buttonW = new Button(shell, SWT.PUSH);
99 buttonW.addListener(SWT.Selection, new Listener() {
100 public void handleEvent(Event event) {
101 MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.CANCEL);
102 messageBox.setText("Working");
103 messageBox.setMessage("You are still compiling");
104 int buttonID = messageBox.open();
105 System.out.println(buttonID);
106 }
107 });
108 buttonW.setText("Working!");
109 buttonW.setBounds(0, 170, 80, 30);
110
111 Rectangle dr = display.getBounds ();
112 Rectangle sr = new Rectangle (0, 0, 280, 250);
113 sr.x = (dr.width-sr.width)/2;
114 sr.y = (dr.height-sr.height)/2;
115 shell.setBounds (sr);
116 }
117
118}
119
Note: See TracBrowser for help on using the repository browser.