Java 怎么更改控件的????谢谢!!
下面的代码怎么不能成功执行啊???
谢谢!!!!!!!!!
//file:ConctrlTest.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ConctrlTest extends JFrame
{
public static void main(String args[]) {
System.setProperty("swing.plaf.metal.controlFont","宋体");
new ConctrlTest();
}
private Container p = getContentPane();
JButton btn = new JButton("更改控件");
JComponent tt = new JTextField(10);
public ConctrlTest()
{
this.setTitle("控件更改的GUI更新测试");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(300,200,300,200);
p.setLayout(new FlowLayout(FlowLayout.CENTER));
p.add(tt);
p.add(btn);
this.setVisible(true);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tt = new JLabel("成功了,就是这样的");
ConctrlTest.this.repaint();
}
});
}
}
请教高手???怎么解决这个控件更行的问题??