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

importjava.awt.*;importjava.awt.event.*;importjava.applet.Applet;publicclasslmyextend... 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>
怎样才可以在浏览器中显示出排列整齐的程序怎么改啊!!!
展开
 我来答
Java天地
2008-02-15 · TA获得超过158个赞
知道小有建树答主
回答量:71
采纳率:0%
帮助的人:144万
展开全部
我看了一下,代码没问题!你只是需要在浏览器中显示出排列整齐的界面对吧?那你只需要把你这个html超文本文件里的width = 400改为width = 350就可以了!即:

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

打开浏览器运行看看吧!
HeartIess
2008-02-14 · TA获得超过1177个赞
知道小有建树答主
回答量:1076
采纳率:0%
帮助的人:838万
展开全部
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);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式