Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  java.awt.Canvas  (Read 1595 times)
0 Members and 1 Guest are viewing this topic.
Offline ENC

Junior Duke





« Posted 2006-03-23 06:54:20 »

Hi ... I would like to know how to place a button on the awt.Canvas... since it extends from Container it should be able to put other components on it correct ?  Huh

I am really confuse... please help me with this... cause I dont see the buttons I want on  the canvas.
Offline Mr_Light

Senior Duke


Medals: 1


shiny.


« Reply #1 - Posted 2006-03-23 11:24:04 »

Click to Play

Since it doesn't you shouldn't be able.  Wink

confused with Panel are we?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline ENC

Junior Duke





« Reply #2 - Posted 2006-03-23 12:02:53 »

oh... I am trying to use canvas to do a game... most of my friends says that drawing graphics on a panel is not possible....

so what i want to know is that if a panel cannot do it? then painting on a canvas should be the right thing correct?

but the problem is that i have seen some games that panels overlap the graphics.... but due to the reason that canvas is a heavy component so how do i make the buttons be seen with the graphics?? cause i cant seem to get it right...

i have tried to overlap the canvas to allow the buttons to be seen ... but failed... do you think you can help me with this?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #3 - Posted 2006-03-23 16:25:56 »

Your friends are totally wrong.  You should use JPanel to do custom drawing.  Just subclass JPanel and override paintComponent(...).  Just don't forget to call super.painComponent(...) before doing your custom drawing.  You may also want to override getPreferredSize() to return the size you want the JPanel to be.  This will allow layout managers and scroll panes to properly display your panel.

Offline Mr_Light

Senior Duke


Medals: 1


shiny.


« Reply #4 - Posted 2006-03-23 21:09:21 »

go swing for overlapping or implent your own components if your doign active rendering. overlay heavy components doesn't work well.


It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #5 - Posted 2006-03-23 21:12:15 »

Yes, Swing is great, just override the necessary paintComponent(Graphics g) methods for your own look & feel as well as game graphics.

Offline ENC

Junior Duke





« Reply #6 - Posted 2006-03-24 03:52:32 »

oh ok... I will try that method...

then may I know what does the createBufferStrategy(int numberOfBuffers) do? Cause it seems that only canvas and window have it... other components like JPanel/ Panel, Frame /JFrame does not have it...

it is really possible to create a game without this method?

cause i tried ... it seems that createBufferStrategy is the answer for a smooth game..... Cry

Can someone write a sample code to see? Then maybe I can ref the codes?  Grin

Thank you! Grin Grin Grin
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #7 - Posted 2006-03-24 04:25:01 »

Swing has "setDoubleBuffered(boolean aFlag)". What game are you trying to do?

Offline ENC

Junior Duke





« Reply #8 - Posted 2006-03-24 05:14:20 »

oh ... I am trying to do a simplified version of SilkRoad but it is 2D not 3D

haha.. Grin

but then problem is that there are able to put buttons or at least panels i think... on to the graphics screen...

been trying to replicate it... but still failed

so yah..

Thanks kingaschi...

i will take note of it.. Cheesy

but still I wish someone can give me some codes to see.... cause i am not a hardcore programmer.. i need codes to understand...

then i can write out my own set of codes... lolz.....
8: Undefined index: online
File: /home/jgo/public_html/Themes/default/Display.template.php (main sub template - eval?)
Line: 161