Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  question about custom buttons  (Read 2173 times)
0 Members and 1 Guest are viewing this topic.
Offline Kommi

Junior Devvie




All opinions will be lined up and shot!


« Posted 2003-12-08 16:21:25 »

Not really custom, more like your own. I was wondering whats everyone's opinion on the proper way to make your own buttons. If I have a few buttons fixed on the screen at certain screen coords, then what is the best way to detect a button press. For now i just have a mouseClicked method that checks to see if the mouse was clicked in the region of the button. So if I have a 100x100 button at 50,600 xy coords I check if the click took place between 50 and 150 x, and 600 and 700 y. Is there a more proffesional way of doing this?

Kommi
Offline tom
« Reply #1 - Posted 2003-12-09 16:18:40 »

If you're using awt you could override canvas and get the events from it.

But if your using opengl or something you would need to do all the work yourself. What you describe sounds like a basic way of doing this it. I think the proffesional way would be to create somehing similar to awt. Where you would have a general Component that get all the propper events. Then just override it to create your button.

Offline Kommi

Junior Devvie




All opinions will be lined up and shot!


« Reply #2 - Posted 2003-12-09 17:54:26 »

I am using AWT. Could you please elaborate on how it could be done. I am currently just drawing boxes in certain locations. What would I use if I overwrode the AWT?  

Kommi
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2003-12-09 22:07:59 »

By overriding Canvas you are making your own button component that you use instead of java.awt.Button.

Here's what you will have to do:
*Create your custom button class that extends Canvas.
*Register it as listener to the mouse, focus, keybard, etc in the constructor.
*Override paint(Graphics g) to draw the button to the screen.
*Keep an array of ActionListeners that is called when the putton is clicked. You would have to implement addActionListener and removeActionListener functions

Got the idee?

Offline Kommi

Junior Devvie




All opinions will be lined up and shot!


« Reply #4 - Posted 2003-12-10 16:40:13 »

Yes I got the idea. Thanks, Ill try it sometime this weekend.

Kommi
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2003-12-11 05:06:07 »

If thsi si an AWT app why not just create a new component?

Even simpler why not sub-class the AWt Button and just chnage the paint code??

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline tom
« Reply #6 - Posted 2003-12-11 16:26:54 »

When overriding java.awt.Component the component will be drawn in the paint function of the parent java.awt.Container.

When overriding java.awt.Canvas, the component will be more heavyweight. It can be repainted independent from the parent.

I don't think it's a good idee to override java.awt.Button because it's a true heavyweigth component that is drawn by native code. And you don't have access to it's internal state. So you don't wich state to draw in the paint function.

Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2003-12-13 03:35:04 »

If you don't want heavyweights you should be using SWING.

In which case you can override JButton Smiley

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Kommi

Junior Devvie




All opinions will be lined up and shot!


« Reply #8 - Posted 2003-12-14 21:58:03 »

Point taken Jeff. Mine is a game with my own render method and I am using Graphics object and awt to draw all images and text to the screen. I will try to sub-class the awt button and add my own paint code.

Kommi
Offline Kommi

Junior Devvie




All opinions will be lined up and shot!


« Reply #9 - Posted 2003-12-17 12:05:21 »

Oh by the way if I am devedloping a game and am using active rendering and going for fast frame rates is overridding the Swing stuff a good aproach? I read somewhere that it wasnt as it creates too much overhead.

Kommi
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #10 - Posted 2003-12-18 01:12:27 »

Ah.

yeah if you are trying to get fast frame rate and integrating the gui into your game its probably best to do what traditional games have done and just write your own menu logic.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Kommi

Junior Devvie




All opinions will be lined up and shot!


« Reply #11 - Posted 2003-12-22 11:51:41 »

So to reiterate my question: is storing button screen coords and checking for mouse clicks in specific areas the right menu logic for a fast game loop implementation?

Kommi
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (80 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!