1 / 9

学习情境 5-2

学习情境 5-2. 应用布局管理器设计学生信息录入界面. 教学目标: 掌握常用的容器组件及其使用方法 教学重点: 掌握常用的容器组件及其使用方法 教学难点: 掌握常用的容器组件及其使用方法 教学课时: 2 学时. 工作任务. 应用布局管理器设计学生信息录入界面. 在 Eclipse 编辑器中,新建 AddF I 类 AddF I 类继承 JFrame 窗口类. 1. 在 Eclipse 编辑器中,新建 AddFI 类继承 JFrame 窗口类,编写如下代码:. Container c2 = this.getContentPane();

Download Presentation

学习情境 5-2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 学习情境5-2 应用布局管理器设计学生信息录入界面

  2. 教学目标: • 掌握常用的容器组件及其使用方法 • 教学重点: • 掌握常用的容器组件及其使用方法 • 教学难点: • 掌握常用的容器组件及其使用方法 • 教学课时:2学时

  3. 工作任务 • 应用布局管理器设计学生信息录入界面

  4. 在Eclipse编辑器中,新建AddFI类 • AddFI类继承JFrame窗口类

  5. 1.在Eclipse编辑器中,新建AddFI类继承JFrame窗口类,编写如下代码:1.在Eclipse编辑器中,新建AddFI类继承JFrame窗口类,编写如下代码: Container c2 = this.getContentPane(); c2.setLayout(new GridLayout(3, 1)); JPanel center = new JPanel(new GridLayout(5, 2)); JPanel low = new JPanel(new FlowLayout()); JLabel label1 = new JLabel("添加学生信息", SwingConstants.CENTER); label1.setFont(new Font("TRUE", Font.TRUETYPE_FONT, 20)); c2.add(label1); STNOText = new JTextField(30);//30列文本框 SNAMEText = new JTextField(30); SUMText = new JTextField(30); JAVAText = new JTextField(30); center.add(new JLabel("学号", SwingConstants.CENTER));//添加标签学号写在标签中间 center.add(STNOText);//添加文本框 5

  6. center.add(new JLabel("姓名", SwingConstants.CENTER)); center.add(SNAMEText); center.add(new JLabel("高考总分", SwingConstants.CENTER)); center.add(SUMText); center.add(new JLabel("java", SwingConstants.CENTER)); center.add(JAVAText); c2.add(center); b1 = new JButton("添加"); b2 = new JButton("清除"); b3 = new JButton("退出"); low.add(b1); low.add(b2); low.add(b3); c2.add(low); this.setBounds(200, 200, 600, 400); this.setVisible(true); this.setTitle("添加学生信息"); } 6

  7. 布局管理器 布局管理器决定组件在容器中的位置和尺寸。所有容器都会引用一个布局管理器的实例,通过它来自动进行组件的布局管理。当一个容器被创建后,它们有相应的默认布局管理器。Window、Frame、Dialog的默认布局管理器是 BorderLayout;Panel、Applet的默认布局管理器是FlowLayout。

  8. FreeLayout类取消了布局管理器,然后按照手工布局把一个Button加入到Frame中。 FreeLayout类取消了布局管理器,然后按照手工布局把一个Button加入到Frame中。 import java.awt.*; public class FreeLayout { public static void main(String[] args){ Frame f = new Frame("First"); f.setLayout(null); //取消布局管理器 f.setSize(300, 150); //宽300,高150 Button b = new Button("Press"); b.setSize(100, 30); //宽100,高30 b.setLocation(45, 65); //x坐标45,y坐标65 f.add(b); f.setVisible(true); } } 8

  9. 小结 • 布局管理器

More Related