Пример #1
0
  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 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;
    }
  }
Пример #3
0
 /** Factory method to get the canvas singleton object. */
 public static Canvas getCanvas() {
   if (canvasSingleton == null) {
     canvasSingleton = new Canvas("BlueJ Picture Demo", 500, 300, Color.white);
   }
   canvasSingleton.setVisible(true);
   return canvasSingleton;
 }
Пример #4
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();
  }
Пример #5
0
 /** Factory method to get the canvas singleton object. */
 public static Canvas getCanvas() {
   if (canvasSingleton == null) {
     canvasSingleton = new Canvas(Constants.TITLE, Constants.SIZE, Constants.SIZE, Color.white);
   }
   canvasSingleton.setVisible(true);
   return canvasSingleton;
 }
Пример #6
0
 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);
   }
 }
Пример #7
0
 /** Factory method to get the canvas singleton object. */
 public static Canvas getCanvas() {
   if (canvasSingleton == null) {
     canvasSingleton = new Canvas("BlueJ Shapes Demo", 1400, 600, Color.gray);
   }
   canvasSingleton.setVisible(true);
   return canvasSingleton;
 }
Пример #8
0
  public void destroyWindow() {
    if (parent != null) {
      parent.removeFocusListener(parent_focus_tracker);
      parent_focus_tracker = null;
    }

    nReleaseDC(hwnd, hdc);
    nDestroyWindow(hwnd);
    freeLargeIcon();
    freeSmallIcon();
    resetCursorClipping();
  }
Пример #9
0
  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);
  }
 // 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();
 }
Пример #11
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 + "!!");
    }
  }
Пример #12
0
  public static void main(String[] args) {
    Canvas canvas = new Canvas();

    canvas.setTitle("canvas sample");
    canvas.setSize(600, 200);
    canvas.setLocationRelativeTo(null);
    canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    CanvasData dd = new CanvasData(300);

    NewPanel p = new NewPanel(dd);
    canvas.add(p);

    canvas.setVisible(true);
  }
Пример #13
0
  @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();
  }
Пример #14
0
  public Controller() {
    super("Login");
    System.out.println("Controller for AdMan");

    c = new Canvas();
    c.setSize(10, 5);

    layout1 = new GridBagLayout();
    gbContraints = new GridBagConstraints();
    setLayout(layout1);

    gbContraints.fill = GridBagConstraints.BOTH;
    gbContraints.anchor = GridBagConstraints.NORTH;

    labelUserID = new JLabel("userID[@gmail.com]: ");
    addComponent(labelUserID, 0, 0, 1, 1);

    textFieldUserID = new JTextField(20);
    addComponent(textFieldUserID, 0, 1, 1, 1);

    labelEmpty = new JLabel("             ");
    addComponent(labelEmpty, 1, 0, 1, 1);

    labelPassword = new JLabel("password: "******"             ");
    addComponent(labelEmpty, 3, 0, 1, 1);

    labelEmpty = new JLabel("             ");
    addComponent(labelEmpty, 4, 1, 1, 1);

    buttonOK = new JButton("OK");
    addComponent(buttonOK, 5, 1, 1, 1);

    okButtonHandler = new OKButtonHandler();
    buttonOK.addActionListener(okButtonHandler);
  }
Пример #15
0
 /**
  * Sets the background color.
  *
  * @param backgroundColor the new background color.
  * @see #getBackgroundColor
  */
 public static void setBackgroundColor(Color backgroundColor) {
   if (backgroundColor == null) {
     throw new IllegalArgumentException("backgroundColor must not be null.");
   }
   canvas.setBackground(backgroundColor);
 }
Пример #16
0
 /**
  * Returns the background color.
  *
  * @return the background color.
  * @see #setBackgroundColor
  */
 public static Color getBackgroundColor() {
   return canvas.getBackground();
 }
Пример #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
  public void createWindow(DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y)
      throws LWJGLException {
    close_requested = false;
    is_dirty = false;
    isMinimized = false;
    isFocused = false;
    redoMakeContextCurrent = false;
    maximized = false;
    this.parent = parent;
    hasParent = parent != null;
    parent_hwnd = parent != null ? getHwnd(parent) : 0;
    this.hwnd =
        nCreateWindow(
            x,
            y,
            mode.getWidth(),
            mode.getHeight(),
            Display.isFullscreen() || isUndecorated(),
            parent != null,
            parent_hwnd);
    this.resizable = false;
    if (hwnd == 0) {
      throw new LWJGLException("Failed to create window");
    }
    this.hdc = getDC(hwnd);
    if (hdc == 0) {
      nDestroyWindow(hwnd);
      throw new LWJGLException("Failed to get dc");
    }

    try {
      if (drawable instanceof DrawableGL) {
        int format =
            WindowsPeerInfo.choosePixelFormat(
                getHdc(),
                0,
                0,
                (PixelFormat) drawable.getPixelFormat(),
                null,
                true,
                true,
                false,
                true);
        WindowsPeerInfo.setPixelFormat(getHdc(), format);
      } else {
        peer_info = new WindowsDisplayPeerInfo(true);
        ((DrawableGLES) drawable)
            .initialize(
                hwnd,
                hdc,
                EGL.EGL_WINDOW_BIT,
                (org.lwjgl.opengles.PixelFormat) drawable.getPixelFormat());
      }
      peer_info.initDC(getHwnd(), getHdc());
      showWindow(getHwnd(), SW_SHOWDEFAULT);

      updateWidthAndHeight();

      if (parent == null) {
        if (Display.isResizable()) {
          setResizable(true);
        }
        setForegroundWindow(getHwnd());
      } else {
        parent_focused = new AtomicBoolean(false);
        parent.addFocusListener(
            parent_focus_tracker =
                new FocusAdapter() {
                  public void focusGained(FocusEvent e) {
                    parent_focused.set(true);
                    clearAWTFocus();
                  }
                });
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                clearAWTFocus();
              }
            });
      }
      grabFocus();
    } catch (LWJGLException e) {
      nReleaseDC(hwnd, hdc);
      nDestroyWindow(hwnd);
      throw e;
    }
  }
Пример #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
 private void updateConstants() {
   sim.setTimeStep(t.getValue());
   sim.setGravity(g.getValue());
   sim.setMagnetism(m.getValue());
   sim.setDelay(d.getValue());
 }
Пример #21
0
 /**
  * Wrapper for the canvas' keyPress method
  *
  * @param ke A keyboard event.
  */
 public void keyPressed(KeyEvent ke) {
   canvas.keyPress(ke.getKeyCode());
 }
Пример #22
0
 /**
  * Wrapper for the canvas' keyType method
  *
  * @param ke A keyboard event.
  */
 public void keyTyped(KeyEvent ke) {
   canvas.keyType(ke.getKeyCode());
 }
Пример #23
0
 public void setToNaturalSize(int locationX, int locationY) {
   Canvas canvas = ic.getCanvas();
   int zoomedWidth = canvas.getZoomedWidth();
   int zoomedHeight = canvas.getZoomedHeight();
   setSize(zoomedWidth, zoomedHeight, locationX, locationY);
 }
Пример #24
0
 /**
  * Returns four points representing the corners of the window.
  *
  * @return the corners of the window.
  */
 public static Point[] getCorners() {
   return canvas.getCorners();
 }
Пример #25
0
 static Segment[] getBorders() {
   return canvas.getBorders();
 }
Пример #26
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));
 }
Пример #27
0
 /**
  * Wrapper for the canvas' mouseMoved method
  *
  * @param me A mouse motion event.
  */
 public void mouseMoved(MouseEvent me) {
   canvas.mouseMove(me.getX(), me.getY());
 }
Пример #28
0
 /**
  * Wrapper for the canvas' keyRelease method
  *
  * @param ke A keyboard event.
  */
 public void keyReleased(KeyEvent ke) {
   canvas.keyRelease(ke.getKeyCode());
 }