Jump to content
  • 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

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();

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!