简体   繁体   English

为什么没有显示此JOptionPane?

[英]Why isn't this JOptionPane showing up?

I'm trying to show a JOptionPane input dialog and then have the view come up after but I am not sure why it is not appearing, the view pops up but not the input dialog, I try commenting out the view part and nothing happens 我试图显示一个JOptionPane输入对话框,然后显示视图,但是我不确定为什么它不出现,视图弹出但没有输入对话框,我尝试注释掉视图部分,但没有任何反应

Here is my controller where the JOptionPane input dialog is 这是我的控制器的JOptionPane输入对话框所在的位置

package model;

import java.util.*;
import javax.swing.*;




public class Controller {
    private View myView;
    private NQueensModel myModel;
    private static int int1, possibilities;
    private static String intString;

    public static void main(String[] args)
    {
        intString = JOptionPane.showInputDialog(null, "How many rows/cols?");
        int1 = Integer.parseInt(intString);
    }

    public Controller()
    {
        myView = new View(this);

    }
    public void solve()
    {

        myView.doViewGrid();
        myModel = new NQueensModel(int1);
        myModel.solvePuzzle();
        possibilities = myModel.getPossibilities();
        myView.addButtons();
        myView.setPossibilitiesLabel(possibilities);
        myView.revalidate();
        myView.repaint();




    }

    public boolean[][] getMyBoard()
    {
        return myModel.getBoard();
    }



}

here is the main class where the controller is first called 这是第一次调用控制器的主要类

package model;

public class queensBasics
{
    public static void main(String[] args)
    {
        Controller myController = new Controller();
    }
}

The statement 该声明

intString = JOptionPane.showInputDialog(null, "How many rows/cols?");

is located in the main method of the Controller class rather that in queensBasics which is the application's entry point. 位于Controller类的main方法中,而不是应用程序的切入点queensBasics中。 Simply move this statement to the latter 只需将此语句移到后者

public class QueenBasics {
  public static void main() {
     String intString = JOptionPane.showInputDialog(null, "How many rows/cols?");
     // process/pass in intString to Controller 
     ...
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM