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

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的配置、監控與優化,比較實用,值得學習。java

相關文章
相關標籤/搜索