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>
怎样才可以在浏览器中显示出排列整齐的程序怎么改啊!!! 展开
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>
怎样才可以在浏览器中显示出排列整齐的程序怎么改啊!!! 展开
2个回答
展开全部
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);
}
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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询