这是一个如何从另一个本身就是Jframe的类中释放Jframe的示例:
import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.Jframe;import javax.swing.SwingUtilities;public class Demo{ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { frameA one = new frameA(); frameB two = new frameB(one); one.setVisible(true); two.setVisible(true); } }); }}class frameA extends Jframe{ private static final long serialVersionUID = 1812279930292019387L; public frameA() { super("frame A"); setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); setSize(400, 400); setLocationRelativeTo(null); setResizable(false); }}class frameB extends Jframe{ private static final long serialVersionUID = 5126089271972476434L; public frameB(final Jframe otherframe) { super("frame B"); setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); setSize(400, 400); setLayout(new GridBagLayout()); setLocationRelativeTo(otherframe); JButton button = new JButton("Dispose Other"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { otherframe.dispose(); } }); add(button); setResizable(false); }}


