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 ("=");
}
}