Skip to main content
Share Your Experience: Take the 2024 Developer Survey
15 votes
Accepted

Detecting Tiles in Java

The entirety of the if/else statements are redundent if we consider that if we divide the current location by the tile_size we get the correct tile number ...
Ludisposed's user avatar
  • 11.6k
14 votes

Simple Java MIDI player followup

Well, your post is over a year old, but hopefully this can still be of some use to you! Javadoc No need to say the method name again - the method name is automatically part of the Javadoc. What are ...
avojak's user avatar
  • 614
12 votes
Accepted

Ping-Pong game in Java

Model vs UI Your classes have basic separation of concerns. But as you can see by yourself some model elements like "Ball" or "Box" or "Paddle" or even "Game" ...
oopexpert's user avatar
  • 3,132
11 votes
Accepted

Velocity, Distance and Time Calculator

...
200_success's user avatar
10 votes
Accepted

Bare bones painter app in Java

A few notes: Is there a reason you aren't using JavaFX? See this answer as to why you should be using it. Since I mostly rewrote your code, I'll do the best I can to explain all the components of ...
syb0rg's user avatar
  • 21.8k
9 votes

Ping-Pong game in Java

Thanks for sharing this. Looks quite reasonable to me. I have only a few thing I'd change: unnecessary inheritance Your Game class extends ...
Timothy Truckle's user avatar
8 votes
Accepted

Java Snake game

Welcome to Code Review! There's lots that can be improved about this code, so lets get started. Use the Random class instead of Math.random() Instead of this ...
bazola's user avatar
  • 8,569
8 votes
Accepted

Java Langton's Ant simulation

Bugs Your simulation is buggy — and not just because an ant is involved! It looks like you intend for each call of AntFrame.SimulationThread.run() to execute one ...
200_success's user avatar
7 votes

Simple Hangman game in Java

Just quickly, here's some feedback: I think your set up code is fine (where you're creating the JFrames etc), it's very boiler platey, but that's java. But you shouldn't put that logic in the ...
dwjohnston's user avatar
  • 1,308
7 votes
Accepted

Civilization Wars Game

MVC The MVC pattern is described like this: The controller knows the model and the view. The view knows the model. About how components communication with each other: I've seen different opinions on ...
slowy's user avatar
  • 1,866
7 votes

Detecting Tiles in Java

Instead of implementing MouseListener, you can use the MouseAdapter class to implement only the method you need. ...
Marc-Andre's user avatar
  • 6,711
7 votes
Accepted

Cookie Clicker in Java

Thanks for sharing your code. It is a really good for the first attempt. Nevertheless there is something to mention... Naming Finding good names is the hardest part in programming. So always take ...
Timothy Truckle's user avatar
7 votes
Accepted

Java program to disturb user and waste SSD lifetime

Your program is very inefficient. First, to use up the SSD write cycles, you should write lots of data. A single three-bytes string is not that much. Plus, there might be SSD implementations that ...
Roland Illig's user avatar
  • 21.3k
7 votes
Accepted

Chess application with GUI and AI in Java

On first glance, I wouldn't call things just View, Controller, and Observable, even if they ...
Christian Hujer's user avatar
7 votes

Game of life GUI simulation using java.swing

The first thing that I notice when looking at the code is something that directly stings in my eyes: Formatting. The code is is not formatted according to the SUN or Google Code Conventions (which are ...
Christian Hujer's user avatar
6 votes

Bare bones painter app in Java

this.imageGraphics.setColor(Color.WHITE); this.imageGraphics.fillRect(0, 0, width, height); this.imageGraphics.setColor(Color.BLACK); This part of ...
Pimgd's user avatar
  • 22.3k
6 votes

Simple Hangman game in Java

TestLetter should accept a char instead of a String void testLetter(String a) { You really want to test if a single character is inside the search word, than a ...
Ferrybig's user avatar
  • 1,357
6 votes
Accepted

SpaceWar game in java

Well, then let's tear this apart piece by piece. We will start with your questions: One of them is "access can be package-private". I know what it means, it tries to "narrow down" the access. So, ...
Ext3h's user avatar
  • 2,799
6 votes

Velocity, Distance and Time Calculator

The first problem that stands out with your code is the formatting. You can always paste your code into a Java code formatter/beautifier such as that found on TutorialsPoint to indent and format the ...
Phrancis's user avatar
  • 20.4k
5 votes
Accepted

Integer sum program

Avoid relying on display for business logic if (event.getActionCommand().equals("Add")) { Be careful with this kind of thing. If you write a real ...
mdfst13's user avatar
  • 21.6k
5 votes

Swing Temperature Converter

Inheritance Do not extend any class unless you you have an "is a" relationship and add new behavior to the extended class. You extend JFrame without adding Frame related behavior, you just configure ...
Timothy Truckle's user avatar
5 votes
Accepted

Animation of java.awt.Polygons

Conceptual Problems You have hard coded the animation FPS as ANIMATION_FPS = 60. This is a big no-no! You are assuming that your code will be called exactly with ...
Emily L.'s user avatar
  • 16.6k
5 votes

Animation of java.awt.Polygons

Use the right tool for the Job - Timer instead of SwingWorker Using the right tool for the job will significantly simplify your ...
Christian Hujer's user avatar
5 votes
Accepted

Java Game Of Life

...
Pimgd's user avatar
  • 22.3k
5 votes
Accepted

Tic Tac Toe in Swing

Change your fields' visibility to private as others object shouldn't know (nor care) about the inner working of your TicTacToe, ...
Ronan Dhellemmes's user avatar
5 votes

Tic Tac Toe in Swing

MVC Because I didn't know how to compare images, I stored a parallel String array to compare the values. Should I be using a 2-D array? You have to separate concerns and responsibilities. Any ...
Timothy Truckle's user avatar
5 votes

Simulating a closed particle system in Java

I don't like Comments :P - no, really: /** * The mass of this particle. */ private final double mass; That should be really obvious. And there's also those ones: ...
slowy's user avatar
  • 1,866
5 votes
Accepted

A small but expandable Exam system

Thank for sharing your code. OOP doesn't mean to "split up" code into random classes. The ultimate goal of OOP is to reduce code duplication, improve readability and support reuse as well as ...
Timothy Truckle's user avatar
5 votes
Accepted

Sorting an array of numbers in Java with an algorithm

Im impressed that you used selection sort. The standard bubble sort method would be slower. Have a look at the bubble sort method anyway. ...
Riley Jones's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible