0

I compiled some sample code with javac and when i tried running it here's what i get:

C:\Users\Lenis>cd C:\Java\2D

C:\Java\2D>java donut.board
Error: Could not find or load main class donut.board

I tried writing "java -cp . donut.board" and still get the same.

My classpath is : "C:\Program Files\Java\jdk1.7.0_02\lib\tools.jar;."

How to fix it?

And here is the code:

package donut;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import javax.swing.JPanel;

public class Board extends JPanel{

public void paint(Graphics g)
{
  super.paint(g);

  Graphics2D g2 = (Graphics2D) g;

  RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                           RenderingHints.VALUE_ANTIALIAS_ON);

  rh.put(RenderingHints.KEY_RENDERING,
         RenderingHints.VALUE_RENDER_QUALITY);

  g2.setRenderingHints(rh);

  Dimension size = getSize();
  double w = size.getWidth();
  double h = size.getHeight();

  Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
  g2.setStroke(new BasicStroke(1));
  g2.setColor(Color.gray);


  for (double deg = 0; deg < 360; deg += 5) {
      AffineTransform at =
          AffineTransform.getTranslateInstance(w / 2, h / 2);
      at.rotate(Math.toRadians(deg));
      g2.draw(at.createTransformedShape(e));
    }
}
}
tshepang
  • 12,111
  • 21
  • 91
  • 136
Reus
  • 31
  • 1
  • 4

3 Answers3

3

You don't have main method in the class and also when invoking you have to give donut.Board (capital B) It is case sensitive. Add the main method.

prajeesh kumar
  • 1,916
  • 1
  • 17
  • 17
1

Your class name Board starts with capital.

Kuldeep Jain
  • 8,409
  • 8
  • 48
  • 73
0

Include your main method in your Board class, you can see a simple example here: http://docs.oracle.com/javase/tutorial/java/concepts/class.html

Also change java -cp . donut.board to java -cp . donut.Board

As you can see in the following code, this is a class that by itself can´t do anything, this is saying just what you can do with a Bicycle but you are not using all that behavior

 class Bicycle {
    int cadence = 0;
    int speed = 0;
    void changeCadence(int newValue) {
         cadence = newValue;
    }
    void speedUp(int increment) {
         speed = speed + increment;   
    }
    void applyBrakes(int decrement) {
         speed = speed - decrement;
    }
    void printStates() {
         System.out.println("cadence:" +
             cadence + " speed:" + 
             speed );
    }
} 

So if you want to use this class you can create another class where you include the main method, now you are really using all the behavior that you gave to a Bicycle in the previous class

class BicycleDemo {
    public static void main(String[] args) {
       Bicycle bike1 = new Bicycle();
        Bicycle bike2 = new Bicycle();

        bike1.changeCadence(50);
        bike1.speedUp(10);
        bike1.printStates();

        bike2.changeCadence(50);
        bike2.speedUp(10);
        bike2.changeCadence(40);
        bike2.speedUp(10);
        bike2.printStates();
    }
}
femtoRgon
  • 32,893
  • 7
  • 60
  • 87
salembo
  • 11
  • 1
  • 4
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Rick Mar 11 '15 at 17:32
  • 1
    @Rick thanks for your comment, I'll add some code to improve the answer :) – salembo Mar 11 '15 at 18:50