java中JFrame没有设置BorderLayout为什么还可以用
packageChapter12;importjava.awt.*;importjavax.swing.*;publicclassShowPanelextendsJFra...
package Chapter12;
import java.awt.*;
import javax.swing.*;
public class ShowPanel extends JFrame{
/**
* @param args
*/
public ShowPanel(){
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(4,3));
for(int i=1;i<=9;i++)
p1.add(new JButton(""+i));
p1.add(new JButton(""+0));
p1.add(new JButton("Start"));
p1.add(new JButton("Stop"));
JPanel p2 = new JPanel();
p2.setLayout(new BorderLayout());
p2.add(new JTextField("Time to be displayed here"),BorderLayout.NORTH);
p2.add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.EAST); // 问题在这
add(new JButton("Food to be placed here"),BorderLayout.CENTER);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
ShowPanel frame = new ShowPanel();
frame.setTitle("The Front View of a Microwave Oven");
frame.setSize(400,250);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
} 展开
import java.awt.*;
import javax.swing.*;
public class ShowPanel extends JFrame{
/**
* @param args
*/
public ShowPanel(){
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(4,3));
for(int i=1;i<=9;i++)
p1.add(new JButton(""+i));
p1.add(new JButton(""+0));
p1.add(new JButton("Start"));
p1.add(new JButton("Stop"));
JPanel p2 = new JPanel();
p2.setLayout(new BorderLayout());
p2.add(new JTextField("Time to be displayed here"),BorderLayout.NORTH);
p2.add(p1,BorderLayout.CENTER);
add(p2,BorderLayout.EAST); // 问题在这
add(new JButton("Food to be placed here"),BorderLayout.CENTER);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
ShowPanel frame = new ShowPanel();
frame.setTitle("The Front View of a Microwave Oven");
frame.setSize(400,250);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询