0

I have created 2 JFrames and tying to link two JFrames Windows together. But i couldnt get the content in the 2nd Jframe. Can anyone help me with this?

My first Frame:

public class Main extends JFrame {

private JPanel contentPane;
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Main frame = new Main();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JButton btnOpenTheJung = new JButton("Open the JUNG window");
    btnOpenTheJung.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            **JungLearning1 frame1 = new JungLearning1();
            frame1.setVisible(true);
            frame1.setSize(600, 400);**
        }
    });
    btnOpenTheJung.setBounds(172, 99, 145, 34);
    contentPane.add(btnOpenTheJung);
}}

My second Frame:

public class JungLearning1 extends JFrame {

private JPanel contentPane;

/**
 * Launch the application.
 */
public static void main(String[] args) {

    EventQueue.invokeLater(new Runnable() {

        public void run() {
            try {
                DirectedSparseGraph<String, String> g = new DirectedSparseGraph<String, String>();
                g.addVertex("Vertex1");
                g.addVertex("Vertex2");
                g.addVertex("Vertex3");
                g.addEdge("Edge1", "Vertex1", "Vertex2");
                g.addEdge("Edge2", "Vertex1", "Vertex3");
                g.addEdge("Edge3", "Vertex3", "Vertex1");
                VisualizationImageServer<String, String> vs = new VisualizationImageServer<String, String>(
                        new CircleLayout<String, String>(g), new Dimension(
                                200, 200));

                **JFrame frame1 = new JFrame();
                frame1.getContentPane().add(vs);
                frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame1.pack();
                frame1.setVisible(true);**
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });
}

/**
 * Create the frame.
 */
public JungLearning1() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
}}

I want to display the 2nd frame along with the content when clicking the butten from the first window

Steffi Ma
  • 70
  • 9
  • 1
    1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) See [Detection/fix for the hanging close bracket of a code block](http://meta.stackexchange.com/q/251795/155831) for a problem I could no longer be bothered fixing. – Andrew Thompson Aug 13 '15 at 04:50
  • Thank you for the comment sir. But i don't know how to incorporate these 2 frames as one JFrame. – Steffi Ma Aug 13 '15 at 05:21
  • *".. i don't know how to incorporate these 2 frames as one JFrame"* Why do none of the (guessing) half dozen ways described on that page give you some ideas? Please don't expect spoon fed solutions, if you see a technique that might work, try it. If you should fail to implement it as required, get back to us with a [mcve] and we can help further. ... Oh, and please don't call me 'sir' - just 'Andrew' is fine. :) – Andrew Thompson Aug 13 '15 at 05:34

0 Answers0