[nbusers] Re: Using g.DrawRect and paint functions in Netbeans

  • From: trhouse < >
  • To:
  • Subject: [nbusers] Re: Using g.DrawRect and paint functions in Netbeans
  • Date: Fri, 26 Oct 2012 18:28:42 -0700

On 10/26/2012 10:35 AM, nagatopain17 wrote:
Hello! First of all, I'm rather new to both netbeans and java. I get the 
coding when i see it because ive programmed somewhat in C++ and basic visual, 
but im still new :3

Ok, im reading this guide:
http://www.gamedev.net/page/resources/_/technical/game-programming/java-game-programming-part-i-the-basics-r1262

im trying to use the shape functions like g.drawRect(x,y,width,height)

netbeans however tells me it doesnt know what g. is or something...

cant post the specific words right now, but could someone tell me how i can 
use this? Thanks!




"g" is a Graphics (an object type). It carries internally a state which determines what it draws.. That state is sometimes referred to as the graphics context and sometimes people mean just the graphics object itself when they say "graphics context" .

"State" is sort of an abstract idea so to be clear, when I say state think of stuff like line shape and line thickness and pen color and stuff like that. .

Graphics can be thought of as a pen which you use to draw upon the figurative canvas of the Component. It is passed into the methods of Component which are responsible for rendering some aspect of the Component.

In other words it's the system-created / system-granted pen which Components are passed and which they then take up to paint themselves with.

Every Component shares an instance and if you want to draw your Component a certain way, you change the Graphics object state and then start drawing.

Disembodied references to "g" in GUI code snippets are implicitly understood to have been taken from some method of Component (or one of its subclasses) such as

paint(GraphicsContext g)
or
paintComponent(GraphicsContext g)


and so on which ultimately paint what you see on the screen. There are quite a few rules about what you should and shuld not do when you paint components to the screen and at least you should refer to the Swing tutorial and learn what it is telling you before making API calls to draw Components for the very specific reason that some public methods of the Component class ought *not* to be called despite being public and all drawing code needs to execute in a particular thread- the EventDispatchThread. You may already be familiar with many of these caveats and rules :)


HTH




[nbusers] Using g.DrawRect and paint functions in Netbeans

nagatopain17 10/26/2012

[nbusers] Re: Using g.DrawRect and paint functions in Netbeans

Benno Markiewicz 10/26/2012

[nbusers] Re: Using g.DrawRect and paint functions in Netbeans

trhouse 10/26/2012

[nbusers] Re: Using g.DrawRect and paint functions in Netbeans

Edson Richter 10/26/2012

[nbusers] Re: Using g.DrawRect and paint functions in Netbeans

trhouse 10/26/2012

[nbusers] Re: Using g.DrawRect and paint functions in Netbeans

Edson Richter 10/27/2012

[nbusers] Re: Using g.DrawRect and paint functions in Netbeans

trhouse 10/27/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close