Results 1 to 2 of 2
  1. #1
    tnt417 is offline Member
    Join Date
    Sep 2015
    Posts
    21
    Rep Power
    0

    Question Java 2d graphics rendering method

    this is my code but it doesn't work:
    Java Code:
    private void render() {
    		BufferStrategy bs = this.getBufferStrategy();
    		if(bs == null){
    			this.createBufferStrategy(3);
    			return;
    		}
    		Graphics g = bs.getDrawGraphics();
    		
    			g.fillRect(0, 0, 720, 480);
    		
    		g.dispose();
    		bs.show();
    	
    	}

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Java 2d graphics rendering method

    When asking for help, code snippets are not very useful. Check out the tutorial in my signature on how to do graphics. Here are the basics.

    1. Create a class of some name (YourClass) and extend JPanel
    2. Add an instance of YourClass to an instance of JFrame
    3. In YourClass, override paintComponent
    and place your fillRect code in that method.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. help with Graphics method
    By The original stinger in forum Java Applets
    Replies: 4
    Last Post: 05-21-2012, 09:29 PM
  2. Rendering graphics on JPanel
    By wired-in=p in forum New To Java
    Replies: 4
    Last Post: 10-06-2011, 06:08 AM
  3. Replies: 0
    Last Post: 09-12-2011, 01:06 PM
  4. Putting graphics into the run() method.
    By theCardboardBox in forum New To Java
    Replies: 11
    Last Post: 11-17-2010, 06:33 PM
  5. java graphics within main method
    By jforce93 in forum New To Java
    Replies: 4
    Last Post: 02-02-2010, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •