下面是我的两个java文件,
一个是继承JFrame,一个集成JPanel
大家看一下,为什么点击change后,显示空白,没有把另一个面板加进来:第一个文件:
import java.awt.BorderLayout;
import java.awt.event.*;import javax.swing.*;public class mainFrame extends JFrame { /**
 * Launch the application
 * @param args
 */
public static void main(String args[]) {
try {
mainFrame frame = new mainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} /**
 * Create the frame
 */
public mainFrame() {
super();
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.CENTER); final JButton changeButton = new JButton();
panel.add(changeButton);
changeButton.setText("change"); changeButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JPanel tj = new testJPanel();
getContentPane().remove(panel);
getContentPane().add(tj);
}

});

//
}}
第二个文件:import javax.swing.*;
import javax.swing.JLabel;public class testJPanel extends javax.swing.JPanel { /**
 * Create the panel
 */
public testJPanel() {
super();

setVisible(true); final JLabel label_1 = new JLabel();
add(label_1);
label_1.setText("testJPanel-newJLabel");
//
}}这是两个文件,如果有错误,请指出,如果可以实现,应该怎么做?