Panel: 确定一个四边形,可以添加其他组件(add()方法),但必须放在Window或Window的子类之中,才能显示出来。 Frame:可以添加其他组件(add()方法),具有标题和缩放角 Dialog 是一个带标题和边界的顶层窗口,边界一般用于从用户处获得某种形式的输入 TextComponent:允许编辑文本的组件的超类 TextField:创建文本框对象 TextA...
panel.add(newLabel("first"));//将标签放入面板中getContentPane().add(panel);//将panel放入jframe界面JPanel panel_1=newJPanel();//第二个JPanelpanel_1.setBorder(newLineBorder(Color.PINK)); panel_1.setBounds(10, 141, 364, 128); panel_1.add(newLabel("second"));//这是第二个面板getCo...
29 add(but_02); 30 add(jLabel); 31 } 32 private static Panel_02 panel_02=null; 33 //对外接口 34 public static Panel_02 getInstance(JFrame jFrame){ 35 panel_02 = new Panel_02(jFrame); 36 return panel_02; 37 } 38 } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13....
Panel 实际上,Frame往往仅作为容器存在,想要绘制的窗口内容一般在Panel中实现。 publicclassTestPanel{publicstaticvoidmain(String[] args){MyFramemyFrame=newMyFrame(300,300,500,500,Color.green); myFrame.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvent e){ System.exit(0); } });...
是这样的:BorderLayout默认会压缩四周,即压缩North,South,West,East中的组件;同时扩展中心,即Center中的组件。由于你的WEST和EAST中的Panel都没有设置首选大小(调用setPreferredSize),所以会被压缩至没有宽度,就看不见了。你只需要加上:p1.setPreferredSize(new Dimension(xxx,xxx));p2.set...
frame.setLayout(null);panel.setSize(x, y);//假设你需要设置的panel是这个大小。int width = frame.getWidth(), height = frame.getHeight();panel.setLocation((width - x) / 2, (height - y) / 2);你
("测试文本框");// 创建 按钮Button button=newButton("测试按钮");// 向 Panel 中添加文本框和按钮panel.add(textField);panel.add(button);// 将 Panel 放到 Frame 中frame.add(panel);// 设置窗口位置frame.setLocation(50,50);// 设置窗口大小frame.setSize(800,500);// 设置窗口可见frame....
{publicstaticvoidmain(String[]args){JFrame frame=newJFrame("JPanel Example");frame.setSize(400,300);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JPanel panel=newJPanel();JButton button=newJButton("Click me!");panel.add(button);frame.getContentPane().add(panel);frame.setVisible(...
this.add(jpBlueRightBottom1); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } } //使用第二种方式(就是传窗口)得到页面的控件 class swingJpanel_shijian implements ActionListener{ public static swingJpanel ss;//现在的ss就是拥有控件的窗体了 ...
this.add(jpBlueRightBottom1); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } } //使用第二种方式(就是传窗口)得到页面的控件 class swingJpanel_shijian implements ActionListener{ public static swingJpanel ss;//现在的ss就是拥有控件的窗体了 ...