■ swingコンポーネント->JTextField |
|||||
テキストフィールドは文字列の表示と入力することができます。 外観的に枠があり、背景がデフォルトで白になります。 |
|
||||
コンストラクタ(抜粋) | |||||
|
|||||
メソッド(抜粋) | |||||
|
|||||
|
|||||
クリックして下さい。 |
|||||
JTextSample1.java | |||||
import java.awt.*; | |||||
import java.awt.event.*; | |||||
import javax.swing.*; | |||||
public class JTextSample1 extends Frame { | |||||
JLabel lbl1 = new JLabel("名前を入力"); | |||||
JTextField txt1 = new JTextField(); | ← @インスタンス生成 | ||||
public JTextSample1() { | |||||
super(JTextFieldSample1); | |||||
addWindowAdapter(new WindowListener() { | |||||
public void windowClosing(WindowEvent e) { | |||||
System.exit(0); | |||||
} | |||||
}); | |||||
setSize(200,60); | |||||
setLocation(100,100); | |||||
setLayout(new GridLayout(1,2)); | ← Aグリッドレイアウトに配置 | ||||
add(lbl1); | ← Bラベルをレイアウトに配置 | ||||
add(txt1); | ← Bテキストフィールドをレイアウトに配置 | ||||
setVisible(true); | |||||
} | |||||
public static void main(String[] args) { | |||||
JTextSample1 myClass = new JTextSample1(); | |||||
} | |||||
} | |||||
@テキストフィールドのインスタンスを生成 文字列をセットせずにインスタンスを生成しています。 |
|||||
Aレイアウトの設定 ここでは1行2列のGridLayoutでレイアウトを指定しています。 |
|||||
Bラベル とテキストフィールドをそれぞれレイアウトに配置 addメソッドでレイアウトに配置しています。 |
|||||
もどる |