Calling a jFrame of another class in a click event in java [duplicate]

0

I have a JFrame with two buttons, and a second class that has a JFrame with other features ... I wanted to make the second window open by clicking one of the buttons in the first window, but I can not make the call inside of the first class click event. Any suggestions?

// opening window

    public class JanelaPrincipal {  

    public static void main (String[] args){    
      JFrame frame = new JFrame("Test");
      frame.setVisible(true);
      frame.setSize(500,500);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      JPanel panel = new JPanel();
      frame.add(panel);
      JButton montar = new JButton("Montar Grade");
      panel.add(montar);
      montar.addActionListener((ActionListener) new Action1());

      JButton analisar = new JButton("Analisar");
      panel.add(analisar);
      analisar.addActionListener (new Action2()); 
    }

    static class Action1 implements ActionListener {        
      public void actionPerformed (ActionEvent e) {
          //abrir primeira janela aqui
      }
    }   

    static class Action2 implements ActionListener {        
      public void actionPerformed (ActionEvent e) {     
        //abrir segunda janela aqui
      }
    }   

}

// window to open with click     public class Window extends Thread {

    private JFrame frame;
    private JTextField textField;

    private DefaultComboBoxModel<Grafo.Vertice> origem = new DefaultComboBoxModel<>();
    private DefaultComboBoxModel<Grafo.Vertice> destino = new DefaultComboBoxModel<>();
    private DefaultComboBoxModel<Grafo.Vertice> vertice = new DefaultComboBoxModel<>();
    private DefaultComboBoxModel<Grafo.Vertice> vertice2 = new DefaultComboBoxModel<>();



    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Janela window = new Janela();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public Janela() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */

     Grafo g = new Grafo();
     Grafo.Vertice s = g.addVertice("Arq e org computadores");
     Grafo.Vertice t = g.addVertice("Sistemas lógicos e digitais");
     Grafo.Vertice y = g.addVertice("Matemática Discreta");
     Grafo.Aresta st = g.addAresta(s, t);
     Grafo.Aresta sy = g.addAresta(s, y);
     Grafo.Aresta ty = g.addAresta(t, y);
     private JTextField tfAlt;


    protected void initialize() {
        frame = new JFrame();

        origem.addElement(s);
        destino.addElement(s);
        vertice.addElement(s);
        vertice2.addElement(s);

        origem.addElement(t);
        destino.addElement(t);
        vertice.addElement(t);
        vertice2.addElement(t);

        origem.addElement(y);
        destino.addElement(y);
        vertice.addElement(y);
        vertice2.addElement(y);

.......
    
asked by anonymous 06.06.2018 / 17:06

0 answers