자바 코드 swt 대화 상자
import java.io.File;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
public class DialogSample {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout( new GridLayout());
shell.setText("Dialog Sample");
Button b1 = new Button ( shell,SWT.NONE);
b1.setText(" ");
b1.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
// ,
MessageBox box = new MessageBox( shell ,SWT.ICON_ERROR|SWT.YES|SWT.NO);
//
box.setText(" ");
//
box.setMessage(" !");
// , choice
int choice = box.open();
//
if (choice==SWT.YES)
System.out.print("Yes");
else if ( choice==SWT.NO)
System.out.print("No");
}
});
Button b2 = new Button ( shell,SWT.NONE);
b2.setText(" ");
b2.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(shell);
//
dialog.setMessage(" ");
//
dialog.setText(" ");
//
dialog.setFilterPath("C:\\");
// ,
String saveFile = dialog.open();
if ( saveFile != null )
{
// File
File directory = new File(saveFile);
System.out.print(directory.getPath());
}
}
});
Button b3 = new Button ( shell,SWT.NONE);
b3.setText(" open ");
b3.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
// , SWT.OPEN, SWT.SAVE、SWT.MULTI
FileDialog dialog = new FileDialog(shell,SWT.OPEN);
//
dialog.setFilterPath(System.getProperty("java.home"));
//
dialog.setFilterExtensions(new String[] {"*.txt", "*.*"});
//
dialog.setFilterNames( new String[]{"Text Files (*.txt)", "All Files (*.*)"});
// ,
String file = dialog.open();
if ( file != null )
{
System.out.print(file);
}
}
});
Button b5 = new Button ( shell,SWT.NONE);
b5.setText(" save ");
b5.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
// , SWT.OPEN, SWT.SAVE、SWT.MULTI
FileDialog dialog = new FileDialog(shell,SWT.SAVE);
//
dialog.setFilterPath(System.getProperty("java.home"));
//
dialog.setFilterExtensions(new String[] {"*.txt", "*.*"});
//
dialog.setFilterNames( new String[]{"Text Files (*.txt)", "All Files (*.*)"});
// ,
String file = dialog.open();
if ( file != null )
{
System.out.print(file);
}
}
});
Button b4 = new Button ( shell,SWT.NONE);
b4.setText(" ");
b4.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
//
ColorDialog dialog = new ColorDialog(shell);
//
dialog.setRGB( new RGB( 255 ,255 ,128));
// , rgb
RGB rgb = dialog.open();
if ( rgb != null )
{
System.out.print(rgb);
//
Color color = new Color( display , rgb );
// ,
color.dispose();
}
}
});
Button b55 = new Button ( shell,SWT.NONE);
b55.setText(" ");
b55.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
//
FontDialog dialog = new FontDialog (shell);
//
dialog.setRGB( new RGB( 255 ,255 ,128));
// , fontData
FontData fontData = dialog.open();
if ( fontData != null )
{
System.out.print(fontData);
//
Font font = new Font( display , fontData );
// ,
font.dispose();
}
}
});
Button b6 = new Button ( shell,SWT.NONE);
b6.setText(" ");
b6.addSelectionListener( new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
//
PrintDialog dialog = new PrintDialog (shell);
// , fontData
PrinterData printData = dialog.open();
if ( printData != null )
{
//
Printer printer = new Printer( printData );
// ,
printer.dispose();
}
}
});
//shell.setSize(200, 150);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.