0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Javaで「パネルのサイズの設定と枠線の表示」の動作を確認してみた。

Posted at

概要

Javaで「パネルのサイズの設定と枠線の表示」の動作を確認してみました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

Sample.java
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Dimension;

class Sample extends JFrame{
  public static void main(String args[]){
    Sample frame = new Sample("MyTitle");
    frame.setVisible(true);
  }

  Sample(String title){
    setTitle(title);
    setBounds(100, 100, 728, 400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setLayout(new FlowLayout());

    JPanel panel1 = new JPanel();
    panel1.setBackground(Color.BLUE);
    panel1.setPreferredSize(new Dimension(150, 100));

    JPanel panel2 = new JPanel();
    panel2.setBackground(Color.RED);
    panel2.setPreferredSize(new Dimension(100, 200));

    add(panel1);
    add(panel2);
  }
}

以下のコマンドを実行しました。

$ javac Sample.java 
$ java Sample 

まとめ

何かの役に立てばと。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?