How do I call another screen in java, I can not

-4

Follows the code of MainPageClass

package telas;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Window.Type;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaPrincipal extends JFrame {

private JPanel contentPane;

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

/**
 * Create the frame.
 */
public TelaPrincipal() {
    setTitle("Cadastro Geral v 1.0");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    setExtendedState(MAXIMIZED_BOTH);       
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JButton btnCadastrar = new JButton("CADASTRAR");
    btnCadastrar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new TelaCadastro().setVisible(true);
        }

    });
    btnCadastrar.setBounds(91, 135, 89, 23);
    contentPane.add(btnCadastrar);
}
}

Class TelaCadastro

package telas;

import java.awt.EventQueue;

public class TelaCadastro extends JInternalFrame {

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

/**
 * Create the frame.
 */
public TelaCadastro() {
    setBounds(100, 100, 450, 300);

}

}
    
asked by anonymous 17.06.2014 / 02:26

2 answers

2

In your code, the 'ScreenScreen' class is extending from a 'JInternalFrame', in order to use this type of frame you should add it to a JDesktopPane, this is the problem of your code, at first.

I recommend that you take a look at this article to learn how to use it, even if it is in English, it is easy to understand.

link

    
21.06.2014 / 16:53
1

To show the other screen, if you have already created it, you only have to implement a Actionlistener of a button, include the event in the button, within the action event, and you put to call the other window like this:

Classe janela = new classe()
janela.show;
    
13.06.2016 / 00:36