[3945] in java-interest

home help back first fref pref prev next nref lref last post

I need help with Java Beta Adding

daemon@ATHENA.MIT.EDU (Jonathan_Mark_Smith@CCMAIL.PRUSEC.)
Tue Dec 5 02:39:51 1995

From: Jonathan_Mark_Smith@CCMAIL.PRUSEC.COM
Date: Mon, 04 Dec 95 11:11:31 EST
To: java-interest@java.sun.com

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);
                        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

home help back first fref pref prev next nref lref last post