Welcome to Dream.In.Code
Become a Java Expert!

Join 149,581 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,756 people online right now. Registration is fast and FREE... Join Now!




Trying to run this but keep getting error

 
Reply to this topicStart new topic

Trying to run this but keep getting error, "exception in thread "main" java.Lang.NoSuchMethodError

trayyrho
10 Oct, 2007 - 04:22 PM
Post #1

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 9


My Contributions
CODE
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 Oct, 2007 - 04:24 PM
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Trying To Run This But Keep Getting Error
10 Oct, 2007 - 04:29 PM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
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:

CODE
<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 smile.gif Enjoy!

And yes please use code tags when posting code.

This post has been edited by PennyBoki: 10 Oct, 2007 - 04:30 PM
User is offlineProfile CardPM
+Quote Post

trayyrho
RE: Trying To Run This But Keep Getting Error
10 Oct, 2007 - 04:37 PM
Post #3

New D.I.C Head
*

Joined: 9 Oct, 2007
Posts: 9


My Contributions
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/
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:44PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month