hyljava

          實(shí)現(xiàn)文件瀏覽功能

          用java的圖形用戶(hù)界面實(shí)現(xiàn)文件瀏覽功能(需要導(dǎo)包)
          import org.eclipse.swt.SWT;
          import org.eclipse.swt.widgets.Display;
          import org.eclipse.swt.widgets.FileDialog;
          import org.eclipse.swt.widgets.MessageBox;
          import org.eclipse.swt.widgets.Shell;
          import org.eclipse.swt.widgets.Label;
          import org.eclipse.swt.widgets.Text;
          import org.eclipse.swt.widgets.Button;
          import org.eclipse.swt.events.SelectionAdapter;
          import org.eclipse.swt.events.SelectionEvent;
          import org.eclipse.swt.widgets.Group;
          import org.eclipse.wb.swt.SWTResourceManager;
          public class TestShell  {
          protected Shell shell;
           
          private Text text_file;
           
          public static void main(String[] args) {
          try {
          TestShell window = new TestShell();
          window.open();
          } catch (Exception e) {
          e.printStackTrace();
          }
          }
          /**
          * Open the window.
          */
          public void open() {
          Display display = Display.getDefault();
          createContents();
          shell.open();
          shell.layout();
          while (!shell.isDisposed()) {
          if (!display.readAndDispatch()) {
          display.sleep();
          }
          }
          }
          /**
          * Create contents of the window.
          */
          protected void createContents() {
          shell = new Shell();
          shell.setSize(500, 200);
          shell.setText("解析WSDL");
          text_file = new Text(shell, SWT.BORDER);
          text_file.setBounds(80, 33, 290, 24);
          //實(shí)現(xiàn)文件瀏覽功能
          Button browseButton = new Button(shell,SWT.PUSH);
          browseButton.setText("瀏覽...");
          browseButton.setFont(SWTResourceManager.getFont("Tahoma", 12, SWT.NORMAL));
          browseButton.setBounds(383, 33, 80, 24);
          browseButton.addSelectionListener(new SelectionAdapter(){
          /* (non-Javadoc)
          * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
          */
          public void widgetSelected(SelectionEvent e){
          FileDialog dialog = new FileDialog (shell, SWT.OPEN);
          dialog.setText("Source Folder Selection");
          dialog.setFilterExtensions(new String[] {"*.txt","*.jpg","*.*"});
          String filePath = dialog.open();
          if(dialog!=null){
          text_file.setText(filePath);
          }
          }
          });
          Button button_exe = new Button(shell, SWT.NONE);
          button_exe.addSelectionListener(new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
          MessageBox msgbox = new MessageBox(shell,
          SWT.ICON_QUESTION | SWT.OK);
          msgbox.setText("提示");
          String file = "";
          file = text_file.getText();
          if(file.equals("") || file == null){
          msgbox.setMessage("WSDL文件不能為空");
          msgbox.open();
          return;
          }else{
          msgbox.setMessage("文件獲取到了!!!");
          System.out.println(file);
          msgbox.open();
          }
          }
          });
          button_exe.setFont(SWTResourceManager.getFont("Tahoma", 12, SWT.NORMAL));
          button_exe.setBounds(214, 133, 87, 23);
          button_exe.setText("\u6267\u884C");
          Group group = new Group(shell, SWT.NONE);
          group.setBounds(10, 10, 472, 117);
          Label label = new Label(group, SWT.NONE);
          label.setBounds(10, 23, 105, 24);
          label.setFont(SWTResourceManager.getFont("Tahoma", 12, SWT.NORMAL));
          label.setText("源文件:");
          }
          }

          posted on 2013-02-23 20:55 何云隆 閱讀(1514) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): java

          評(píng)論

          # re: 實(shí)現(xiàn)文件瀏覽功能[未登錄](méi) 2013-02-24 18:07 feenn

          呃,和jxl有啥關(guān)系,只需要SWT就夠了~~~  回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 鹤峰县| 雷州市| 乡宁县| 安西县| 安福县| 疏勒县| 三明市| 汤原县| 宁海县| 凤城市| 永靖县| 昌吉市| 诏安县| 普陀区| 乌鲁木齐县| 襄城县| 麻阳| 根河市| 荔波县| 库伦旗| 怀柔区| 汕头市| 历史| 于都县| 香格里拉县| 鄂托克前旗| 上思县| 朝阳县| 郯城县| 麻城市| 新建县| 江西省| 赣榆县| 利津县| 祁门县| 甘德县| 柳江县| 西充县| 漳州市| 措勤县| 梁平县|