您的位置:首页 > 产品设计 > UI/UE

GUI编程笔记(java)04:GUI(HelloWorld)窗体案例

2015-08-25 20:20 579 查看
1.Frame

在JAVA中,[b]Frame是一种控件,可作为父窗体加载其他swing控件。案例:[/b]

package cn.itcast_01;

import java.awt.Frame;

public class FrameDemo {
public static void main(String[] args) {
// 创建窗体对象
// Frame f = new Frame();
// Frame(String title)
Frame f = new Frame("林青霞");

// 设置窗体标题
//f.setTitle("HelloWorld");
// 设置窗体大小
f.setSize(400, 300); // 单位:像素
// 设置窗体位置
f.setLocation(400, 200);

// 调用一个方法,设置让窗体可见
// f.show();
f.setVisible(true);

// System.out.println("helloworld");
}
}


运行的效果:





2.代码的优化:

package cn.itcast_01;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Point;

public class FrameDemo2 {
public static void main(String[] args) {
// 创建对象
Frame f = new Frame("方法调用的前后关系");

//Dimension(int width, int height)
Dimension d = new Dimension(400, 300);
f.setSize(d);
// Point(int x, int y)
Point p = new Point(400, 200);
f.setLocation(p);
// 一个方法搞定setBounds(int x, int y, int width, int height);
//f.setBounds(400, 200, 400, 300);
f.setVisible(true);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: