• Advertisement

how to make game in java swing

Recommended Posts

Hi everyone.

My name is Sang and I am a student in primary school. I studied Java and  i am really like it.

and now I want to learn make game a game use Java in Java Swing. Would you like give me some websites teach make game java for begginers, please?

Thank you very much!

Share this post


Link to post
Share on other sites
Advertisement

Java, in general, is not well suited for game development (server code aside), specially Swing. You can do simple games with that, but it lacks many usefull things for games, such as joystick support and hardware acceleration.

If you really want to use Java, consider using better suited libraries like libGDX.

For Swing, check something like http://zetcode.com/tutorials/javagamestutorial/. Many concepts like game loops, state machines and collisions are applicable, so you can look for these, even if not in Java, and translate them as needed.

Share this post


Link to post
Share on other sites

Start with really simple games like hangman. Tictactoe for 2 players is easy too, quite more difficult is tictactoe if the computer playes one side!

With these games you don't need a graphical interface, you can just use standard input and output from the terminal (also known as console). Eg inspired from https://stackoverflow.com/a/5488107 :

import java.util.Scanner;

public class CopyTerminal {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String line = "";
        while (!line.startsWith("quit") && s.hasNextLine()) {
            line = s.nextLine();
            System.out.println(line);
        }
        s.close();
    }
}

Instead of merely printing the read line, check if the user typed something you understand by examining the 'line' variable, and process that input. update the game data, and print the new situation using System.out.println calls.

It may seem a bit silly to start here, but using the terminal is an easy and quick way to display information, I use it every day. Just printing a bunch of text lines is much simpler than displaying it in a graphical way. It allows you to quickly try things, and concentrate on the actual game rather than get distracted by big complicated gui stuff that merely just displays some information.

 

For swing, I would advise to first do a normal swing tutorial. You may find however it is quite oriented at normal gui (menu-bar, drop-down, buttons, labels, popup windows, hovers, etc) as you see in every-day programs, and not so much aimed at displaying loads of nice splashy graphics and cool sound-effects, as you tend to have in a game.

This is why people here use specialized game libraries like libgdx. Like swing it provides functionality for display and keyboard interaction, but also for displaying lots of graphics, and other things you may need in a game, like sound, joystick support etc.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By Snaked
      Im working in this project for 1 year .... mostly i develop a tool and databases for make the different maps and now i'm doing the client for play the game
      Tell me if you like it......
      this is a capture of how is viewing atm

       
       
      https://youtu.be/9251v4wDTQ0
    • By EddieK
      Hi i'm trying incorporate sounds into my game and I have ran into troubles with performance. Whenever I call:
      soundPool = new SoundPool.Builder().setAudioAttributes(new AudioAttributes.Builder().build()).build(); I immediately notice lagging and the framerate drops drastically. I don't even have to actually play the sounds for the framerate drop to occur.
      Is there anything I can do to fix this issue?
      Thanks in advance.
       
      P.S. Never mind, I figured out that restarting the phone got rid of the lagg and it wasn't because of the sound.
    • By RoKabium Games
      Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama
    • By Dave Haylett
      Hi everyone. I need some help with my project. It's a 2D-graphics-heavy WPF front-end app written in C#, which talks to two Access 2000 databases (yes I know, it's all I've got). It will be distributed freely on the internet, and so will be being used by Windows users of various installations/versions of Windows, Office, etc.
      One of the two databases (let's call it A), is intended to be read-only, and will be distributed with the app. It has half a dozen relational tables which I as the developer have populated, and is connected to in the app via OleDB Jet 4 with SQL querying the data now and then as the user uses the front-end. The database will be replaced whenever I release an update to the app.
      Database B is read/write, and contains end-user preferences, for example when they favourite something in my front-end, a Favourites table in here gets appended to. This database is not distributed with my app, and should not be overwritten, as it will lose user prefs, etc. and annoy my users.
      Whenever my app is run by a user, during initialisation database A will suck in the user data from database B (using simple SQL SELECT * INTO...), so that all the tables can be joined together by the SQL in database A (to include user prefs/favourites in SQL queries), and whenever the user favourites something, a record is created both in A (for the short-term session) and B (permanently). Database B isn't just about holding favourites, there is other user data in here as well, so there are 3 or 4 tables in B.
      So far, this is all working fine and I'm happy...
      Unfortunately my app is currently 32-bit, and it now needs to break the 32-bit memory barrier what with the size and volume of the graphics I'm pulling in (using the HDD is not really an option, as different graphics are needed kind of instantly and the hard disc would be being hosed and the app dog-slow otherwise, I suspect even off an SSD).
      I'm using VS2015, and switching to 64-bit will probably fix the memory problem, but it breaks Jet 4.0. I'm sure this is old news to most of you.
      To try to keep with 32-bit (and Jet4) but get the memory I need I've tried the -largeaddressaware toggle, and I've tried the editbin suggestion, but I just can't get these solutions to work in VS2015 no matter how hard I try. Are these definitely 100% solutions to 2gb memory limit in 32-bit applications? Should they always work? Am I dumb in being unable to get this to work?
      So otherwise I'm resigned to migrating to 64-bit, and having to get around the database issue, not the memory issue.
      My users will be using a variety of Windows versions (probably 7 and 10), and I'm sure various versions of Office, and so my solution for querying my two Access databases needs to be pretty open if possible.
      Googling has suggested I switch from JET4 to ACE12, but this is apparently requiring me to uninstall Office 2000 and install a 64-bit version (which I don't have), so I can't use it, and I suspect any users who also have an old version of Office installed won't be able to use it either?
      Googling has also suggested I use MS SQL Server. This sounds fine if there's such a thing as a "lite" local version which can manage database access, but I still need to somehow get the data from the databases (A.mdb and B.mdb) into the SQL Server each time the users fire up my app.
      The only solution I can think of at the minute, is to export all the tables from database A into CSVs every time I update the data in there, and have the app import them in a lame way, and also convert database B into some crappy text file which gets written to whenever the user changes a preference. I'd much rather use SQL to do all this if possible, as when the user browses around the app, queries involving joining several tables in A are regularly created and executed to adjust the user's experience/return search results/etc.
      So to summarise my misery, is there either an easy reliable way for me to keep with 32-bit/Jet4 and be able to address >2gb. Or is there instead an easy reliable way for me to switch to 64-bit and successfully query two Access databases without requiring all my users to have 64-bit Office installed?
      Thanks for reading and I hope someone can help.
    • By Alexander Winter
       
        Jumpaï is a game about creating platformer levels and playing them online with everyone. Will you become the most popular level maker or will you be a speedrunner holding world records on everyone's levels? More into casual play? No problems! You can happily play through the giant level database or chill at people's hub. Meet new people, make new friends, learn to master the game by asking pros or ask for people's favorite tricks on level making.  





      Unlike other games of its genre, Jumpaï is about playing levels with everyone in real time. You have the fun to see how other people are playing and get to realize you are not the only one failing that jump!

      The game is currently into development and still have lots to do. I am looking for people willing to help how they can. Developer? Graphist? Play tester? Sound designer? Game designer? I'm welcoming everyone. The project is so big I have a lot of work to do in all areas. Server backend, UI/UX, Game networking, Gameplay and even the website some day. As you can see from the default buttons, the game has been made with LibGDX. 

      If you plan to take an important role into the development of the game, we will discuss how you will get paid once the game generates money. Note that I'm not working on the game full-time. I'm studying full-time and working on it is a hobby. It's been 14 months since it started.

      So, are you interested? If so join me on my discord https://discord.gg/dwRTNCG and I'll answer all your questions.

      Additionnal screenshots:
       



  • Advertisement