应该加进去了
但不是加在你main函数创建的test里
所以你看不到的import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;public class Test extends JFrame
{
JComboBox cb;
public Test()
{
JButton button=new JButton("open");
cb=new JComboBox();
cb.setBounds(100,100,100,20);
button.setBounds(100,200,100,20);
getContentPane().setLayout(null);
getContentPane().add(cb);
getContentPane().add(button);
cb.addItem("aaaaa");
button.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e)
{
frame fr=new frame();
fr.setBounds(200,200,200,300);
fr.setVisible(true);
}
}
);
}
public static void main(String[] Angie)
{
Test test=new Test();
test.setBounds(300,300,300,400);
test.setVisible(true);
}
}class frame extends JFrame
{
public frame()
{
JButton button =new JButton("add");
getContentPane().add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
Test tt=new Test();
tt.cb.addItem("bbbb");
                                     //tt.setBounds(300,300,300,400);
                                     //tt.show();
                                     //这样显示看看,加进去了没有
}
});
}
}