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で「テキストフィールドで入力されたテキストのフォントを設定する」の動作を確認してみました。
以下のページを参考にしました。

実装

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

JSample4_1.java
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPanel;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Font;

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

  JSample4_1(String title){
    setTitle(title);
    setBounds(100, 100, 600, 400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField text1 = new JTextField("Tokyo", 10);
    JTextField text2 = new JTextField("Osaka", 10);
    text2.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 20));
    JTextField text3 = new JTextField("Kyoto", 10);
    text3.setFont(new Font("Century", Font.ITALIC, 30));

    JPanel p = new JPanel();
    p.add(text1);
    p.add(text2);
    p.add(text3);

    Container contentPane = getContentPane();
    contentPane.add(p, BorderLayout.CENTER);
  }
}

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

$ javac JSample4_1.java 
$ java JSample4_1

実行結果は以下の通りでした。

Screenshot from 2025-01-21 08-08-04.png

まとめ

何かの役に立てばと。

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?