Swingdialog Error Fatal

Asked

Viewed 35 times

0

I am studying Swing with the Java Programmer’s Guide book, and this code does not validate.

import javax.swing.*;
@SuppressWarnings("serial")
public class Main extends JFrame{

    public Main() {
        super(); //ajusta o titulo
        setBounds(50, 50, 250, 90); //ajusta a posição e tamanho
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //ação fechar
        add(new JLabel("Janela")); //conteúdo

    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Main principal = new Main(); //crai a janela principal
               principal.setVisible(true); //exibe a janela principal
             SwingDialog dialogo = SwingDialog (principal, true); //cria dialogo //AQUI INFORMA UM ERROR FATAL
               dialogo.setVisible(true); //exibe dialogo

            }

        }
    ); } }

1 answer

0


The error occurs because there is no class called SwingDialog in JAVA.

You must use JOptionPane or JDialog.

Try the following:

import javax.swing.*;

@SuppressWarnings("serial")
public class Main extends JFrame{

    public Main(){
        super(); // ajusta o titulo     
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // ação fechar
        add(new JLabel("Janela")); // conteúdo
        setSize(250,90);//tamanho do frame
        setLocationRelativeTo(null);//centraliza frame na tela
    }

    public static void main(String[] args){
        SwingUtilities.invokeLater(new Runnable(){
            @Override
            public void run(){
                Main principal = new Main(); // crai a janela principal
                principal.setVisible(true); // exibe a janela principal
                JDialog dialogo = new JDialog(principal, true); // cria dialogo
                dialogo.setSize(100,50); //tamanho do dialogo
                dialogo.setLocationRelativeTo(null);//centraliza dialogo na tela
                dialogo.setVisible(true); // exibe dialogo
            }
        });
    }
}

Browser other questions tagged

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