자바 모방 qq 메시지 알림 상자
swt.jar
주 클래스:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
public class Z {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell();
shell.setText("aaa");
shell.setSize(250, 150);
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
MessageBox mb = new MessageBox(shell,SWT.ICON_QUESTION | SWT.OK| SWT.CANCEL);
mb.setText(" ");
mb.setMessage(" ?");
int rc = mb.open();
if (e.doit == (rc == SWT.OK)) {
System.exit(0);
}
else if(e.doit == (rc == SWT.CANCEL)) {
return;
}
}
});
final Button button = new Button(shell, SWT.NONE);
button.setBounds(50, 20, 100, 25);
button.setText("button");
// button , Popup popup 。
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// popup , popup 。
Popup popup = new Popup(" ");
popup.start();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
방법 클래스:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class Popup extends Thread {
Shell shell;
protected int moveStep = 2; // pixel
protected int upPosition; //
protected int downPosition; // popup
protected int leftPosition; // popup
public Popup(String message) {
// TODO Auto-generated constructor stub
shell = new Shell(SWT.ON_TOP);
Text text = new Text(shell, SWT.MULTI | SWT.WRAP);
text.setBounds(10, 20, 180, 80);
text.setBackground(shell.getBackground());
text.setText(message);
//
Rectangle area = Display.getDefault().getClientArea();
upPosition = area.height - 100;// popup
downPosition = area.height + 100;// popup
leftPosition = area.width - 180;
shell.setSize(180, 100);
// popup
shell.setLocation(leftPosition, downPosition);
shell.open();
}
public void run() {
Display display = shell.getDisplay();
while (true) {
try {
Thread.sleep(10);
// , 。
if ((downPosition - moveStep) > upPosition) {
display.asyncExec(new Runnable() {
public void run() {
shell.setLocation(leftPosition, downPosition - moveStep);
downPosition -= moveStep;
}
});// , 5 , 。
} else {
Thread.sleep(5000);
display.asyncExec(new Runnable() {
public void run() {
shell.dispose();
}
});
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
shell :
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.