Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  For Java2D n00bs - Mixing Swing and a drawable canvas to make a boardgame  (Read 2409 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultroman

JGO Knight

Medals: 25
Projects: 1

Snappin' at snizzes since '83

« Posted 2012-12-11 18:02:43 »

Hello everyone!

A friend of mine asked me how he could start programming games in Java, without having to make
his own menu-system and learn a lot about animations, before he could get started. He just wanted
to play around with something simple, like a boardgame. Nothing too crazy. Something like "Risk".

There are many good Java tutorials out there, but few tackle the difficulties of dealing with Swing-
menus combined with a drawable canvas, and fewer actually describe and explain what they're doing
to make it all work. It quickly becomes magic to many. I've tried to make a simple, thoroughly commen-
ted project, with a few helpful modules to get started with. They're not completely optimized or state-
of-the-art, but that's the point. I wanted to make a project a newcomer could look at, and easily learn
from and expand on.

I've covered the following:
- Creating the JFrame with the correct desired size / handling insets
- Loading images from within your Jar
- Loading images from a folder next to your Jar
- Setting up two menus; one to the right, and one at the bottom
- How to fill the menus with buttons and labels where you want them
- Comprehensive customizing of JButtons and JLabels
- Custom cursor
- Creating a simple canvas to draw on
- A very simple gameloop implementation, just to explain the concept
- Drawing strings and rectangles
- Very simple keyboard- and mouse-implementation
- Reacting to controls on the canvas
- Changing stuff in the menus and on the canvas, when the canvas registers clicks or keystrokes
- How to get error-logs when running your game as a Jar
- Customized close-operation attached to the JFrame
- Using HTML to add more lines in your JLabels, JButtons and tooltips

It is a zip file, which you should be able to import directly into Eclipse. It is Java 1.6.
Download Zipped Eclipse Project
Download Runnable Jar

NOTE: The project is set up, so if you swap the worldmap-image for another image, it can resize itself automatically.
The project is meant as a simple example of a layout, from which one could make a decent game,
given some time, and some activity in a Photoshop-like application. It should be pretty easy to
completely remove the existing menus and create your own playing field, but if you are a newcomer,
I'd advise you to read through everything carefully first, to ensure that you know what is going on.
For now, the mouse- and keyboard-modules aren't commented. Big whoop. If I get around to it, I'll
upload a new version, and update the link.

I hope this helps someone out there. Any suggestions welcome.

Sincerely, Jonas Tingmose aka. Ultroman


- Jonas
Offline SwampChicken
« Reply #1 - Posted 2012-12-13 04:02:02 »

Will have a closer look at this after work tonight...
Pages: [1]
  ignore  |  Print  

EgonOlsen (73 views)
2018-06-10 19:43:48

EgonOlsen (54 views)
2018-06-10 19:43:44

EgonOlsen (73 views)
2018-06-10 19:43:20

DesertCoockie (253 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!