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();
}
}
运行截图:
本文介绍了一个简单的Java Swing应用程序,演示了如何使用文本框(JTextField)和标签(JLabel)来创建用户界面。通过示例代码展示了如何设置文本框的默认文本及长度,并将标签与文本框组合显示。
5540

被折叠的 条评论
为什么被折叠?



