Beispiel #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();
  }
Beispiel #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;
    }
  }
Beispiel #3
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);
  }
Beispiel #4
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();
  }
Beispiel #5
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);
  }
 // 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();
 }