0

我正在尝试显示一个 JOptionPane 输入对话框,然后显示视图,但我不确定为什么它没有出现,视图弹出但没有输入对话框,我尝试注释掉视图部分并且没有任何反应

这是我的控制器 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();
    }



}

这是第一次调用控制器的主类

package model;

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

1 回答 1

0

该声明

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

位于类的main方法中,Controller而不是queensBasics应用程序的入口点。只需将此语句移至后者

public class QueenBasics {
  public static void main() {
     String intString = JOptionPane.showInputDialog(null, "How many rows/cols?");
     // process/pass in intString to Controller 
     ...
  }
}
于 2013-11-10T20:28:33.040 回答