java FlowLayout里面的参数是什么意思?那参数和整体布局到底有什么对应关系?
importjava.awt.*;importjavax.swing.*;publicclassComputerextendsJFrame{Computer(){JPan...
import java.awt.*;
import javax.swing.*;
public class Computer extends JFrame{
Computer(){
JPanel p1=new JPanel(new FlowLayout(3,5,5));
for(int i=9;i>=1;i--){
p1.add(new JButton(" "+i));
}
JPanel p2=new JPanel(new BorderLayout());
p2.add(new JButton(" -"),BorderLayout.NORTH);
p2.add(new JButton(" +"),BorderLayout.SOUTH);
JPanel p3=new JPanel(new FlowLayout(1));
p3.add(new JButton("="));
JPanel p4=new JPanel(new BorderLayout());
p4.add(p2,BorderLayout.CENTER);
p4.add(p3,BorderLayout.EAST);
JPanel p5=new JPanel(new FlowLayout(4,5,5));
p5.add(new JButton("M+"));
p5.add(new JButton("M-"));
p5.add(new JButton("±"));
p5.add(new JButton("√"));
p5.add(new JButton("/"));
p5.add(new JButton("%"));
p5.add(new JButton("×"));
p5.add(new JButton("1/x"));
JPanel p6=new JPanel(new FlowLayout(2,5,5));
p6.add(new JButton("MC"));
p6.add(new JButton("MR"));
p6.add(new JButton("MS"));
p6.add(new JButton("←"));
p6.add(new JButton("CE"));
p6.add(new JButton(" C"));
JPanel p7=new JPanel(new FlowLayout(1,5,5));
p7.add(new JButton(" 0"));
p7.add(new JButton(" ."));
JPanel p8=new JPanel(new GridLayout());
p8.add(p6,BorderLayout.NORTH);
p8.add(p1,BorderLayout.CENTER);
p8.add(p7,BorderLayout.SOUTH);
JPanel p9=new JPanel(new GridLayout());
p9.add(p5,BorderLayout.NORTH);
p9.add(p4,BorderLayout.SOUTH);
JPanel p10=new JPanel(new GridLayout());
p10.add(p8,BorderLayout.WEST);
p10.add(p9,BorderLayout.EAST);
add(new JButton(" 0"),BorderLayout.NORTH);
add(p10,BorderLayout.SOUTH);
}
public static void main(String[] args){
Computer frame=new Computer();
frame.setTitle("计算器");
frame.setSize(400,400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}} 展开
import javax.swing.*;
public class Computer extends JFrame{
Computer(){
JPanel p1=new JPanel(new FlowLayout(3,5,5));
for(int i=9;i>=1;i--){
p1.add(new JButton(" "+i));
}
JPanel p2=new JPanel(new BorderLayout());
p2.add(new JButton(" -"),BorderLayout.NORTH);
p2.add(new JButton(" +"),BorderLayout.SOUTH);
JPanel p3=new JPanel(new FlowLayout(1));
p3.add(new JButton("="));
JPanel p4=new JPanel(new BorderLayout());
p4.add(p2,BorderLayout.CENTER);
p4.add(p3,BorderLayout.EAST);
JPanel p5=new JPanel(new FlowLayout(4,5,5));
p5.add(new JButton("M+"));
p5.add(new JButton("M-"));
p5.add(new JButton("±"));
p5.add(new JButton("√"));
p5.add(new JButton("/"));
p5.add(new JButton("%"));
p5.add(new JButton("×"));
p5.add(new JButton("1/x"));
JPanel p6=new JPanel(new FlowLayout(2,5,5));
p6.add(new JButton("MC"));
p6.add(new JButton("MR"));
p6.add(new JButton("MS"));
p6.add(new JButton("←"));
p6.add(new JButton("CE"));
p6.add(new JButton(" C"));
JPanel p7=new JPanel(new FlowLayout(1,5,5));
p7.add(new JButton(" 0"));
p7.add(new JButton(" ."));
JPanel p8=new JPanel(new GridLayout());
p8.add(p6,BorderLayout.NORTH);
p8.add(p1,BorderLayout.CENTER);
p8.add(p7,BorderLayout.SOUTH);
JPanel p9=new JPanel(new GridLayout());
p9.add(p5,BorderLayout.NORTH);
p9.add(p4,BorderLayout.SOUTH);
JPanel p10=new JPanel(new GridLayout());
p10.add(p8,BorderLayout.WEST);
p10.add(p9,BorderLayout.EAST);
add(new JButton(" 0"),BorderLayout.NORTH);
add(p10,BorderLayout.SOUTH);
}
public static void main(String[] args){
Computer frame=new Computer();
frame.setTitle("计算器");
frame.setSize(400,400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询