Implement file browsing

Source: Internet
Author: User

Use the java graphical user interface to implement the file browsing function (the package needs to be imported) 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; 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 (); createConte ETS (); 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 ("parse WSDL"); text_file = new Text (shell, SWT. BORDER); text_file.setBounds (80, 33,290, 24); // implement the file browsing function. Button browseButton = new Button (shell, SWT. PUSH); browseButton. setText ("Browse... "); 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. setFilterExt Ensions (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 () {@ Overridepublic void widgetSelected (SelectionEvent e) {MessageBox msgbox = new MessageBox (shell, SWT. ICON_QUESTION | SWT. OK); msgbox. setText ("prompt"); String file = ""; file = text_file.getText (); if (file. equals ("") | file = null) {msgbox. setMessage ("the WSDL file cannot be blank "); Msgbox. open (); return;} else {msgbox. setMessage ("file retrieved !!! "); 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 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 ("source file :");}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.