예제 #1
0
  /*This method runs the actual playing part of the game. It goes in a loop while game is true and constantly paints the game,
  requests the focus, checks for collisions, and checks if anyone won with a small delay. If game is false, it leaves the loop and the game is done.*/
  public void game() // constantly runs update and paint world
      {
    // Loops while game is true
    while (game) {
      // Paints the game
      paintGame();

      // Requests the focus for listening to key events
      window.requestFocus();

      // Checks if any player has collided with anything
      checkCollision();

      // Checks if any player has won
      checkWin();

      // Sleeps for SPEED milliseconds
      try {
        Thread.sleep(SPEED);
      } // delay
      catch (InterruptedException e) {
      }

      // Checks if window closed. If so, game is false
      if (!isVisible()) {
        game = false;
      }
    }

    // Makes the mode 5 so that it still stays on the game screen after game is done
    mode = 5;

    // Paints the game once more
    paintGame();
  }
예제 #2
0
  public static void main(String[] args) {
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "What's Wrong ...");
    changeUI(USE_SYSTEM_UI);

    final NLPCanvas canvas = new NLPCanvas();

    // create the filter pipeline
    EdgeTokenFilter edgeTokenFilter = new EdgeTokenFilter();
    EdgeLabelFilter edgeLabelFilter = new EdgeLabelFilter();
    TokenFilter tokenFilter = new TokenFilter();
    EdgeTypeFilter edgeTypeFilter = new EdgeTypeFilter();
    FilterPipeline filterPipeline =
        new FilterPipeline(tokenFilter, edgeTypeFilter, edgeLabelFilter, edgeTokenFilter);

    // set filter of canvas to be the pipeline
    canvas.setFilter(filterPipeline);

    int canvasWidth = 900;
    int canvasHeight = 300;
    int canvasX = 50;
    int canvasY = 50;
    int canvasBottom = canvasHeight + canvasY;

    final CorpusLoader gold = new CorpusLoader("Select Gold");
    final CorpusLoader guess = new CorpusLoader("Select Guess");
    gold.loadProperties(properties);
    guess.loadProperties(properties);

    // Menu
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenuItem exportEps = new JMenuItem("Export EPS");
    final JFileChooser fc = new JFileChooser();
    exportEps.setAccelerator(KeyStroke.getKeyStroke('E', java.awt.event.InputEvent.ALT_MASK));
    exportEps.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int returnVal = fc.showSaveDialog(canvas);
            if (returnVal == JFileChooser.APPROVE_OPTION)
              try {
                canvas.exportToEPS(fc.getSelectedFile());
              } catch (IOException e1) {
                e1.printStackTrace();
              }
          }
        });
    file.add(exportEps);
    file.setMnemonic('F');

    JMenuItem quit = new JMenuItem("Quit");
    // quit.setMnemonic('Q');
    file.add(quit);
    quit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        });

    JMenu window = new JMenu("Window");

    menuBar.add(file);
    menuBar.add(window);

    // Toolbar
    JToolBar toolBar = new JToolBar("Blub");
    toolBar.add(new JButton("Test"));

    // dummy Frame
    // JFrame dummy = new JFrame();
    // dummy.setVisible(false);

    // canvas frame
    JFrame canvasFrame = new JFrame("What's Wrong With My NLP?");
    canvasFrame.setSize(canvasWidth, canvasHeight);
    canvasFrame.getContentPane().setLayout(new BorderLayout());
    canvasFrame.getContentPane().add(new JScrollPane(canvas), BorderLayout.CENTER);
    canvasFrame.setJMenuBar(menuBar);
    // canvasFrame.getContentPane().add(toolBar, BorderLayout.NORTH);
    canvasFrame.setLocation(canvasX, canvasY);
    canvasFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    // window.add(new WindowMenuItem(canvasFrame,"Canvas"));
    // desktop.add(canvasFrame);

    // file selection frame
    final ControllerDialog fileWindow = new ControllerDialog("File Selection", USE_SYSTEM_UI);
    fileWindow
        .getContentPane()
        .setLayout(new BoxLayout(fileWindow.getContentPane(), BoxLayout.Y_AXIS));
    fileWindow.getContentPane().add(gold);
    fileWindow.getContentPane().add(new JSeparator());
    fileWindow.getContentPane().add(guess);
    fileWindow.setLocation(canvasX + 20, canvasBottom + 20);
    fileWindow.pack();
    fileWindow.setVisible(USE_SYSTEM_UI);
    // fileWindow.toBack();
    window.add(new WindowMenuItem(fileWindow));
    // fileFrame.setResizable(false);
    // desktop.add(fileFrame);

    // filter frame
    ControllerDialog filterWindow = new ControllerDialog("Edge Filters", false);
    filterWindow
        .getContentPane()
        .setLayout(new BoxLayout(filterWindow.getContentPane(), BoxLayout.Y_AXIS));
    filterWindow.getContentPane().add(new EdgeTypeFilterPanel(canvas, edgeTypeFilter));
    filterWindow.getContentPane().add(new JSeparator());
    filterWindow
        .getContentPane()
        .add(new DependencyFilterPanel(canvas, edgeLabelFilter, edgeTokenFilter));
    filterWindow.pack();
    filterWindow.setLocation(canvasX + 250, canvasBottom + 15);
    filterWindow.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(filterWindow));

    // token filter frame
    ControllerDialog tokenFilterWindow = new ControllerDialog("Token Filters", false);
    tokenFilterWindow
        .getContentPane()
        .setLayout(new BoxLayout(tokenFilterWindow.getContentPane(), BoxLayout.Y_AXIS));
    tokenFilterWindow.getContentPane().add(new TokenFilterPanel(canvas, tokenFilter));
    tokenFilterWindow.pack();
    tokenFilterWindow.setLocation(canvasX + 360, canvasBottom + 230);
    tokenFilterWindow.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(tokenFilterWindow));

    // appearance
    ControllerDialog appearance = new ControllerDialog("Appearance", false);
    appearance
        .getContentPane()
        .setLayout(new BoxLayout(appearance.getContentPane(), BoxLayout.Y_AXIS));
    appearance.getContentPane().add(new AppearancePanel(canvas));
    appearance.pack();
    appearance.setLocation(canvasX + 500, canvasBottom + 25);
    appearance.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(appearance));

    // description
    ControllerDialog description = new ControllerDialog("Description", true);
    // description.getContentPane().setLayout(new BoxLayout(appearance.getContentPane(),
    // BoxLayout.Y_AXIS));
    JTextArea text = new JTextArea(15, 40);
    description.getContentPane().add(new JScrollPane(text));
    description.pack();
    description.setLocation(canvasX + 700, canvasBottom + 25);
    description.setVisible(USE_SYSTEM_UI);
    canvas.setTextArea(text);
    window.add(new WindowMenuItem(description));

    // navigator
    ControllerDialog navigatorWindow = new ControllerDialog("Search Corpus", USE_SYSTEM_UI);
    navigatorWindow
        .getContentPane()
        .setLayout(new BoxLayout(navigatorWindow.getContentPane(), BoxLayout.Y_AXIS));
    CorpusNavigator navigator = new CorpusNavigator(canvas, gold, guess, edgeTypeFilter);
    navigatorWindow.getContentPane().add(navigator);
    navigatorWindow.pack();
    navigatorWindow.setMinimumSize(navigatorWindow.getSize());
    navigatorWindow.setLocation(canvasX + 800, canvasBottom + 20);
    navigatorWindow.setVisible(USE_SYSTEM_UI);
    window.add(new WindowMenuItem(navigatorWindow, "Navigator"));

    // statusbar
    JPanel statusBar = new JPanel();
    JLabel status = new JLabel("What's Wrong With My NLP version " + VERSION);
    status.setForeground(Color.LIGHT_GRAY);
    statusBar.setLayout(new GridBagLayout());
    statusBar.setBorder(BorderFactory.createEmptyBorder(1, 10, 1, 10));
    statusBar.add(status);
    statusBar.add(navigator.getSpinnerPanel(), new SimpleGridBagConstraints(0, USE_SYSTEM_UI));
    statusBar.add(
        navigator.getSpinnerPanel(), new SimpleGridBagConstraints(1, 0, 1.0, 0.0, EAST, NONE));

    // final preparation of canvas
    canvasFrame.getContentPane().add(statusBar, BorderLayout.SOUTH);
    canvasFrame.setVisible(USE_SYSTEM_UI);
    canvasFrame.requestFocus();
    // canvasFrame.requestFocusInWindow();

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                new Runnable() {
                  public void run() {
                    gold.saveProperties(properties);
                    guess.saveProperties(properties);
                    try {
                      properties.store(
                          new FileOutputStream(System.getProperty("user.home") + "/.whatswrong"),
                          "Whats wrong with you NLP properties");
                    } catch (IOException e) {
                      e.printStackTrace();
                    }
                  }
                }));
  }