问题1:我用swt做了一个始终在所有程序最前的窗口,现在在另外一个用swing做的窗口,点击按钮怎么能swt的那个窗口隐藏呢?
问题2:我还想swt的窗口不允许随便关闭,当用户不小心点了关闭按钮后,要求给出提示信息,当确定以后,才允许真正关闭swt窗口。
现附一个始终在所有窗口最前的swt的简单代码:
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import org.eclipse.swt.internal.win32.*;public class Swt {
public Swt() {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello world");
shell.setBounds(0, 700, 1000, 200);
//窗口始终最前
OS.SetWindowPos(shell.handle, OS.HWND_TOPMOST, 500, 111, 1000,200,
SWT.NULL); Text helloText = new Text(shell, SWT.CENTER);
helloText.setText("Hello,World!");
helloText.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
Swt t = new Swt();
}
}
问题2:我还想swt的窗口不允许随便关闭,当用户不小心点了关闭按钮后,要求给出提示信息,当确定以后,才允许真正关闭swt窗口。
现附一个始终在所有窗口最前的swt的简单代码:
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import org.eclipse.swt.internal.win32.*;public class Swt {
public Swt() {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello world");
shell.setBounds(0, 700, 1000, 200);
//窗口始终最前
OS.SetWindowPos(shell.handle, OS.HWND_TOPMOST, 500, 111, 1000,200,
SWT.NULL); Text helloText = new Text(shell, SWT.CENTER);
helloText.setText("Hello,World!");
helloText.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
Swt t = new Swt();
}
}
第一个问题继续关注中,期待大家提出好建议。以前可能是没有代码的原因,现在附一个简单的代码文件:
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import org.eclipse.swt.internal.win32.*;public class Swt {
Display display = new Display();
public Swt() {
display = new Display();
Shell shell = new Shell(display,SWT.TITLE);
shell.setText("Hello world");
shell.setBounds(0, 700, 100, 200);
//窗口始终最前
OS.SetWindowPos(shell.handle, OS.HWND_TOPMOST, 500, 111, 100,200,
SWT.NULL); Text helloText = new Text(shell, SWT.CENTER);
Button closeButton = new Button(shell, SWT.PUSH | SWT.CENTER);
closeButton.setText("关闭");
closeButton.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent m) {
int result = javax.swing.JOptionPane.showConfirmDialog(null,"确定关闭对话框?","提示",JOptionPane.OK_CANCEL_OPTION);
if(result=0)
display.dispose();
}
});
helloText.setText("Hello,World!");
helloText.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
} display.dispose();
}
public static void main(String[] args) {
Swt t = new Swt();
}
}