java文本域
package JAVASwing;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class TestingJTextfILE {
public static void main(String[] args) {
new TestingFile();
}
}
class TestingFile extends JFrame
{
public TestingFile()
{
this.setVisible(true);
this.setSize(600,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=this.getContentPane();
c.setLayout(new FlowLayout());
final JTextField text=new JTextField("这是一个文本框",20);
JButton button=new JButton("清空文本");
text.setSize(30, 30);
c.add(text);
c.add(button);
button.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
text.setText("已完成清空处理!");
}
});
}
}
©著作权归作者所有:来自51CTO博客作者chaiyesongtest的原创作品,如需转载,请注明出处,否则将追究法律责任