Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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 1040 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Posted 2012-12-11 19: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

Screenshot:

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

Thankyou.
Will have a closer look at this after work tonight...
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.

xsi3rr4x (63 views)
2014-04-15 18:08:23

BurntPizza (61 views)
2014-04-15 03:46:01

UprightPath (74 views)
2014-04-14 17:39:50

UprightPath (57 views)
2014-04-14 17:35:47

Porlus (75 views)
2014-04-14 15:48:38

tom_mai78101 (100 views)
2014-04-10 04:04:31

BurntPizza (160 views)
2014-04-08 23:06:04

tom_mai78101 (255 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!