连接2个Jframe与JUNG

时间:2015-08-13 04:36:21

标签: java swing jframe jung jung2

我创建了2个JFrame并将两个JFrames链接在一起。但我无法获得第二个Jframe中的内容。任何人都可以帮我这个吗?

我的第一帧:

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);
}}

我的第二帧:

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);
}}

我想在第一个窗口点击按钮时显示第二帧和内容

0 个答案:

没有答案