GUI组件——文本框和标签 TextField &Label
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package x_06;
import java.awt.*;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class TextField extends JFrame{
/**
* @param args the command line arguments
*/
public TextField (){
super("编辑文本框和标签 Textfield and JLabel");
setSize(500,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
FlowLayout flo =new FlowLayout();
setLayout(flo);
JLabel pageLabel=new JLabel("Web page address:",JLabel.LEFT);//Q:文本左右对齐不行??
JTextField pageAdress=new JTextField("http:\\\\",29);//设置文本框长度为20个字符
//String country=pageAdress.getText();
//country.setText("US");//setFext方法无效??
add(pageAdress);
add(pageLabel);
}
public static void main(String[] args) {
// TODO code application logic here
TextField sal=new TextField();
}
}
运行截图: