JAVA编程 图形用户界面详解.docVIP

  • 21
  • 0
  • 约2.64万字
  • 约 31页
  • 2018-02-17 发布于湖北
  • 举报
JAVA编程 图形用户界面详解

成绩: JAVA编程B实验报告 实验时间:2012年月 JAVA编程B了解图形用户界面基本组件窗口、按钮、文本框、选择框、滚动条等的使用方法 2、了解如何使用布局管理器对组件进行管理,以及如何使用Java 的事件处理机制。Windows 7、JDK 1.6与Eclipse 3.5创建图形用户界面了解事件处理机制使用Swing 组件 使用自定义对话框与内部类 import java.awt.*; import java.applet.Applet; public class JAVA_B_6_1 extends Applet { Label l1; //标签 Button b1, b2, b3, b4, b5, b6; //按键 public void init() { setLayout(new GridLayout(3, 3)); // 设置网格布局(3 行3 列共9 个网格) l1 = new Label(标签1); b1 = new Button(按钮1); b2 = new Button(按钮2); b3 = new Button(按钮3); b4 = new Button(按钮4); add(l1); add(b1); add(b2); add(b3); add(new Label()); add(b4); add(new Button(按钮5)); add(new Button(按钮6)); add(new Label(标签2)); } }import java.awt.*; import java.awt.Color; import java.applet.Applet; public class JAVA_B_6_2 extends Applet { public void init() { setFont(new Font(Arial, Font.PLAIN, 20)); // 设置最底层的 Applet 容器为顺序布局 Label l = new Label(这是最底层的 Applet 容器中的标签, Label.CENTER); add(l); Panel panel1 = new Panel(); add(panel1); panel1.setBackground(Color.blue); //设置背景颜色 panel1.setForeground(Color.red); //设置字体颜色 panel1.setLayout(new BorderLayout());// 设置边界布局 panel1.add(North, new Button(北)); panel1.add(South, new Button(南)); panel1.add(East, new Button(东)); panel1.add(West, new Button(西)); panel1.add(Center, new Label(这是在 Panel1 面板 中部添加的标签)); Panel panel2 = new Panel(); add(panel2); panel2.setLayout(new GridLayout(3, 1)); // 设置网格布局 Choice c = new Choice();// 创建下拉式列表 c.addItem(北京); c.addItem(上海); c.addItem(天津); Label l1 = new Label(这是在 Panel2 面板中的标签); Button b1 = new Button(Panel2 中的按钮); panel2.setBackground(Color.green); panel2.add(l1); panel2.add(b1); panel2.add(c); } }import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class JAVA_B_6_3 extends Applet implements ActionListener { // 实现动作事件监听接口 public void init() { setLayout(null);// 关闭默认的顺序管理布局 Label l = new Label(按一下按钮可听到响声!, Label.CENTER); add(l); l.setBounds(40, 10, 150, 30); Button b

文档评论(0)

1亿VIP精品文档

相关文档