码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-08-25 21:18:08      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:

1.Frame

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

 1 package cn.itcast_01;
 2 
 3 import java.awt.Frame;
 4 
 5 public class FrameDemo {
 6     public static void main(String[] args) {
 7         // 创建窗体对象
 8         // Frame f = new Frame();
 9         // Frame(String title)
10         Frame f = new Frame("林青霞");
11 
12         // 设置窗体标题
13         //f.setTitle("HelloWorld");
14         // 设置窗体大小
15         f.setSize(400, 300); // 单位:像素
16         // 设置窗体位置
17         f.setLocation(400, 200);
18 
19         // 调用一个方法,设置让窗体可见
20         // f.show();
21         f.setVisible(true);
22 
23         // System.out.println("helloworld");
24     }
25 }

运行的效果:

技术分享

 

 

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);
    }
}

 

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

标签:

原文地址:http://www.cnblogs.com/hebao0514/p/4758518.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!