import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class JSQDemo extends Applet implements ActionListener
{
public TextField no1;
Label lb=new Label("+",Label.CENTER);
public TextField no2;

public void init()
{
//Frame f = new Frame("Flow Lay out");
Button dengyu=new Button("等于");
        
        Label lc=new Label("",Label.CENTER);
        Button exit=new Button("exit");
Label no11=new Label("请输入两个数");
Panel p = new Panel();
               // p.setLayout(new  FlowLayout());      add(no11);
     add(lc);
     no1=new TextField(10);
     add(no1);
     
     no2=new TextField(10);
     add(no2);
     add(lb);
     add(dengyu);
     add(exit);



//setSize(600,700);
dengyu.addActionListener(this);
exit.addActionListener(this);
}
public void paint(Graphics g)
{

}
public void actionPerformed(ActionEvent e)
{
String Label=e.getActionCommand();
if(Label=="exit")
System.exit(0);
//else if(co==dengyu)
//lb.setText((e.getActionCommand(no1))+(e.getActionCommand(no2)));
//repaint();

}
///public static void main(String args[])
//{


// JSQDemo se=new JSQDemo();
// se.show();

//}
}
用什么语句?调用文本框输入的内容,还有“+”怎么加不到两个文本框之间?
谢谢!!!

解决方案 »

  1.   

    textField.getText()可以读取它的数据textField.getText()+textField.getText()是可以的
      

  2.   

    textField.getText()可以读取它的数据 textField.getText()+textField.getText()是可以的
      

  3.   

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class Jsq extends Applet implements ActionListener{
    public TextField tf1;
    public TextField tf2;
    Label la=new Label("+");
    Button b1=new Button(" = ");
    Button b2=new Button("exit");
    Label la1=new Label("      ");
    public void init()
    {   FlowLayout flow=new FlowLayout();
          flow.setAlignment(FlowLayout.LEFT);
          flow.setHgap(20);flow.setVgap(40);
          setLayout(flow);
          //setLayout(new GridLayout(1,2));  
    setBackground(Color.cyan);
       tf1=new TextField(10);
        add(tf1);
        add(la);
         tf2=new TextField(10);
        add(tf2);
       add(b1);
        add(la1);
        add(b2);
       b1.addActionListener(this); 
       b2.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ev)
    {String la2=ev.getActionCommand();
    String l1,l2;
    l1=tf1.getText();
    l2=tf2.getText();
    int a=Integer.valueOf(l1).intValue();
    int b=Integer.valueOf(l2).intValue();
    int c=a+b;
    String l3=String.valueOf(c);
    if(la2==" = ")
    la1.setText(l3);
    else System.exit(0);
    }
    }//flaot n=Float.valueOf("12334.870").floatValue() 
    这个怎么用的是flow不明白?????
    求救!!!