5 Replies - 1844 Views - Last Post: 28 October 2010 - 06:54 PM Rate Topic: -----

#1 mvalor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 16-November 08

Help with method not found error

Posted 27 October 2010 - 07:03 PM

OK, so I wrote this code for practice.
The code does show an error stating that "themometer.thermometer does not have a main method", everytime I make the file run.

The code is written exacly as it is in the Book "Imagine Java" by Frank Carrano, page 117-119.
I am als using NETBEANS 6.9 as the IDE.

Here is the code:


package thermometer;

/**
 *Thermometer.java program
 * @author mvalor
 */
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Random;

public class Thermometer extends JPanel {

    /**
     * @param args the command line arguments
     */
    public void paintComponent(Graphics pen) {
        // TODO code application logic here
        final int BORDER =20; //distance between top/side edges and temperature column
        final int EDGE_LEFT = 175;
        final int EDGE_TOP = 30;
        
        //Temperature column geometry
        final int COLUMN_LEFT = EDGE_LEFT + BORDER;
        final int COLUMN_TOP = EDGE_TOP + BORDER;
        final int COLUMN_HEIGHT = 150;
        final int COLUMN_WIDTH = 5;
        
        //thermometer dimensions
        final int EDGE_WIDTH = COLUMN_WIDTH + 2 * BORDER;
        final int EDGE_HEIGHT = COLUMN_HEIGHT + (int)(2.5 * BORDER);
        
        //key temperatures
        final int MAX_TEMPERATURE = 500;
        final int MIN_TEMPERATURE = -40;

        //get temperatures
        Random randomInteger = new Random();
        int temperature = randomInteger.nextInt(MAX_TEMPERATURE -
                MIN_TEMPERATURE +1) + MIN_TEMPERATURE;

        //paint fluid in temperature column
        double range = (double)(MAX_TEMPERATURE - MIN_TEMPERATURE);
        int fluidHeight = (int)(COLUMN_HEIGHT * temperature / range);
        int fluidTop = COLUMN_TOP + COLUMN_HEIGHT - fluidHeight;
        pen.fillRect(COLUMN_LEFT, fluidTop, COLUMN_WIDTH, fluidHeight);

        //draw edge of temperature column and the frame around it
        pen.drawRect(COLUMN_LEFT, COLUMN_TOP, COLUMN_WIDTH, COLUMN_HEIGHT);
        pen.drawRect(EDGE_LEFT, EDGE_TOP, EDGE_WIDTH, EDGE_HEIGHT);

        //show digital temperature
        int xLable = COLUMN_LEFT - 2 * BORDER / 3;
        int yLable = COLUMN_TOP + COLUMN_HEIGHT + BORDER;
        pen.setFont(new Font("Monospaced", Font.BOLD, 10));
        pen.drawString(temperature + "DegF", xLable, yLable);
    }// end paintComponent

}// end Thermometer



Can anyone tell me what I am missing?

Thanks
Mike

Is This A Good Question/Topic? 0
  • +

Replies To: Help with method not found error

#2 rekless  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 42
  • Joined: 08-January 09

Re: Help with method not found error

Posted 27 October 2010 - 07:25 PM

the answer to what your missing is simple.

your missing the main function that actually runs the code. hence the error.

you need to create the method

public static void main(String[] args)

and inside you will call the paintComponent() method.

or for nicer coding. build a display class and inside that build the main method. Then create an Thermometer object and call the function through the object.
Was This Post Helpful? 0
  • +
  • -

#3 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2686
  • View blog
  • Posts: 15,726
  • Joined: 24-September 08

Re: Help with method not found error

Posted 27 October 2010 - 07:26 PM

Main method. Lol.

public static void main(String[] args) {
Thermometer t = new Thermometer();
}
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2873
  • View blog
  • Posts: 11,032
  • Joined: 15-July 08

Re: Help with method not found error

Posted 28 October 2010 - 01:29 AM

Topic Renamed. "Java" is a terrible name for posts in the Java help forum.
Was This Post Helpful? 0
  • +
  • -

#5 mvalor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 16-November 08

Re: Help with method not found error

Posted 28 October 2010 - 03:56 PM

View Postrekless, on 27 October 2010 - 06:25 PM, said:

the answer to what your missing is simple.

your missing the main function that actually runs the code. hence the error.

you need to create the method

public static void main(String[] args)

and inside you will call the paintComponent() method.

or for nicer coding. build a display class and inside that build the main method. Then create an Thermometer object and call the function through the object.


Can you give an example?
Because, in every example in the book shows nothing that you are stating even though I know your right.

Still I cannot fige how you write this even though I know that one you show me, I am going to slap myself in the back of he head.

Mike
Was This Post Helpful? 0
  • +
  • -

#6 mvalor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 16-November 08

Re: Help with method not found error

Posted 28 October 2010 - 06:54 PM

Never mind...I got it!

package thermometer;
import javax.swing.JFrame;
/**
 *
 * @author mvalor
 */
public class displayThermometer {
public static void main(String[] args)
    {
    final int WIDTH = 395;
    final int HEIGHT = 300;
    JFrame aWindow = new JFrame();
    awindow.setSize(WIDTH, HEIGHT);
    awindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    awindow.setTitle("Thermometer");
    thermometer panel = new thermometer();
    awindow.add(panel);
    awindow.setVisible(true);
  
}//end main
}//end display






This was supposed to added to the project in a new file.

Thanks!
Mike
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1