乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      JAVA.SWT/JFace: SWT高級控件之對話框

       桑枯海 2012-03-17
      JAVA.SWT/JFace: SWT高級控件之對話框
      2010年07月31日 星期六 20:46

      《Eclipse SWT/JFACE 核心應(yīng)用》 清華大學(xué)出版社 9.8 對話框

          SWT中的對話框有消息提示框(MessageBox)、文件目錄對話框(DirectoryDialog)、文件對話框(FileDialog)、顏色 對話框(ColorDialog)、字體對話框(FontDialog)、打印對話框(PrintDialog)等。

      package www.swt.com.ch9;

      import java.io.File;

      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) {
           //創(chuàng)建消息框?qū)ο?,使用警告圖標(biāo)并顯示是和否按鈕
           MessageBox box = new MessageBox( shell ,SWT.ICON_ERROR|SWT.YES|SWT.NO);
           //設(shè)置對話框的標(biāo)題
           box.setText("錯誤消息對話框");
           //設(shè)置對話框顯示的消息
           box.setMessage("讀取文件發(fā)生錯誤!");
           //打開對話框,將返回值賦給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);
           //設(shè)置顯示在窗口上方的提示信息
           dialog.setMessage("請選擇所要保存的文件夾");
           //設(shè)置對話框的標(biāo)題
           dialog.setText("選擇文件目錄");
           //設(shè)置打開時默認(rèn)的文件目錄
           dialog.setFilterPath("C:\\");
           //打開窗口,返回用戶所選的文件目錄
           String saveFile = dialog.open();
           if ( saveFile != null )
           {
            //創(chuàng)建一個File對象
            File directory = new File(saveFile);
            System.out.print(directory.getPath());
           }
          }
         });
        
         Button b3 = new Button ( shell,SWT.NONE);
         b3.setText("文件對話框");
         b3.addSelectionListener( new SelectionAdapter(){
          public void widgetSelected(SelectionEvent e) {
           //創(chuàng)建一個打開對話框,樣式設(shè)置為SWT.OPEN,其他也可以是SWT.SAVE、SWT.MULTI
           FileDialog dialog = new FileDialog(shell,SWT.OPEN);
           //設(shè)置打開默認(rèn)的路徑
           dialog.setFilterPath(System.getProperty("java.home"));
           //設(shè)置所打開文件的擴展名
           dialog.setFilterExtensions(new String[] {"*.txt", "*.*"});
           //設(shè)置顯示到下拉框中的擴展名的名稱
           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) {
           //創(chuàng)建一個顏色對話框
           ColorDialog dialog = new ColorDialog(shell);
           //設(shè)置默認(rèn)選中的顏色
           dialog.setRGB( new RGB( 255 ,255 ,128));
           //打開對話框,將選中的顏色返回給rgb對象
           RGB rgb = dialog.open();
           if ( rgb != null )
           {
            System.out.print(rgb);
            //創(chuàng)建顏色對象
            Color color = new Color( display , rgb );
            //在使用完顏色對象后,釋放資源
            color.dispose();
           
           }
          }
         });
        
         Button b5 = new Button ( shell,SWT.NONE);
         b5.setText("字體對話框");
         b5.addSelectionListener( new SelectionAdapter(){
          public void widgetSelected(SelectionEvent e) {
           //創(chuàng)建一個字體對話框
           FontDialog dialog = new FontDialog (shell);
           //設(shè)置默認(rèn)選中的顏色
           dialog.setRGB( new RGB( 255 ,255 ,128));
           //打開對話框,將選中的字體返回給fontData對象
           FontData fontData = dialog.open();
           if ( fontData != null )
           {
            System.out.print(fontData);
            //創(chuàng)建顏色對象
            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) {
           //創(chuàng)建一個打印對話框
           PrintDialog dialog = new PrintDialog (shell);
           //打開對話框,將選中的字體返回給fontData對象
           PrinterData printData = dialog.open();
           if ( printData != null )
           {
            //創(chuàng)建打印對象
            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();

      }
      }

      顯示效果:

      消息提示框:

      目錄選取對話框:

      文件對話框:

      顏色對話框:

      字體對話框:

      打印對話框:

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多