JOptionPane: parentComponent 没有有效的父组件

JOptionPane: parentComponent does not have a valid parent

我正在为我的数据库使用 Java eclipse,但最终我遇到了这样的错误: JOptionPane: parentComponent does not have a valid parent 我不知道是什么问题,请有人解释一下,因为我才 2 年级IT 学生和我想了解更多 Java 我想完成我的目标。

import java.awt.EventQueue;
import java.lang.*;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.*;

import javax.swing.*;

public class Login {

  Connection connection = null;

  private JFrame frame;
  private JTextField username;
  private JPasswordField password;

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

  /**
   * Create the application.
   */

  public Login() {
    initialize();
    connection = Database.dbconector();

  }

  /**
   * Initialize the contents of the frame.
   */
  private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    username = new JTextField();
    username.setBounds(127, 55, 200, 50);
    frame.getContentPane().add(username);
    username.setColumns(10);

    password = new JPasswordField();
    password.setBounds(127, 125, 200, 50);
    frame.getContentPane().add(password);

    JButton btnLogin = new JButton("Log in");
    btnLogin.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {


        try {
          String query = "select * from bsit-db where Username=? and Password=?";
          PreparedStatement pst = connection.prepareStatement(query);
          pst.setString(1, username.getText());
          pst.setString(2, password.getText());


          ResultSet rs = pst.executeQuery();
          int count = 0;
          while (rs.next()) {
            count = count + 1;
          }
          if (count == 1) {
            JOptionPane.showInternalInputDialog(null, "Successfully Login to your account!");



          } else {
            JOptionPane.showInternalInputDialog(null, "Incorrect ID/Password. Please Try Again!");
          }
          rs.close();
          pst.close();

        } catch (Exception e1) {
          JOptionPane.showInternalInputDialog(null, e1);

        } finally {
          try {

          } catch (Exception e1) {
            JOptionPane.showInternalInputDialog(null, e1);
          }
        }


      }
    });
    btnLogin.setBounds(103, 202, 112, 37);
    frame.getContentPane().add(btnLogin);

    JButton btnClear = new JButton("clear");
    btnClear.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {

        username.setText(null);
        password.setText(null);
      }
    });
    btnClear.setBounds(237, 202, 112, 37);
    frame.getContentPane().add(btnClear);

    JLabel lblUsername = new JLabel("username");
    lblUsername.setBounds(66, 55, 200, 50);
    frame.getContentPane().add(lblUsername);

    JLabel lblPassword = new JLabel("password");
    lblPassword.setBounds(66, 125, 200, 50);
    frame.getContentPane().add(lblPassword);
  }
}

这是控制台错误

Sun Aug 06 20: 54: 43 CST 2017 WARN: Establishing SSL connection without server 's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn' t set.For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.You need either to explicitly disable SSL by setting useSSL = false, or set useSSL = true and provide truststore for server certificate verification. java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent at javax.swing.JOptionPane.createInternalFrame(Unknown Source) at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source) at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source) at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source) at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source) at Database.dbconector(Database.java: 19) at Login. < init > (Login.java: 44) at Login.run(Login.java: 29) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access0(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

showInternalInputDialog is for option panes meant to appear in a JDesktopPane. Look instead to showInputDialog.

看到这个问题: