Box容器中的"胶水"概念
2009-10-01 20:55
267 查看
该例是为了学习胶水的用法.胶水是尽可能地将组件分离开。
(1)Box3.java
import javax.swing.*;
import java.awt.*;
public class Box3 extends JApplet
{
public void init()
{
Box bv=Box.createVerticalBox();
bv.add(new JLabel("Hello"));
bv.add(Box.createVerticalGlue());
bv.add(new JLabel("Applet"));
bv.add(Box.createVerticalGlue());
bv.add(new JLabel("World"));
Box bh=Box.createHorizontalBox();
bh.add(new JLabel("Hello"));
bh.add(Box.createHorizontalGlue());
bh.add(new JLabel("Applet"));
bh.add(Box.createHorizontalGlue());
bh.add(new JLabel("World"));
bv.add(Box.createVerticalGlue());
bv.add(bh);
bv.add(Box.createVerticalGlue());
getContentPane().add(bv);
}
public static void main(String[] args)
{
Console.run(new Box3(),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)Box3.java
import javax.swing.*;
import java.awt.*;
public class Box3 extends JApplet
{
public void init()
{
Box bv=Box.createVerticalBox();
bv.add(new JLabel("Hello"));
bv.add(Box.createVerticalGlue());
bv.add(new JLabel("Applet"));
bv.add(Box.createVerticalGlue());
bv.add(new JLabel("World"));
Box bh=Box.createHorizontalBox();
bh.add(new JLabel("Hello"));
bh.add(Box.createHorizontalGlue());
bh.add(new JLabel("Applet"));
bh.add(Box.createHorizontalGlue());
bh.add(new JLabel("World"));
bv.add(Box.createVerticalGlue());
bv.add(bh);
bv.add(Box.createVerticalGlue());
getContentPane().add(bv);
}
public static void main(String[] args)
{
Console.run(new Box3(),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++初学者必读)
- "创建的CMO对象失败,应用程序将被中断"和"Unable to load VirtualBox engin"解决方法
- "your computer needs to restart" when install Windows 8 on Virtualbox
- "回生电阻" 是什么个概念?
- 黑马程序员--java基础--java中常用的"容器"-集合
- 管理者的" 概念技能"
- 长度小于8000(varchar类型),以"逗号"分隔的字符串
- "The length of the string value exceeds the length configured in the mapping/parameter."}
- "印度制造"能否取代"中国制造"?
- tomcat作服务时出现的" 重叠I/O操作在进行中"
- <context:component-scan base-package="com.xx" />
- JDBC中鲜为人知的"中级应用"
- <input type = "submit"> 提交方式和用js的form.submit()有什么区别?
- <jsp:include>和<%@include file=""%> 有什么区别
- "无法删除文件夹,目录不是空的"解决办法
- 发布windows的"Universal Apps" Unity3D游戏
- "围观"设计模式(11)--结构型之适配器模式(Adapter Pattern)
- 婉约有致 华三川笔下的"十大神话仕女"