Java SWT implements the simplest adder

Source: Internet
Author: User
Tags gettext

Practice Practicing ~ ~

Http://zhidao.baidu.com/question/24470286.html learned it from here.

Difficulty: How to convert an input string into a double type

Related code:

Import Org.eclipse.swt.SWT;
	public class Test {protected Shell shell;
	Private Text T1;
	Private Text T2;


	Private Text T3;
	 /** * Launch the application.
			* @param args */public static void main (string[] args) {try {test window = new test ();
		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 (450, 300);
		
		Shell.settext ("SWT application"); Button B1 = New button (Shell, SWT.
		NONE);
				    B1.addselectionlistener (New Selectionadapter () {@Override public void widgetselected (Selectionevent e) {
				    Double A1 = double.parsedouble (T1.gettext ()); Double A2= Double.parsedouble (T2.gettext ());    
				   T3.settext (string.valueof (A1+A2));			
			
			
	
		}


				  });
		B1.setbounds (0, 10, 80, 27);
		
		B1.settext ("Begin"); T1 = new Text (Shell, SWT.
		BORDER);
		
		T1.setbounds (7, 65, 73, 23); t2 = new Text (Shell, SWT.
		BORDER);
		
		T2.setbounds (155, 65, 73, 23); T3 = new Text (Shell, SWT.
		BORDER);
		
	
		T3.setbounds (304, 65, 73, 23); Label Lblnewlabel = new label (Shell, SWT.
		NONE);
		Lblnewlabel.setbounds (123, 68, 61, 17);
		
		Lblnewlabel.settext ("+"); Label Lblnewlabel_1 = new label (Shell, SWT.
		NONE);
		Lblnewlabel_1.setbounds (259, 68, 61, 17);


	Lblnewlabel_1.settext ("=");
 }


}


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.