Try this small example and see if you can adapt it in your program:
OtherFrame.java -- Frame you'll be setting the visibility of
Code:import javax.swing.*; import java.awt.*; public class OtherFrame extends JFrame { public OtherFrame() { JButton btnVisible = new JButton("I do Nothing"); JButton btnInvis = new JButton("Neither do I"); Container content = getContentPane(); content.setLayout(new FlowLayout()); content.add(btnVisible); content.add(btnInvis); setSize(200,60); setVisible(true); } }
Test2.java -- The main frame with buttons that set the visibility
Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Test2 extends JFrame implements ActionListener { private OtherFrame otherFrame; private JButton btnVisible = new JButton("Visible"); private JButton btnInvis = new JButton("Invisible"); public Test2() { otherFrame = new OtherFrame(); btnVisible.addActionListener(this); btnInvis.addActionListener(this); Container content = getContentPane(); content.setLayout(new FlowLayout()); content.add(btnVisible); content.add(btnInvis); setSize(200,60); setVisible(true); } public void actionPerformed(ActionEvent ae) { if (ae.getSource() == btnVisible) { otherFrame.setVisible(true); } else if (ae.getSource() == btnInvis) { otherFrame.setVisible(false); } } public static void main(String[] args) { Test2 t = new Test2(); } }




Reply With Quote