Hi People who have this kind heart who could help me in my Java Programming Language Project..

I cannot sleep since last week coz I can't find a way how to solve my problem in Java
My teacher told me to make a simple game using Java programming Application. Since we're still in the basic learning on Java, I'm sure to my self that I cant make it by my own.
and I guess posting some threads here in Daniweb can help me to solve this problem. Please Help me...............

Thank you so much.

Dani AI

Generated

Replies from , , and show the main needs: a concrete starting plan, a tiny working example, and a few troubleshooting tips. Below is a compact, practical path to finish a beginner Java game assignment and a minimal Swing skeleton that runs immediately and can be extended one feature at a time.

First, break the project into small deliverables: pick one clear mechanic (move a sprite, click targets, avoid obstacles), choose a platform (console, Swing, or JavaFX depending on the class JDK), and implement an MVP that only does input -> update -> render. Add scoring, sound, and menus after the core works. Keep each step testable: start with a window that draws a single shape, then accept keyboard input to move it, then add collision or scoring.

A minimal Swing starter: it creates a window, runs a regular update via javax.swing.Timer (safe on the Event Dispatch Thread), accepts arrow keys, updates game state, and repaints. Save as SimpleGame.java and compile with a modern JDK.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SimpleGame {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame f = new JFrame("SimpleGame");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new GamePanel());
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        });
    }
}

class GamePanel extends JPanel implements ActionListener, KeyListener {
    int x = 50, y = 50;
    final int SPEED = 4;
    Timer timer;

    GamePanel() {
        setPreferredSize(new Dimension(400, 300));
        setBackground(Color.BLACK);
        setFocusable(true);
        addKeyListener(this);
        timer = new Timer(16, this); // ~60 FPS
        timer.start();
        requestFocusInWindow();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        repaint();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.RED);
        g.fillRect(x, y, 20, 20);
    }

    @Override public void keyPressed(KeyEvent e) {
        int k = e.getKeyCode();
        if (k == KeyEvent.VK_LEFT) x -= SPEED;
        else if (k == KeyEvent.VK_RIGHT) x += SPEED;
        else if (k == KeyEvent.VK_UP) y -= SPEED;
        else if (k == KeyEvent.VK_DOWN) y += SPEED;
    }
    @Override public void keyReleased(KeyEvent e) {}
    @Override public void keyTyped(KeyEvent e) {}
}

Quick troubleshooting: if nothing appears, ensure pack() and setVisible(true) are called on the EDT (use SwingUtilities.invokeLater). If keys seem ignored, confirm the panel is focusable and call requestFocusInWindow() after showing the window. For deeper reading on Swing and loop patterns see the Java Swing tutorial (Oracle) and a concise explanation of game loops (Game Programming Patterns).

Recommended Answers

All 4 Replies

>make a simple game using Java programming Application
This can be as simple as a number guessing game. You don't have to write the next Quake engine. :rolleyes:

>I'm sure to my self that I cant make it by my own
Then you can't. If you don't believe in yourself then nobody else will.

You should at least make a concept for the game.. and ask question about how to make something work.

You basically asked for someone to do the whole thing for you :P ble :rolleyes:

what exactly are you looking for in the game?

While I likely could not help you in the design of a game, I can help you get more responses to your posts on this forum.

I went ahead and changed the title of your post. "Can anyone help me??????????" had nothing to do with what you're actually asking. In the future, please consider composing a different title for your posts, so you can get more attention from those who might be able to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.