为什么这个JOptionPane不会出现?

时间:2013-11-10 20:26:49

标签: java swing function user-interface methods

我正在尝试显示一个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();
    }
}

1 个答案:

答案 0 :(得分: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 
     ...
  }
}