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

New Topic/Question
Reply




MultiQuote










|