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

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:32:00
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(

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

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

打开浏览器运行看看吧!

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