📄 imagebuttondemo.java
字号:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class ImageButtonDemo {
public static Display myDisplay;
public static boolean internalCall = false;
public static void main(String[] args) {
internalCall = true;
myDisplay = new Display();
ImageButtonDemo id = new ImageButtonDemo();
id.runDemo(myDisplay);
}
public void runDemo(Display display) {
myDisplay = display;
Shell shell = new Shell(display);
shell.setSize(180,320);
shell.setText("Image Button Demo");
//load an image from a JPEG file
Image original = new Image(display, "EclipseBannerPic.jpg");
//create a duplicate image with 3 different values for flag
Image copy = new Image(display, original, SWT.IMAGE_COPY);
Image gray = new Image(display, original, SWT.IMAGE_GRAY);
Image disable = new Image(display, original, SWT.IMAGE_DISABLE);
//create, size, and position 3 buttons
Button b1 = new Button(shell, SWT.PUSH);
b1.setSize(150,80);
b1.setLocation(10,10);
Button b2 = new Button(shell, SWT.PUSH);
b2.setSize(150,80);
b2.setLocation(10,100);
Button b3 = new Button(shell, SWT.PUSH);
b3.setSize(150,80);
b3.setLocation(10,190);
//set the image for each button
b1.setImage(copy);
b2.setImage(gray);
b3.setImage(disable);
//open the shell, so we can draw on it
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
copy.dispose();
gray.dispose();
disable.dispose();
original.dispose();
if (internalCall) display.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -