Java基础 awt Frame 设置窗体的大小 位置 可见性

  •     JDK :OpenJDK-11
  •      OS :CentOS 7.6.1810
  •      IDE :Eclipse 2019‑03
  • typesetting :Markdown

code

package per.jizuiku.gui;

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

/**
 * @author 给最苦
 * @date 2019/06/30
 * @blog www.cnblogs.com/jizuiku
 */
public class Demo {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // 创建窗体对象 相当于 创建了一个线程
        Frame f = new Frame();

        // 设置窗体的标题
        // Frame(String title) 可以通过构造函数来设置
        f.setTitle("第一个窗口程序");

        // 设置窗体的大小,单位是像素
        int width = 400;
        int height = 500;
        Dimension d = new Dimension(width, height);
        f.setSize(d);

        // 设置窗体出现的位置
        int x = 300;
        int y = 200;
        Point p = new Point(x, y);
        f.setLocation(p);

        // f.setBounds(x, y, width, height);
        // 可以通过这个函数 一次性设置窗口的位置和大小s

        // 让窗体显示出来
        f.setVisible(true);

    }

}

result

1161442-20190630161419455-348690354.png

sourceCode

/**
    * {@inheritDoc}
    * <p>
    * The {@code d.width} and {@code d.height} values
    * are automatically enlarged if either is less than
    * the minimum size as specified by previous call to
    * {@code setMinimumSize}.
    * <p>
    * The method changes the geometry-related data. Therefore,
    * the native windowing system may ignore such requests, or it may modify
    * the requested data, so that the {@code Window} object is placed and sized
    * in a way that corresponds closely to the desktop settings.
    *
    * @see #getSize
    * @see #setBounds
    * @see #setMinimumSize
    * @since 1.6
    */
public void setSize(Dimension d) {
    super.setSize(d);
}
/**
    * {@inheritDoc}
    * <p>
    * The method changes the geometry-related data. Therefore,
    * the native windowing system may ignore such requests, or it may modify
    * the requested data, so that the {@code Window} object is placed and sized
    * in a way that corresponds closely to the desktop settings.
    */
@Override
public void setLocation(Point p) {
    super.setLocation(p);
}

resource

  • [ JDK ] openjdk.java.net
  • [ doc - 参考 ] docs.oracle.com/en/java/javase/11
  • [ 规范 - 推荐 ] yq.aliyun.com/articles/69327
  • [ 规范 - 推荐 ] google.github.io/styleguide
  • [ 源码 ] hg.openjdk.java.net
  • [ OS ] www.centos.org
  • [ IDE ] www.eclipse.org/downloads/packages
  • [ 平台 ] www.cnblogs.com


感谢帮助过 给最苦 的人们。
Java、Groovy和Scala等基于JVM的语言,优秀,值得学习。
规范的命名和代码格式等,有助于沟通和理解。
JVM的配置、监控与优化,比较实用,值得学习。

转载于:https://www.cnblogs.com/jizuiku/p/11110227.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值