java - Stretch Canvas to the size of a JFrame -


my task program game 128*128 px. started prepare game java framework , fine: i've got jframe , inside of canvas can draw. can't set sizes correctly. have to work 128*128 px if frame same size way small need scale up.

but if scale size of frame up, canvas small , doesn't fill anymore. if i'd give same size frame wouldn't work 128*128 px anymore. how can draw normal onto small canvas , scale afterwards?

package de.gaminggears.communitygame;  import java.awt.color; import java.awt.graphics; import java.awt.graphics2d; import java.awt.image.bufferstrategy;  import de.gaminggears.communitygame.display.display;  public class game implements runnable{  private display display; public int width, height; public string title;  private boolean running = false; private thread thread;  private bufferstrategy bs; private graphics g;   public game(string title,int width, int height){     this.height = height;     this.width = width;     this.title = title;  }  private void init(){     display = new display(title, width, height); }  private void tick(){  }  private void render(){     bs = display.getcanvas().getbufferstrategy();     if(bs == null){         display.getcanvas().createbufferstrategy(3);         return;     }     g = bs.getdrawgraphics();     graphics2d g2d = (graphics2d) g;     //clear screen     g2d.clearrect(0, 0, width, height);     //draw here!      g2d.setcolor(color.red);     g2d.fillrect(10, 50, 50, 70);     g2d.fillrect(0, 0, 10, 10);      //end drawing      g2d.scale(5, 5);     bs.show();     g.dispose(); }  public void run(){      init();      while(running){         tick();         render();     }     stop(); }   public synchronized void start(){     if(running)         return;     running = true;     thread = new thread(this);     thread.start(); }  public synchronized void stop(){     if(!running)         return;     running = false;     try {         thread.join();     } catch (interruptedexception e) {         e.printstacktrace();     } }  } 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -