刚才你好象问过这个问题不是采纳了一个人的吗?
我觉得你没有理清自己的程序关系。下边给你一个例子。
----------------------------------------------------------------------------------------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Run {
public static void main(String[] args) {
BFrame b = new BFrame();
AFrame a = new AFrame(b);
CFrame C = new CFrame(b);
}
}
class AFrame extends JFrame implements ActionListener {
BFrame b = null;
public AFrame(BFrame b) {
this.b = b;
setTitle("AFrame");
setSize(298, 120);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(null);
JButton btnNewButton = new JButton("Open B");
btnNewButton.addActionListener(this);
btnNewButton.setBounds(185, 9, 93, 23);
getContentPane().add(btnNewButton);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
b.setVisible(true);
}
}
class BFrame extends JFrame {
public BFrame() {
setTitle("BFrame");
setSize(298, 120);
setDefaultCloseOperation(HIDE_ON_CLOSE);
}
}
class CFrame extends JFrame implements ActionListener {
BFrame b = null;
public CFrame(BFrame b) {
setTitle("CFrame");
this.b = b;
setSize(298, 120);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(null);
JButton btnNewButton = new JButton("Open B");
btnNewButton.addActionListener(this);
btnNewButton.setBounds(185, 9, 93, 23);
getContentPane().add(btnNewButton);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
b.setVisible(true);
}
}
dlwin.setBounds(30, 10, 350, 400);//设置位置和大小
最好能发一部分相对完整的代码。这里很难看得出你是怎么实现的,以至于把内存都干满了
import java.awt.event.*;
import javax.swing.*;
public class TestDialog extends JDialog implements ActionListener
{
private JButton jb1 = new JButton("Show Dialog2");
private JButton jb2 = new JButton("Show Dialog1");
private JDialog jd2 = new JDialog();
TestDialog()
{
initJD1();
initJD2();
}
private void initJD1()
{
setTitle("Dialog1");
getContentPane().setLayout(null);
getContentPane().add(jb1);
jb1.setSize(150, 25);
jb1.addActionListener(this);
setSize(400, 400);
setVisible(true);
}
private void initJD2()
{
jd2.setTitle("Dialog2");
jd2.getContentPane().setLayout(null);
jd2.getContentPane().add(jb2);
jb2.setSize(150, 25);
jb2.addActionListener(this);
jd2.setSize(400, 400);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == jb1)
{
this.setVisible(false);
jd2.setVisible(true);
}
else if(source == jb2)
{
jd2.setVisible(false);
this.setVisible(true);
}
}
public static void main(String[] args)
{
new TestDialog();
}
内存溢出一般是自己调用自己或者死循环导致内存泄露了,所以检查下你的代码吧
特别是B窗口的代码