Hot answers tagged

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.5k
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,122
11 votes
Accepted

Velocity, Distance and Time Calculator

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

Simon Says: "Optimizations!"

Use interfaces when possible ArrayList<Score> scores = new ArrayList<Score>(); ArrayList<Score> sessionScores = new ArrayList<Score>(); ...
bazola's user avatar
  • 8,579
10 votes

Learning by translating - Follow the Rubberduck - Part 2: Beta

public static final String RUBBERDUCK_PATH = "RetailCoder.VBE/UI"; This value shouldn't be compiled into the binary. It should be a configurable setting that's ...
Mathieu Guindon's user avatar
10 votes
Accepted

Medical diagnosis selector

Layout Don't hard-code dimensions and positions. On a Mac, everything looks wrong. (I don't have your images, so I'm going to ignore them for the rest of this review.) Furthermore, the user of the ...
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,579
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,326
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,701
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.2k
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
Accepted

Learning by translating - Follow the Rubberduck - Part 2: Beta

Main What is the purpose of: private Main() { } I can currently think of two possibilities: To prevent inheritance: Easily fixed with the ...
TheCoffeeCup's user avatar
  • 9,454
6 votes

Java Swing Text Editor

Violating important threading practices test2 a = new test2(); The swing documentation state all swing actions should be done from the event dispatch thread. If ...
Ferrybig's user avatar
  • 1,347
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,347
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
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,779
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
6 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
5 votes
Accepted

Using actionPerformed() to call different methods per radio button selection

Indeed, the conditional branching in actionPerformed(ActionEvent) is quite complex and prone to bugs. This implementation does too many things at the same time: ...
Antot's user avatar
  • 3,637
5 votes
Accepted

Swing UI for database-to-Excel tool

Minimize failure scopes Try-Blocks should be as small as reasonably possible. Some people even advocate extracting error-handling into a separate method of the form: ...
Vogel612's user avatar
  • 25.2k
5 votes

Basic TicTacToe game in java

There's lots of duplication here. Cleaning that up will leave things a lot shorter. ...
Michael Shaw's user avatar
5 votes
Accepted

Swing GUI in Java

Yes, that is proper use of composition over inheritance. Although some may say this is actually aggregation, due to the nature of Swing. Composotion is the act of one object owning another object. ...
Dioxin's user avatar
  • 424
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.4k

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