jQuery in Action, 2nd edition
The moose likes Swing / AWT / SWT and the fly likes how to draw directly to the monitor without a While loop Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "how to draw directly to the monitor without a While loop" Watch "how to draw directly to the monitor without a While loop" New topic
Author

how to draw directly to the monitor without a While loop

Arturo Gamboa
Greenhorn

Joined: Apr 02, 2010
Posts: 3
this idea has gone round round in my head, and i can figure it out..

how do i draw a simple image to the monitor without a loop.

the common way to draw an image to the monitor as i have seen so far, is inside a while loop( active rendering i think), otherwise it wont draw


if i do it that way it get drew to the screen.

i want to know if thres a way to get something drawn out of a single sentence like the last one but wihout the loop.






pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
What GUI/Graphics library are you using? Swing? If so, then your best bet is to study the Sun/Oracle 2D Graphics tutorials.

Much luck!
Arturo Gamboa
Greenhorn

Joined: Apr 02, 2010
Posts: 3
thank you for the advice, i knew it could be done with 2D.
anyway, i have the curiosity if theres a way other than using Java 2d graphics.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Arturo Gamboa wrote:thank you for the advice, i knew it could be done with 2D.
anyway, i have the curiosity if theres a way other than using Java 2d graphics.


I'm having a great deal of difficulty understanding just what you're asking here. It's kind of like asking if one could prepare dinner without using food. Can you give us more details regarding just what you're trying to do?
Arturo Gamboa
Greenhorn

Joined: Apr 02, 2010
Posts: 3
sorry for not explaining myself better.

ill do it more explicitly-

ill write down the the methods i know so far to draw an image:

1.- using paint method from inside the component(passive rendering):



2.-using active rendereing(anywhere inside a while loop)


3.- and finally using Java2d graphics to draw on a bufferedimage which will be drawn on the monitor afterward(very similar to what i want)
definitly too much ado for painting an image




the thing i want to know if there is a more natural way to draw an image on the monitor;something like this or alike


Component contextcComponent
image image = myGetImage(url location);

Graphics g = contextComponent.Getgraphics();
g.drawImage(image,x,y,null);



//and ready. a simple image on the monitor. i have been surfing on the web but cant get any answer, maybe theres not any?
sorry if its still dificult to figure out what i want. your answers are very apreciated


Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4164
    
    3

I think what you're looking for is a JLabel with an Icon (probably ImageIcon)


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32668
    
    4
I know it's late (I seem to have been very busy over the weekend) but Ithink thisought to move to our GUIs forum.

Beware of drawing to the screen; that can take much much longer than the loop and it is possible for the loop to re-start before drawing is completed.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to draw directly to the monitor without a While loop
 
Similar Threads
Loading Images
Drawing Image Doubles Memory Consumption
unreachable statement
Set Pixel(x, y) to color c
how to get Image from Canvas