Box容器中的"刚性区域"概念
2009-10-01 20:57
225 查看
该例是为了学习刚性区域的用法.
(1)Box4.java
import javax.swing.*;
import java.awt.*;
public class Box4 extends JApplet
{
public void init()
{
Box bv=Box.createVerticalBox();
bv.add(new JButton("Top"));
bv.add(Box.createRigidArea(new Dimension(120,90)));
bv.add(new JButton("Bottom"));
Box bh=Box.createHorizontalBox();
bh.add(new JButton("Left"));
bh.add(Box.createRigidArea(new Dimension(160,80)));
bh.add(new JButton("Right"));
bv.add(bh);
getContentPane().add(bv);
}
public static void main(String[] args)
{
Console.run(new Box4(),450,300);
}
}
(2)Console.java
import javax.swing.*;
public class Console
{
public static String title(Object o)
{
String t=o.getClass().toString();
if(t.indexOf("class")!=-1)
{
t=t.substring(6);
}
return t;
}
public static void run(JFrame frame,int width,int height)
{
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width,height);
frame.setVisible(true);
}
public static void run(JApplet applet,int width,int height)
{
JFrame frame=new JFrame(title(applet));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width,height);
applet.init();
applet.start();
frame.setVisible(true);
}
public static void run(JPanel panel,int width,int height)
{
JFrame frame=new JFrame(title(panel));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}
注意:"刚性区域"使用了绝对值,因此有人认为这么做带来的问题比带来的好处更多,
所以,要慎用。
(1)Box4.java
import javax.swing.*;
import java.awt.*;
public class Box4 extends JApplet
{
public void init()
{
Box bv=Box.createVerticalBox();
bv.add(new JButton("Top"));
bv.add(Box.createRigidArea(new Dimension(120,90)));
bv.add(new JButton("Bottom"));
Box bh=Box.createHorizontalBox();
bh.add(new JButton("Left"));
bh.add(Box.createRigidArea(new Dimension(160,80)));
bh.add(new JButton("Right"));
bv.add(bh);
getContentPane().add(bv);
}
public static void main(String[] args)
{
Console.run(new Box4(),450,300);
}
}
(2)Console.java
import javax.swing.*;
public class Console
{
public static String title(Object o)
{
String t=o.getClass().toString();
if(t.indexOf("class")!=-1)
{
t=t.substring(6);
}
return t;
}
public static void run(JFrame frame,int width,int height)
{
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width,height);
frame.setVisible(true);
}
public static void run(JApplet applet,int width,int height)
{
JFrame frame=new JFrame(title(applet));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width,height);
applet.init();
applet.start();
frame.setVisible(true);
}
public static void run(JPanel panel,int width,int height)
{
JFrame frame=new JFrame(title(panel));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}
注意:"刚性区域"使用了绝对值,因此有人认为这么做带来的问题比带来的好处更多,
所以,要慎用。
相关文章推荐
- Box容器中的"支架"概念
- Box容器中的"胶水"概念
- "回生电阻" 是什么个概念?
- "堆"和"栈"的基本概念(C/C++初学者必读)
- 黑马程序员--java基础--java中常用的"容器"-集合
- 管理者的" 概念技能"
- "创建的CMO对象失败,应用程序将被中断"和"Unable to load VirtualBox engin"解决方法
- "和平使命-2007"中方部队抵达演习区域
- "your computer needs to restart" when install Windows 8 on Virtualbox
- "HelloNeon" on android-ndk-r5
- "performSelector may cause a leak because its selector is unknown"警告原因及其解决办法
- "XP practices" 应翻译为"XP惯例"
- "app_name" is not translated in "en" (English)
- object-c之从"Hello World"开始(object-c)
- glassfish3下报错"只有事务类型为 JTA 的持久性单元才能用作容器管理的实体管理器"
- "窗体加载闪烁处理、无边框窗体的移动" 之 配餐系统的开发
- "EGO" Xcode Theme for Xcode 4 + EGOv2
- "Bilateral texture filtering"论文 matlab实现代码
- JDBC中鲜为人知的"中级应用"
- Undefined symbols for architecture i386: "_SecItemAdd", referenced from: