コード例 #1
0
ファイル: GUIImpl.java プロジェクト: rockerdiaz/halfnes
  public synchronized void setRenderOptions() {
    if (canvas != null) {
      this.remove(canvas);
    }
    screenScaleFactor = PrefsSingleton.get().getInt("screenScaling", 2);
    smoothScale = PrefsSingleton.get().getBoolean("smoothScaling", false);
    if (PrefsSingleton.get().getBoolean("TVEmulation", false)) {
      renderer = new NTSCRenderer();
      NES_WIDTH = 302;
    } else {
      renderer = new RGBRenderer();
      NES_WIDTH = 256;
    }
    if (PrefsSingleton.get().getInt("region", 0) > 1) {
      NES_HEIGHT = 240;
      renderer.setClip(0);
    } else {
      NES_HEIGHT = 224;
      renderer.setClip(8);
    }

    // Create canvas for painting
    canvas = new Canvas();
    canvas.setSize(NES_WIDTH * screenScaleFactor, NES_HEIGHT * screenScaleFactor);
    canvas.setEnabled(false); // otherwise it steals input events.
    // Add canvas to game window
    this.add(canvas);
    this.pack();
    canvas.createBufferStrategy(2);
    buffer = canvas.getBufferStrategy();
  }
コード例 #2
0
 public BotMouseListener(Bot bot) {
   this.mouseEnabled = true;
   this.canvas = bot.getCanvas();
   this.defaultMouseListeners = canvas.getMouseListeners();
   this.defaultMouseMotionListeners = canvas.getMouseMotionListeners();
   this.defaultMouseWheelListeners = canvas.getMouseWheelListeners();
   this.mousePoint = new Point(-1, -1);
   addBotListeners();
 }
コード例 #3
0
ファイル: Outline.java プロジェクト: ShifuCifuentes/ridixcr
  /**
   * Called to change the visibility of the outline.
   *
   * @param value true if visible.
   */
  public void setVisible(final boolean value) {
    if (value != isVisible()) {
      super.setVisible(value);

      Container parent = getParent();

      if ((parent != null) && (parent.getComponentCount() == 1)) {
        parent.setVisible(value);
      }

      invalidate();

      try {
        for (; parent != null; parent = parent.getParent()) {
          try {
            parent.getClass().getMethod("resetToPreferredSizes", null).invoke(parent, null);
            visibleArgs[0] = new Integer(value ? 10 : 0);
            parent.getClass().getMethod("setDividerSize", visibleParms).invoke(parent, visibleArgs);

            break;
          } catch (final Throwable ignored) {
          }
        }
      } catch (final Throwable ignored) {
      }

      djvuBean.recursiveRevalidate();
    }
  }
コード例 #4
0
ファイル: Gui2.java プロジェクト: Emilyxu828/APCS-Homework
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == b1) {
     System.out.println("You Clicked Click me");
     System.out.println("And the textarea has: " + text.getText());
     x = x + 10;
     y = y + 10;
     canvas.update(canvas.getGraphics());
   } else if (e.getSource() == labeler) {
     label.setText(text.getText());
     // pane.add(new JLabel(text.getText()));
     text.setText("");
   } else if (e.getSource() == b2) {
     System.out.println("Shutting down");
     System.exit(0);
   }
 }
コード例 #5
0
  public void addClient() {
    client =
        new Canvas() {
          public void paint(Graphics g) {
            super.paint(g);
          }
        };
    client.setBackground(new Color(30, 220, 40));
    clientCont.add(client);
    clientCont.validate();
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    WindowIDProvider pid = (WindowIDProvider) acc.getPeer(client);
    log.fine("Added XEmbed server(Canvas) with X window ID " + pid.getWindow());
    Rectangle toFocusBounds = toFocus.getBounds();
    toFocusBounds.setLocation(toFocus.getLocationOnScreen());
    f.validate();

    // KDE doesn't accept clicks on title as activation - click below title
    Rectangle fbounds = f.getBounds();
    fbounds.y += f.getInsets().top;
    fbounds.height -= f.getInsets().top;

    Process proc =
        startClient(
            new Rectangle[] {
              fbounds,
              dummy.getBounds(),
              toFocusBounds,
              new Rectangle(b_modal.getLocationOnScreen(), b_modal.getSize()),
              new Rectangle(10, 130, 20, 20)
            },
            pid.getWindow());
    new ClientWatcher(client, proc, clientCont).start();
  }
コード例 #6
0
ファイル: GUIImpl.java プロジェクト: rockerdiaz/halfnes
  public synchronized void toggleFullScreen() {
    if (inFullScreen) {
      this.dispose();
      gd.setFullScreenWindow(null);
      canvas.setSize(NES_HEIGHT * screenScaleFactor, NES_WIDTH * screenScaleFactor);
      this.setUndecorated(false);
      this.setVisible(true);
      inFullScreen = false;
      buildMenus();
      // nes.resume();
    } else {
      setJMenuBar(null);
      gd = getGraphicsConfiguration().getDevice();
      if (!gd.isFullScreenSupported()) {
        // then fullscreen will give a window the size of the screen instead
        messageBox("Fullscreen is not supported by your OS or version of Java.");
      }
      this.dispose();
      this.setUndecorated(true);

      gd.setFullScreenWindow(this);
      this.setVisible(true);

      inFullScreen = true;
    }
  }
コード例 #7
0
ファイル: Gui2.java プロジェクト: Emilyxu828/APCS-Homework
  public Gui2() {

    setTitle("My First Gui");
    setSize(600, 600);
    setLocation(100, 100);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    pane = getContentPane();
    // pane.setLayout(new GridLayout(3,3));
    pane.setLayout(new FlowLayout());
    b1 = new JButton("Click me");
    b1.addActionListener(this);
    pane.add(b1);

    b2 = new JButton("exit");
    b2.addActionListener(this);
    pane.add(b2);

    labeler = new JButton("Labeler");
    labeler.addActionListener(this);
    pane.add(labeler);

    label = new JLabel("The Label:");
    pane.add(label);

    box = new JCheckBox("Cap");
    pane.add(box);
    text = new JTextArea();
    text.setColumns(40);
    text.setRows(5);
    text.setBorder(BorderFactory.createLineBorder(Color.red, 2));
    text.addKeyListener(new Key());
    pane.add(text);

    canvas = new Canvas();
    canvas.setPreferredSize(new Dimension(300, 300));
    canvas.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
    pane.add(canvas);
  }
コード例 #8
0
 // Konstruktordefinition
 public InnereKlassemitmainMethode() {
   super("Programmaufruf über eine innere Klasse");
   setBounds(10, 10, 250, 150);
   getContentPane().setLayout(new BorderLayout());
   malflaeche = new Canvas();
   malflaeche.setBackground(Color.pink);
   malflaeche.setSize(100, 100);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   malflaeche.addMouseMotionListener(this);
   status = new JLabel(" ");
   getContentPane().add(status, BorderLayout.SOUTH);
   // Eine lokale Referenz vom Typ des Interface Action zeigt auf
   // ein Objekt vom Typ der inneren Klasse SelectColorAction
   Action select = new SelectColorAction();
   // Zu einer JToolBar-Komponente wird eine JButton-Komponente,
   // welche die vorher definierte Aktion ausführt, hinzugefügt
   JToolBar toolbar = new JToolBar("Farbe wählen");
   JButton b = toolbar.add(select);
   getContentPane().add(toolbar, BorderLayout.WEST);
   getContentPane().add(malflaeche, BorderLayout.EAST);
   setVisible(true);
   // Den Graphikkontext des Canvas ermitteln
   g = malflaeche.getGraphics();
 }
コード例 #9
0
  /** Iterate the physics, call repaint(). */
  public void run() {
    while (true) {
      repaint();
      try {
        canvas.changeSize(getHeight(), getWidth());
        simthread.sleep(10);
        canvasthread.run();
        canvasthread.join();

        // this.iters++;
      } catch (Exception ie) {
        System.out.println(ie.getMessage() + "!!!");
      }
      // System.out.println(iters + "!!");
    }
  }
コード例 #10
0
 public void addBotListeners() {
   for (MouseListener l : defaultMouseListeners) {
     canvas.removeMouseListener(l);
   }
   for (MouseMotionListener l : defaultMouseMotionListeners) {
     canvas.removeMouseMotionListener(l);
   }
   for (MouseWheelListener l : defaultMouseWheelListeners) {
     canvas.removeMouseWheelListener(l);
   }
   canvas.addMouseListener(this);
   canvas.addMouseMotionListener(this);
   canvas.addMouseWheelListener(this);
 }
コード例 #11
0
ファイル: GUIImpl.java プロジェクト: rockerdiaz/halfnes
  @Override
  public final synchronized void render() {
    final Graphics graphics = buffer.getDrawGraphics();
    if (smoothScale) {
      ((Graphics2D) graphics)
          .setRenderingHint(
              RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    }
    if (inFullScreen) {
      graphics.setColor(Color.BLACK);
      DisplayMode dm = gd.getDisplayMode();
      int scrnheight = dm.getHeight();
      int scrnwidth = dm.getWidth();
      // don't ask why this needs to be done every frame,
      // but it does b/c the canvas keeps resizing itself
      canvas.setSize(scrnwidth, scrnheight);
      graphics.fillRect(0, 0, scrnwidth, scrnheight);
      if (PrefsSingleton.get().getBoolean("maintainAspect", true)) {
        double scalefactor = getmaxscale(scrnwidth, scrnheight);
        int height = (int) (NES_HEIGHT * scalefactor);
        int width = (int) (256 * scalefactor * 1.1666667);
        graphics.drawImage(
            frame,
            ((scrnwidth / 2) - (width / 2)),
            ((scrnheight / 2) - (height / 2)),
            width,
            height,
            null);
      } else {
        graphics.drawImage(frame, 0, 0, scrnwidth, scrnheight, null);
      }
      graphics.setColor(Color.DARK_GRAY);
      graphics.drawString(this.getTitle(), 16, 16);

    } else {
      graphics.drawImage(
          frame, 0, 0, NES_WIDTH * screenScaleFactor, NES_HEIGHT * screenScaleFactor, null);
    }

    graphics.dispose();
    buffer.show();
  }
コード例 #12
0
 /**
  * Wrapper for the canvas' mouseMoved method
  *
  * @param me A mouse motion event.
  */
 public void mouseMoved(MouseEvent me) {
   canvas.mouseMove(me.getX(), me.getY());
 }
コード例 #13
0
 /**
  * Wrapper for the canvas' keyPress method
  *
  * @param ke A keyboard event.
  */
 public void keyPressed(KeyEvent ke) {
   canvas.keyPress(ke.getKeyCode());
 }
コード例 #14
0
 /**
  * Wrapper for the canvas' keyRelease method
  *
  * @param ke A keyboard event.
  */
 public void keyReleased(KeyEvent ke) {
   canvas.keyRelease(ke.getKeyCode());
 }
コード例 #15
0
 public void removeNotify() {
   controller.removeListener(this);
   super.removeNotify();
 }
コード例 #16
0
 /**
  * Wrapper for the canvas' keyType method
  *
  * @param ke A keyboard event.
  */
 public void keyTyped(KeyEvent ke) {
   canvas.keyType(ke.getKeyCode());
 }
コード例 #17
0
 /**
  * Paint the drawing surface on the applet.
  *
  * @param g A graphics object
  */
 public void paint(Graphics g) {
   buffG.clearRect(0, 0, getWidth(), getHeight());
   canvas.paint(buffG);
   g.drawImage(buff, 0, 0, this);
 }
コード例 #18
0
ファイル: BottomBar.java プロジェクト: wavebeem/sim
 private void updateConstants() {
   sim.setTimeStep(t.getValue());
   sim.setGravity(g.getValue());
   sim.setMagnetism(m.getValue());
   sim.setDelay(d.getValue());
 }
コード例 #19
0
 /**
  * Wrapper for the canvas' mouseRelease method
  *
  * @param me A mouse event.
  */
 public void mouseReleased(MouseEvent me) {
   canvas.mouseRelease(me.getX(), me.getY(), (me.getButton() == me.BUTTON3));
 }
コード例 #20
0
 /**
  * Wrapper for the canvas' mouseDragged method
  *
  * @param me A mouse motion event.
  */
 public void mouseDragged(MouseEvent me) {
   canvas.mouseDrag(me.getX(), me.getY(), (me.getButton() == me.BUTTON3));
 }