[3953] in java-interest
Re: I need help with Java Beta Adding
daemon@ATHENA.MIT.EDU (Michael Mills)
Tue Dec 5 14:31:55 1995
From: ekim@faline.bellcore.com (Michael Mills)
To: Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM
Date: Tue, 5 Dec 1995 10:37:26 -0500 (EST)
Cc: java-interest@java.sun.com
In-Reply-To: <9511048181.AA818104825@CCMAIL.PRUSEC.COM> from "Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM" at Dec 4, 95 11:11:31 am
>
> The following example should add on two fields and put the total into the total
> field. Can someone please tell me how to get this to work?
>
>
>
> import java.awt.*;
> import java.applet.*;
>
> public class Test extends Applet
> {
> Panel infobar;
> Panel mainbar;
> TextField exp1;
> TextField exp2;
> TextField total;
>
> public void init()
> {
> setLayout(new BorderLayout());
> setBackground(Color.gray);
> setFont(new Font("Helvetica", Font.BOLD, 12));
> }
>
> public void start()
> {
> Panel p = new Panel();
> p.setLayout(new GridLayout(2,2));
> p.add(exp1 = new TextField("10", 30));
> p.add(exp2 = new TextField("15",30));
> p.add(total = new TextField("",30));
>
> mainbar = new Panel();
> mainbar.setLayout(new BorderLayout());
> mainbar.add("West", p);
>
> add("Center", mainbar);
>
> infobar = new Panel();
> infobar.add(new Button("Add the Fields"));
> infobar.add(new Button("Clear all Fields"));
> infobar.add(new Button("Reset all Fields"));
> infobar.setBackground(Color.red);
> add("South", infobar);
> }
>
> public boolean action(Event evt, Object arg)
> {
> if("Add the Fields".equals(arg))
> {
> total.settext(exp1.toString + exp2.toString);
Try:
total.setText(
String.valueOf(
(Double.valueOf( exp1.getText())).doubleValue() +
(Double.valueOf( exp1.getText())).doubleValue()
)
> return true;
> }
> else if("Clear all Fields".equals(arg))
> {
> exp1.setText("");
> exp2.setText("");
> total.setText("");
> return true;
> }
> else if("Reset all Fields".equals(arg))
> {
> exp1.setText("10");
> exp2.setText("15");
> total.setText("");
> return true;
> }
> else if(evt.target instanceof Choice)
> {
> showStatus(arg.toString());
> return true;
> }
> return false;
> }
>
> }
>
>
> -
> This message was sent to the java-interest mailing list
> Info: send 'help' to java-interest-request@java.sun.com
>
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com