Java Tutorial/SWT/Display — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:44, 31 мая 2010
Содержание
- 1 Causes the system hardware to emit a short sound if it supports this capability
- 2 Get color for the given constant
- 3 Get the bounds and client area of a display
- 4 Get the longest duration in milliseconds between two mouse button clicks that will be deemed a double-click.
- 5 Returns the button dismissal alignment
- 6 Returns the maximum allowed depth of icons on the display.
- 7 SWT Event Handling with Displays
- 8 To find the primary monitor, call getPrimaryMonitor.
- 9 Using Display Class
Causes the system hardware to emit a short sound if it supports this capability
import org.eclipse.swt.widgets.Display;
public class MainClass {
static Display display = new Display();
public static void main(String[] args) {
display.beep();
}
}
Get color for the given constant
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
public class MainClass {
static Display display = new Display();
public static void main(String[] args) {
Color col = display.getSystemColor(SWT.COLOR_BLUE);
}
}
The returned color should not be freed because it was allocated and managed by the system.
Get the bounds and client area of a display
import org.eclipse.swt.widgets.Display;
public class DisplayBounds{
public static void main(String[] args) {
Display display = new Display();
System.out.println("Display Bounds=" + display.getBounds() + " Display ClientArea="
+ display.getClientArea());
display.dispose();
}
}
Get the longest duration in milliseconds between two mouse button clicks that will be deemed a double-click.
import org.eclipse.swt.widgets.Display;
public class MainClass {
static Display display = new Display();
public static void main(String[] args) {
System.out.println(display.getDoubleClickTime());
}
}
Returns the button dismissal alignment
Alignment can be either SWT.LEFT or SWT.RIGHT. The button dismissal alignment is used when positioning the default dismissal button for a dialog. For example, if alignement is LEFT, the button order should be OK, CANCEL.
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
public class MainClass {
static Display display = new Display();
public static void main(String[] args) {
System.out.println(display.getDismissalAlignment() == SWT.LEFT);
System.out.println(display.getDismissalAlignment() == SWT.RIGHT);
}
}
Returns the maximum allowed depth of icons on the display.
import org.eclipse.swt.widgets.Display;
public class MainClass {
static Display display = new Display();
public static void main(String[] args) {
System.out.println(display.getIconDepth());
}
}
SWT Event Handling with Displays
The readAndDispatch reads events from the operating system"s event queue and then dispatches them appropriately.
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SWTEventHandlingDisplay {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello, world!");
shell.open();
while(! shell.isDisposed()) { // Event loop.
if(! display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
To find the primary monitor, call getPrimaryMonitor.
Get all the monitors attached to the device, call Display.getMonitors()
import org.eclipse.swt.widgets.Display;
public class MainClass {
static Display display = new Display();
public static void main(String[] args) {
System.out.println(display.getPrimaryMonitor().getClientArea());
}
}
Using Display Class
The primary functions of Display instances are as follows:
- The Display object is the connection between the SWT and the underlying windowing system.
- Implementing the SWT event loop in terms of a platform event model
- Providing methods for accessing information about the operating system
- Managing operating system resources used by SWT
- Only a single Display instance is required in most SWT-based applications.
- The thread that creates the Display object is the event-loop thread (user-interface thread).