用户界面相关设计.pptVIP

  • 1
  • 0
  • 约1.25万字
  • 约 40页
  • 2019-08-29 发布于广东
  • 举报
第10课 用户界面设计 AWT容器 容器Container能够用来存放别的组件。 有两种类型的容器:Window和Panel。 Frame容器 Window是能独立存在的容器,它有一个子类Frame。 Frame有一个构造方法Frame(String title) 你可以通过add()方法,在Frame中加入其他的组件。 Frame被创建后,它是不可见的. 参见FrameShower.java FrameShower.java package gui; import java.awt.*; public class FrameShower{ public static void main(String args[]){ Frame f=new Frame(hello); f.add(new Button(Press Me)); f.setSize(100,100); f.setVisible(true); } } Panel容器 Panel只能存在于其他的容器(Window或其子类)中. 通过Panel的默认构造方法Panel()可以创建一个Panel。 参见MyFrame.java MyFrame.java package gui; import java.awt.*; public class MyFrame extends Frame{ Panel panel=new Panel(); Button button=new Button(press me); public MyFrame(String title){ super(title); panel.add(button); panel.setBackground(Color.yellow); add(panel); setBackground(Color.blue); setSize(500,500); setVisible(true); } public static void main(String args[]){ MyFrame f=new MyFrame(hello); } } 布局管理器 一.取消布局管理器 setLayout(null) 二.默认布局管理器 Window,Frame和Dialog的默认布局管理器是BorderLayout Panel和Applet的默认布局管理器是FlowLayout。 取消布局管理器 public MyFrame(String title){ super(title); panel.setLayout(null); panel.setSize(200,200); panel.setLocation(50,50); button.setSize(80,50); button.setLocation(80,80); panel.add(button); panel.setBackground(Color.yellow); setLayout(null); add(panel); setBackground(Color.blue); setSize(500,500); setVisible(true); } 布局管理器 布局管理器分为5种: - FlowLayout 流式布局管理器 - BorderLayout边界布局管理器 - GridLayout网格布局管理器 - CardLayout卡片布局管理器 - GridBagLayout网格包布局管理器 布局管理器练习 运行 MyFlow.java 运行 BorderLayoutTester.java 运行GridEx.java 运行 CardLayoutTester.java 运行GridBagEx1.java 改变容器中组件的布局,观看显示效果 FlowLayout public class MyFlow { private Frame f; private Button button1, button2, button3; public static void main (String args[]) { MyFlow mflow = new MyFlow (); mflow.go(); } public void go() { f = new Frame (Flow Layout); f.setLayout(new FlowLayou

文档评论(0)

1亿VIP精品文档

相关文档