用Java开发C/S应用(四):swt中的对话框

对话框主要有以下六种:

1.MessageBox,消息对话框

只有OK按钮的:

                MessageBox messageBox  =   new  MessageBox(shell, SWT.ICON_WARNING
                        
|  SWT.OK);
                messageBox.setText(
" title " );
                messageBox.setMessage(
" 这是一个测试 " );
                messageBox.open();

有是和否按钮的:

                MessageBox messageBox  =   new  MessageBox(shell,
                        SWT.ICON_INFORMATION 
|  SWT.YES  |  SWT.NO);
                messageBox.setText(
" title " );
                messageBox.setMessage(
" 这是一个测试 " );
                
int  rc  =  messageBox.open();
                
if  (rc  ==  SWT.YES) {
                    text.setText(
" 你点击了YES " );
                } 
else   if  (rc  ==  SWT.NO) {
                    text.setText(
" 你点击了NO " );
                }

 

2.DirectoryDialog,文件夹选择框

                DirectoryDialog dlg  =   new  DirectoryDialog(shell);
                dlg.setText(
" SWT’s DirectoryDialog " );
                dlg.setMessage(
" Select a directory " );
                String directoryName 
=  dlg.open();
                
if  (directoryName  !=   null ) {
                    text.setText(directoryName);
                }

 

3.FileDialog,文件选择对话框

                FileDialog dlg  =   new  FileDialog(shell, SWT.OPEN);
                dlg.setFilterExtensions(
new  String[] {  " *.doc;*.xls;*.ppt "  });
                String fileName 
=  dlg.open();
                
if  (fileName  !=   null ) {
                    text.setText(fileName);
                }

 

4.FontDialog,字体选择对话框

                FontDialog dlg  =   new  FontDialog(shell);
                FontData fontData 
=  dlg.open();
                
if  (fontData  !=   null ) {
                    Font font 
=   new  Font(shell.getDisplay(), fontData);
                    Color color 
=   new  Color(shell.getDisplay(), dlg.getRGB());
                    text.setFont(font);
                    text.setForeground(color);
                }

 

5.ColorDialog,颜色选择对话框

                ColorDialog dlg  =   new  ColorDialog(shell);
                RGB rgb 
=  dlg.open();
                
if  (rgb  !=   null ) {
                    Color color 
=   new  Color(shell.getDisplay(), rgb);
                    text.setForeground(color);
                }

 

6.PrintDialog,打印对话框

这个稍复杂

 

通过扩展Dialog类,还可以自定义对话框

转载于:https://www.cnblogs.com/modou/articles/1525957.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值