SwingDialog Fatal Error

0

I'm studying Swing with the Java Book Developer's Guide, and this code is not valid.

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

            }

        }
    ); } }
    
asked by anonymous 01.11.2014 / 20:43

1 answer

0

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

You should 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
            }
        });
    }
}
    
01.11.2014 / 23:19