Trying to run this but keep getting error

"exception in thread "main" java.Lang.NoSuchMethodError

Page 1 of 1

6 Replies - 1917 Views - Last Post: 02 May 2010 - 06:38 PM Rate Topic: -----

#1 trayyrho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 10-October 07

Trying to run this but keep getting error

Posted 10 October 2007 - 05:22 PM

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class KilowattApplet extends Applet implements ActionListener
{
	Label welcomeLabel = new Label("Welcome to the Applicance Energy Calculator");
	Label costKwhrLabel = new Label("Please enter the cost per kilowatt-hour in cents: ");
	TextField costKwhrField = new TextField(5);
	Label hoursPerYearLabel = new Label("Please enter the kilowatt-hours consumed: ");
	TextField hoursPerYearField = new TextField(5);
	Button calcButton = new Button("Calculate");
	Label outputLabel = new Label("Click the Calculate buttont to display the average energy cost");

	public void init()
	{
		//insert controls
		add(welcomeLabel);
		add(costKwhrLabel);
		add(costKwhrField);
		add(hoursPerYearLabel);
		add(hoursPerYearField);
		add(calcButton);
		add(outputLabel);
		calcButton.addActionListener(this);
	}
	   //convert input to values
	   public void actionPerformed(ActionEvent e)
	{
		//declare variables
		double costKwhr = Double.parseDouble(costKwhrField.getText());
		double hoursPerYear = Double.parseDouble(hoursPerYearField.getText());

	  //variables used in formula and output
	  double average;

	   //calculations
		average = (costKwhr/100) * hoursPerYear;

		//output
	   outputLabel.setText("The average annual cost to operate this applicance is $" + Math.round(average* 100/100D));
	}
}
edit: code tags PB

This post has been edited by PennyBoki: 10 October 2007 - 05:24 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to run this but keep getting error

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Trying to run this but keep getting error

Posted 10 October 2007 - 05:29 PM

well I guess you are trying to RUN this from the IDE you are using right?
If so then do the following:
Just compile this code, then create an html page where you'll attach the applet, then view the jtml page through a web browser.

this is the code for the html page:

<html>

	<head>
			<applet code="KilowattApplet.class" height=500 width=500 >

			</applet>
			
	</head>






	<body>
			

	</body>


</html>


Note that you can adjust the height and width, I just made it 500x500.

So as I said this code save it as an html page, the just view the page through the web browser :) Enjoy!

And yes please use code tags when posting code.

This post has been edited by PennyBoki: 10 October 2007 - 05:30 PM

Was This Post Helpful? 0
  • +
  • -

#3 trayyrho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 10-October 07

Re: Trying to run this but keep getting error

Posted 10 October 2007 - 05:37 PM

That worked! Thanks, i was forgetting to create the HTML code and was confused as to why the application would not run from TXTPAD. How long does it take to become good at this stuff. I'm still in the beginning stage.

r/
Was This Post Helpful? 0
  • +
  • -

#4 Guest_sid dides*


Reputation:

Re: Trying to run this but keep getting error

Posted 02 May 2010 - 03:45 PM

View Posttrayyrho, on 10 October 2007 - 04:22 PM, said:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class KilowattApplet extends Applet implements ActionListener
{
	Label welcomeLabel = new Label("Welcome to the Applicance Energy Calculator");
	Label costKwhrLabel = new Label("Please enter the cost per kilowatt-hour in cents: ");
	TextField costKwhrField = new TextField(5);
	Label hoursPerYearLabel = new Label("Please enter the kilowatt-hours consumed: ");
	TextField hoursPerYearField = new TextField(5);
	Button calcButton = new Button("Calculate");
	Label outputLabel = new Label("Click the Calculate buttont to display the average energy cost");

	public void init()
	{
		//insert controls
		add(welcomeLabel);
		add(costKwhrLabel);
		add(costKwhrField);
		add(hoursPerYearLabel);
		add(hoursPerYearField);
		add(calcButton);
		add(outputLabel);
		calcButton.addActionListener(this);
	}
	   //convert input to values
	   public void actionPerformed(ActionEvent e)
	{
		//declare variables
		double costKwhr = Double.parseDouble(costKwhrField.getText());
		double hoursPerYear = Double.parseDouble(hoursPerYearField.getText());

	  //variables used in formula and output
	  double average;

	   //calculations
		average = (costKwhr/100) * hoursPerYear;

		//output
	   outputLabel.setText("The average annual cost to operate this applicance is $" + Math.round(average* 100/100D));
	}
}
edit: code tags PB

Was This Post Helpful? -1

#5 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Trying to run this but keep getting error

Posted 02 May 2010 - 05:32 PM

it only takes one foot in front of the other. You always learn cool tricks. The best way to get good at it is to just do it, then begin to help others once you are "proficient". Teaching really is the best way to learn :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#6 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Trying to run this but keep getting error

Posted 02 May 2010 - 06:07 PM

this post is about 3 years old.
i don't think the OP is likely to look for any updates on this post :)
Was This Post Helpful? 0
  • +
  • -

#7 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Trying to run this but keep getting error

Posted 02 May 2010 - 06:38 PM

haha, didn't eve notice, I have my filter to arrange it from newest responses
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1