Advertisement

how to make game in java swing

Started by December 06, 2017 06:16 AM
4 comments, last by sang_261198 6 years, 11 months ago

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!

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.

Advertisement

@TerraSkilll hi friend, Java  is not well suited for game development, so can you give me some tools or software help me make game easier and not very much code?

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.

 

thank so much

This topic is closed to new replies.

Advertisement