JAVA程序怎么才可以把两列排列对齐

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class lmy extends Applet implements ActionListener{

Label label1 = new Label("+");
Label Label3 = new Label("=");

TextField field1 = new TextField(6);
TextField field2 = new TextField(6);
TextField field3 = new TextField(6);
Button button1 = new Button("相加");

Label label2 = new Label("-"+ "\n");
Label Label4 = new Label("=" +"\n");

TextField field4 = new TextField(6);
TextField field5 = new TextField(6);
TextField field6 = new TextField(6);
Button button2 = new Button("相减");

public void init(){ //初使化
add(field1);
add(label1);
add(field2);
add(Label3);
add(field3);
add(button1);
button1.addActionListener(this);

add(field4);
add(label2);
add(field5);
add(Label4);
add(field6);
add(button2);
button2.addActionListener(this);
}
public void actionPerformed(ActionEvent e){ //处理按钮事件
int x = Integer.parseInt(field1.getText())+Integer.parseInt(field2.getText());
field3.setText(Integer.toString(x)); //数值转换为字符串
int y = Integer.parseInt(field4.getText())-Integer.parseInt(field5.getText());
field6.setText(Integer.toString(y)); //数值转换为字符串
}
}
<html>
<applet code = "lmy.class" height = 200 width = 400><applet>
</html>
怎样才可以在浏览器中显示出排列整齐的程序怎么改啊!!!

我看了一下,代码没问题!你只是需要在浏览器中显示出排列整齐的界面对吧?那你只需要把你这个html超文本文件里的width = 400改为width = 350就可以了!即:

<html>
<applet code = "lmy.class" height = 200 width = 350><applet>
</html>

打开浏览器运行看看吧!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-02-14
public void init(){ //初使化
Panel p1=new Panel(),p2=new Panel();
setLayout(new BorderLayout());
add("North",p1);add("Center",p2);
p1.add(field1);
p1.add(label1);
p1.add(field2);
p1.add(Label3);
p1.add(field3);
p1.add(button1);
button1.addActionListener(this);

p2.add(field4);
p2.add(label2);
p2.add(field5);
p2.add(Label4);
p2.add(field6);
p2.add(button2);
button2.addActionListener(this);
}
相似回答