1. 程式人生 > >Java Swing界面編程(18)---單行文本輸入組件:JTextField

Java Swing界面編程(18)---單行文本輸入組件:JTextField

stat rfi import details setbounds add pub lin etl

版權聲明:本文為博主原創文章。未經博主同意不得轉載。 https://blog.csdn.net/xuejiawei123/article/details/27565407

下面的程序與上一例有一點差別,細致對照不難發現當中的不同之處。

package com.beyole.util;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class test17 {
	public static void main(String[] args) {
		JFrame frame = new JFrame("Crystal");
		JTextField nameField = new JTextField(30);
		JTextField location = new JTextField("beyole", 10);
		JLabel name = new JLabel("輸入姓名");
		JLabel locat = new JLabel("所屬單位");
		location.setEnabled(false);
		name.setBounds(10, 10, 100, 20);
		locat.setBounds(10, 40, 100, 20);
		nameField.setBounds(80, 10, 90, 20);
		location.setBounds(80, 40, 50, 20);
		frame.setLayout(null);
		frame.add(locat);
		frame.add(name);
		frame.add(location);
		frame.add(nameField);
		frame.setSize(300, 100);
		frame.setLocation(300, 200);
		frame.setVisible(true);
	}
}

程序截圖:技術分享圖片

Java Swing界面編程(18)---單行文本輸入組件:JTextField