Question

Hey I'm making a very simple Running Jumping game for my Java 1 class. The character is gonna run and jump over oncoming rocks. Should the rock and the running Boy be in the same class or separate?

import javax.swing.*;
import java.awt.*;
import java.awt.Dimension;
public class Boy extends JPanel {

JLabel Boy1;
ImageIcon Boy;

public Boy () {
    setLayout(null);
    setBackground (Color.white);


    Boy = new ImageIcon ("/Users/a/Documents/workspace/JumpyBoy/src/Boy.png");
    Boy1 = new JLabel (Boy, SwingConstants.CENTER);

    Boy1.setBounds(80, 300, 130, 500);

    add (Boy1);
}

}
Was it helpful?

Solution

@niiraj874u is correct. You want 2 classes. One for the boy and one for the rock.

Generally speaking, different nouns should become different classes.

Each noun, a boy and a rock in this case, will have different actions (functions) to perform: the boy will jump, the rock will roll (I guess). And these functions should be encapsulated into the separate classes depending on which object does which action.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top