How do I call another screen in java, I’m not getting

Asked

Viewed 5,634 times

-4

Follows code of the Telaprincipal class

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

Telacadastro class

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

}

}
  • Even so is not calling the registration screen.

  • An error occurs?

  • No, just the other screen doesn’t appear

2 answers

2

In your code the class 'Telacadastro' is extending from a 'Jinternalframe', in order to use this type of frame you must add it in a Jdesktoppane, this is the problem of your code, at first.

I recommend taking a look at this article to learn how to use, even though being in English is easy to understand.

http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html

1

To show the other screen, if you have already created it, just implement a Actionlistener one button, include the event in the button, inside the event action and, you put to call the other window so:

Classe janela = new classe()
janela.show;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.