一个关于java中的frame里面布局的问题
importjava.awt.*;importjavax.swing.*;publicclassGridLayoutHOMEWORK{publicstaticvoidma...
import java.awt.*;
import javax.swing.*;
public class GridLayoutHOMEWORK {
public static void main(String args[]){
GridLayoutFrame gf=new GridLayoutFrame();
gf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gf.setVisible(true);
}
}
class GridLayoutFrame extends JFrame
{
private JPanel contentPane1,contentPane2,contentPane3;
public GridLayoutFrame(){
setSize(500,300);
JTextField textfield=new JTextField(10);
textfield.setMaximumSize(textfield.getMaximumSize());
contentPane2.add(textfield);
contentPane1.setLayout(new GridLayout(4,4,0,0));
contentPane1.add(new JButton("7"));
contentPane1.add(new JButton("8"));
contentPane1.add(new JButton("9"));
contentPane1.add(new JButton("/"));
contentPane1.add(new JButton("4"));
contentPane1.add(new JButton("5"));
contentPane1.add(new JButton("6"));
contentPane1.add(new JButton("*"));
contentPane1.add(new JButton("1"));
contentPane1.add(new JButton("2"));
contentPane1.add(new JButton("3"));
contentPane1.add(new JButton("-"));
contentPane1.add(new JButton("0"));
contentPane1.add(new JButton("."));
contentPane1.add(new JButton("="));
contentPane1.add(new JButton("+"));
contentPane3.setLayout(new BorderLayout());
contentPane3.add(contentPane2,BorderLayout.NORTH);
contentPane3.add(contentPane1,BorderLayout.CENTER);
add(contentPane3);
}
}
想知道我的代码问题在哪 展开
import javax.swing.*;
public class GridLayoutHOMEWORK {
public static void main(String args[]){
GridLayoutFrame gf=new GridLayoutFrame();
gf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gf.setVisible(true);
}
}
class GridLayoutFrame extends JFrame
{
private JPanel contentPane1,contentPane2,contentPane3;
public GridLayoutFrame(){
setSize(500,300);
JTextField textfield=new JTextField(10);
textfield.setMaximumSize(textfield.getMaximumSize());
contentPane2.add(textfield);
contentPane1.setLayout(new GridLayout(4,4,0,0));
contentPane1.add(new JButton("7"));
contentPane1.add(new JButton("8"));
contentPane1.add(new JButton("9"));
contentPane1.add(new JButton("/"));
contentPane1.add(new JButton("4"));
contentPane1.add(new JButton("5"));
contentPane1.add(new JButton("6"));
contentPane1.add(new JButton("*"));
contentPane1.add(new JButton("1"));
contentPane1.add(new JButton("2"));
contentPane1.add(new JButton("3"));
contentPane1.add(new JButton("-"));
contentPane1.add(new JButton("0"));
contentPane1.add(new JButton("."));
contentPane1.add(new JButton("="));
contentPane1.add(new JButton("+"));
contentPane3.setLayout(new BorderLayout());
contentPane3.add(contentPane2,BorderLayout.NORTH);
contentPane3.add(contentPane1,BorderLayout.CENTER);
add(contentPane3);
}
}
想知道我的代码问题在哪 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询