java程序:为什么点击“OK”按钮没有反应阿,各位大侠帮帮小妹阿!

点击“OK”按钮,希望在frame中出现label"The 'OK' button clicked",该怎么做阿,急啊!
package programmingExercises;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Exercise14_3last extends JFrame{
public Exercise14_3last(){

this.setLayout(new BorderLayout());

JLabel label=new JLabel("THE RESULT WILL BE PLAYED HERE");
this.add(label, BorderLayout.NORTH);

JPanel panel=new JPanel();
JButton jbtok=new JButton("OK");
JButton jbtcancel =new JButton("Cancel");
panel.add(jbtok);
panel.add(jbtcancel);
this.add(panel,BorderLayout.SOUTH);

jbtok.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {
add(new JLabel("The 'OK' button clicked"),BorderLayout.CENTER);
}
} );

}

public static void main(String[] args){
Exercise14_3last frame = new Exercise14_3last();
frame.setSize(300,200);
frame.setTitle("Exercise 14_3");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

}

在add(new JLabel("The 'OK' button clicked"),BorderLayout.CENTER);
后面添加两行:
Exercise14_3last.this.invalidate();
Exercise14_3last.this.validate();重新布局一下就好了

或者:
Exercise14_3last.repaint();
Exercise14_3last .this.show();两种方法都能解决问题
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-12-09
你用鼠标改变下外框大小 他就能显示了

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网