public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setSize(1000, 700);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("Collision Effects Test - press any key to start");
    frame.setVisible(true);
    frame.setFocusable(true);
    frame.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent e) {
            start();
          }

          public void keyReleased(KeyEvent e) {}

          public void keyTyped(KeyEvent e) {}
        });
    frame.add(new CollisionEffectsTest());

    Ball ball = new Ball(200, 300, 3);
    ArrayList<Body> bodies = new ArrayList<Body>();
    bodies.add(new Body(500, 300, 150, Color.blue));
    level = new Level(ball, bodies, null, null, null, 5.0, 1.0);
    level.generateLevelData();
  }
Esempio n. 2
0
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   JFrame frame = new JFrame();
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   Animation panel = new Animation();
   frame.getContentPane().add(panel);
   frame.pack();
   frame.setVisible(true);
   frame.setFocusable(false);
   if (!panel.isFocusOwner()) panel.requestFocus();
 }
Esempio n. 3
0
  /**
   * Sets up the event handler mechanics, including invoking the initGUIHandlers method, which would
   * be provided by the game developer using this framework, and would presumably be different for
   * each game.
   */
  private void initHandlers() {
    // SETUP THE LOW-LEVEL HANDLER WHO WILL
    // RELAY EVERYTHING
    MiniGameEventRelayer mger = new MiniGameEventRelayer(this);
    canvas.addMouseListener(mger);
    canvas.addMouseMotionListener(mger);
    window.setFocusable(true);
    window.addKeyListener(mger);
    canvas.addKeyListener(mger);

    // AND NOW LET THE GAME DEVELOPER PROVIDE
    // CUSTOM HANDLERS
    initGUIHandlers();
  }
  public NewRenderMethod() {
    try {
      sSocket = new Socket("localhost", 7214);
      in = new DataInputStream(sSocket.getInputStream());
      PlayerID = in.readInt();
      out = new DataOutputStream(sSocket.getOutputStream());
      Input input = new Input(in, this);
      Thread thread = new Thread(input);
      thread.start();
    } catch (Exception e) {
      e.printStackTrace();
    }

    manager.addMap(map);
    manager.addPlayer(new Player(445, 575));
    manager.PlayerX.add(0);
    manager.PlayerXOffset.add(-220);
    manager.PlayerY.add(0);
    manager.PlayerYOffset.add(-370);
    manager.addPlayer(new Player(445, 575));
    manager.PlayerX.add(0);
    manager.PlayerXOffset.add(-220);
    manager.PlayerY.add(0);
    manager.PlayerYOffset.add(-370);
    manager.addPlayer(new Player(445, 575));
    manager.PlayerX.add(0);
    manager.PlayerXOffset.add(-220);
    manager.PlayerY.add(0);
    manager.PlayerYOffset.add(-370);

    this.addKeyListener(input);
    this.addMouseListener(mouse);
    this.addMouseMotionListener(mouse);

    frame.setPreferredSize(new Dimension(Width, Height));
    frame.setMaximumSize(new Dimension(Width, Height));
    frame.setMinimumSize(new Dimension(Width, Height));
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setFocusable(true);
    frame.setFocusableWindowState(true);
    frame.add(this);

    thread.start();
  }
  private void createFrame() {
    frame = new JFrame(title);
    frame.setSize(dimension);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setFocusable(true);
    frame.setVisible(true);

    canvas = new Canvas();
    canvas.setPreferredSize(dimension);
    canvas.setMaximumSize(dimension);
    canvas.setMinimumSize(dimension);
    canvas.setFocusable(false);

    frame.add(canvas);
    frame.pack();
  }
Esempio n. 6
0
  public void createUI() {
    frame = new JFrame(Messages.getString("OsmExtractionUI.OSMAND_MAP_CREATOR")); // $NON-NLS-1$
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      log.error("Can't set look and feel", e); // $NON-NLS-1$
    }

    frame.addWindowListener(new ExitListener());
    Container content = frame.getContentPane();
    frame.setFocusable(true);

    mapPanel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory());
    mapPanel.setFocusable(true);
    mapPanel.addMapLocationListener(this);

    statusBarLabel = new JLabel();
    content.add(statusBarLabel, BorderLayout.SOUTH);
    File workingDir = DataExtractionSettings.getSettings().getDefaultWorkingDir();
    statusBarLabel.setText(
        workingDir == null
            ? Messages.getString("OsmExtractionUI.WORKING_DIR_UNSPECIFIED")
            : Messages.getString("OsmExtractionUI.WORKING_DIRECTORY")
                + workingDir.getAbsolutePath()); // $NON-NLS-1$ //$NON-NLS-2$

    treePlaces = new JTree();
    treePlaces.setModel(
        new DefaultTreeModel(
            new DefaultMutableTreeNode(Messages.getString("OsmExtractionUI.REGION")),
            false)); //$NON-NLS-1$
    JSplitPane panelForTreeAndMap =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(treePlaces), mapPanel);
    panelForTreeAndMap.setResizeWeight(0.2);
    content.add(panelForTreeAndMap, BorderLayout.CENTER);

    createButtonsBar(content);

    JMenuBar bar = new JMenuBar();
    fillMenuWithActions(bar);

    frame.setJMenuBar(bar);
  }
Esempio n. 7
0
  protected void showView() {
    boolean done = false;

    synchronized (okToProc) {
      if (okToProc.get()) {
        if (frame != null) {
          generateViewImage(viewList.get(viewInx));
          frame.dispose();
        }

        viewInx++;

        ViewIFace view = viewList.get(viewInx);
        System.out.println(view.getName());

        if (!view.getViewSetName().equals("Editor")) // $NON-NLS-1$
        {
          Object data = null;
          try {
            ViewDefIFace viewDef = view.getAltViews().get(0).getViewDef();
            if (!(viewDef.getDataGettable()
                instanceof edu.ku.brc.af.ui.forms.DataGetterForHashMap)) {
              Class<?> dataCls = Class.forName(viewDef.getClassName());
              if (dataCls != null) {
                System.err.println(dataCls);
                data = dataCls.newInstance();
                if (data instanceof FormDataObjIFace) {
                  ((FormDataObjIFace) data).initialize();
                }
              }
            }
          } catch (Exception ex) {
          }

          if (data instanceof Discipline) {
            ((Discipline) data).setType("fish");
          }
          FormPane formPane =
              new FormPane(
                  view.getName(),
                  null,
                  null,
                  view.getName(),
                  "edit",
                  data,
                  MultiView.IS_NEW_OBJECT | MultiView.HIDE_SAVE_BTN,
                  true); //$NON-NLS-1$
          frame = new JFrame();
          frame.setFocusable(false);
          frame.setContentPane(formPane);
          frame.setSize(1024, 768);
          frame.setVisible(true);

          frame.setLocation(0, 0);

          Dimension size = frame.getContentPane().getPreferredSize();
          size.height += 40;
          size.width += 30;
          frame.setSize(size);

          String str = String.format("%d of %d", viewInx + 1, viewList.size());
          System.out.println(str); // $NON-NLS-1$
          getStatusBar().setText(str); // $NON-NLS-1$

        } else if (frame != null) {
          frame.setVisible(false);
          frame.dispose();
          frame = null;
        }

        if (viewInx < viewList.size() - 1) {
          SwingUtilities.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  try {
                    Thread.sleep(500);
                  } catch (Exception ex) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                        .capture(FormDisplayer.class, ex);
                  }
                  showView();
                }
              });
        } else {
          done = true;
        }
      } else {
        done = true;
      }
    }

    if (done) {
      if (cancelDlg != null) cancelDlg.setVisible(false);
      if (frame != null) {
        frame.setVisible(false);
        frame.dispose();
      }

      createIndexFile();

      getStatusBar().setText("Done"); // $NON-NLS-1$
    }
  }
  /**
   * Will start the game up, creates the JFrame and what is inside of it; the grid, the Heads Up
   * Display, the panel, the menu bar and so on.
   */
  public void play() {
    JMenuBar menuBar = new JMenuBar();
    JMenu options = new JMenu("Options");
    JMenu help = new JMenu("Help");

    menuBar.add(options);
    menuBar.add(help);

    JMenuItem game = new JMenuItem("New Game");
    game.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            engine = new Engine();
            JOptionPane.showMessageDialog(f, "NEW GAME!!");
            paint(0);
          }
        });
    JMenuItem save = new JMenuItem("Save");
    save.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            String filename;
            filename = JOptionPane.showInputDialog("NAME OF YOUR SAVE.");
            saveLoad.save(filename, engine);
            JOptionPane.showMessageDialog(f, "GAME SAVED!!");
          }
        });
    JMenuItem load = new JMenuItem("Load");
    load.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            boolean success = false;
            do {
              String filename;
              filename = JOptionPane.showInputDialog("NAME OF WHAT YOU WANT TO LOAD.");
              if (filename == null) {
                success = true;
              } else if (saveLoad.load(filename) == null) {
                JOptionPane.showMessageDialog(f, filename + " NOT FOUND");
              } else {
                JOptionPane.showMessageDialog(f, "GAME LOADED!!");
                engine = saveLoad.load(filename);
                if (engine.isDebugging() == true) {
                  debugPaint(0);
                } else {
                  paint(0);
                }
                success = true;
              }
            } while (!success);
          }
        });

    JMenuItem quit = new JMenuItem("Quit");
    quit.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(f, "GAME HAS QUIT!!");
            System.exit(0);
          }
        });

    JMenuItem about = new JMenuItem("About");
    about.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                f,
                "Development Team:\n\nMario Garcia\nAnuja Joshi\nMichelle Duong\nKristin Adachi\nMatthew Musquiz");
          }
        });

    JMenuItem howtoplay = new JMenuItem("How To Play");
    howtoplay.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                f,
                "Move with the following keys:\nUP_ARROW - move up\nDOWN_ARROW - move down\nLEFT_ARROW - move left\nRIGHT_ARROW - move right"
                    + "\n\nPowerups:\nInvincibility - Invincible for 5 turns\nRadar - Reveal the location of the document\nAmmo Increase - Increase your ammo count by 1"
                    + "\n\nShooting: "
                    + "\nW - shoot up\nS - shoot down\nA - shoot left\nD - shoot right\n\nSearching Tile Spaces:\n\n1 - Look Up\n2 - Look Down\n3 - Look Left \n4 - Look Right"
                    + "\n\nLook for the document hiding in one of these rooms\nWatch for ninjas, they want to rek you.");
          }
        });

    options.add(game);
    options.add(save);
    options.add(load);
    options.add(quit);
    help.add(about);
    help.add(howtoplay);

    f.setJMenuBar(menuBar);
    paint(0);
    f.addKeyListener(this);
    f.setFocusable(true);
    f.setFocusTraversalKeysEnabled(false);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setHUD();
    f.add(HUD, BorderLayout.SOUTH);
    f.add(panel);
    f.pack();
    f.setVisible(true);
    f.setSize(470, 650);
  }