Here is what kept me up last night:
Köll & Sam Classroom Blog
Collapse
X
-
Originally posted by Dököll
A right curly brace too many in the middle of the code; keep that one in mind.
The line number from the error diagnostic is the give away.
kind regards,
JosComment
-
Originally posted by JosAH"Class or interface expected error"
A right curly brace too many in the middle of the code; keep that one in mind.
The line number from the error diagnostic is the give away.
kind regards,
Jos
public class KilowattApplet extends Applet implements ActionListener"
Code was
Code:// Chapter: 3, Programming Assignment 6 // Programmer: Sam Barrett // Date: 24 Sep 2007 // Filename: KilowattApplet.java // Program: Applet // Purpose: Calculate Annual Appliance Running Cost import java.applet.*; import java.awt.*; import java.awt.event.*; public class KilowattApplet extends Applet implements ActionListener { public void init() { this.lblWelcome = new Label("Welcome to the Appliance Energy Calculator"); this.lblCost = new Label("Please enter the cost per kilowatt-hour in cents: "); this.txtCost = new TextField(10); this.lblHours = new Label("Please enter the kilowatt-hours consumed: "); this.txtHours = new TextField(10); this.btnCalculate = new Button("Calculate"); this.lblRunningCost = new Label("Click the Calculate Button to display the average energy cost "); setForeground(Color.black); // Never use Purple, some of us cannot see the text add(this.lblWelcome); add(this.lblCost); add(this.txtCost); add(this.lblHours); add(this.txtHours); add(this.btnCalculate); this.btnCalculate.addActionListener(this); add(this.lblRunningCost); } public void actionPreformed(ActionEvent e) { double dCost = Double.parseDouble(this.txtCost.getText()); double dHours = Double.parseDouble(this.txtHours.getText()); double dAverage = dCost * dHours; this.lblRunningCost.setText("The average annual cost to operate this appliance is $" + Math.round(dAverage*100)/100D); } // Components private Label lblWelcome; private Label lblCost; private TextField txtCost; private Label lblHours; private TextField txtHours; private Button btnCalculate; private Label lblRunningCost; }
Comment
-
Originally posted by SammyBHere's one that's not a give-away. I thought that it was going to keep me up all night, but it all of the sudden just went away. The error message was "C:\Documen ts and Settings\Sam\My Documents\CSD22 4\Homework\Chap ter3\Assignment s\KilowattApple t.java:12: KilowattApplet is not abstract and does not override abstract method actionPerformed (java.awt.event .ActionEvent) in java.awt.event. ActionListener
public class KilowattApplet extends Applet implements ActionListener"
method name 'actionPerforme d'. I always tend to spell it with a leading capital A.
Dunno why; my fingers seem to like that ;-)
kind regards,
JosComment
-
Originally posted by JosAHI've seen that error diagnostic more than often and always I had misspelled the
method name 'actionPerforme d'. I always tend to spell it with a leading capital A.
Dunno why; my fingers seem to like that ;-)
kind regards,
JosComment
-
Originally posted by r035198xI always forgot the first r and wrote it as actionPeformed
it is called when the bound property has changed and I alway type those
darn things as 'PropertyChange dListener' or 'propertyChange d' with a parameter
type of 'PropertyChange dEvent'. I don't even check anymore: when I see the
compiler whining again about classes not being declared abstract and yaddayadda,
I simply remove the 'd' from the methods and inner classes ...
kind regards,
JosComment
-
I guess that I should have realized that you-all would see it at once. It's one of those error messages that is so cryptic that you remember it. The funny thing was that I had no clue, but I had made some mistakes, so I retyped the code at the end and of course I was mystified as to why the message went away.Comment
-
Originally posted by SammyBI guess that I should have realized that you-all would see it at once. It's one of those error messages that is so cryptic that you remember it. The funny thing was that I had no clue, but I had made some mistakes, so I retyped the code at the end and of course I was mystified as to why the message went away.
syntax mistake should be. There is no syntactic mistake in that code; it was
just the fact that you stated that your class implements the ActionListener interface
which it effectively doesn't because there is no 'actionPerforme d' method defined;
the class isn't defined to be abstract either so all the compiler can tell you is what
I just wrote. It is a semantic mistake which the compiler checks for you.
kind regards,
JosComment
-
Originally posted by JosAH"Class or interface expected error"
A right curly brace too many in the middle of the code; keep that one in mind.
The line number from the error diagnostic is the give away.
kind regards,
Jos
Will keep this and any other curve balls in mind...
In a bit!Comment
-
Originally posted by DököllThat sounds very familiar...just got word through Java forum on this:-)
Will keep this and any other curve balls in mind...
In a bit!Comment
-
Originally posted by SammyBIf I were you, I would download Eclipse, http://www.eclipse.org/downloads/ (top-most download). It is a Java IDE, looks alot like VB's IDE, has intellisense, and tutorials. You will have about an hour learning curve, but it makes development much easier!
nothing' as they say so themselves. It's the JDT (Java Development Tool) that
makes Eclipse a Java IDE, but there's also a CDT (C and C++) and there's a whole
lot more to Eclipse; I use it on a daily basis; it's a great thing.
kind regards,
JosComment
-
Originally posted by JosAHSlight nitpick: Eclipse is *also* a Java IDE; Eclipse itself is about 'everything and
nothing' as they say so themselves. It's the JDT (Java Development Tool) that
makes Eclipse a Java IDE, but there's also a CDT (C and C++) and there's a whole
lot more to Eclipse; I use it on a daily basis; it's a great thing.
kind regards,
Jos
But, since you use Eclipse on a daily basis, a couple of questions. As part of each chapter, we develop the sample application as an Applet. The book is assuming that you are using TextPad and gives you a three line Html program which not only calls the Applet, but also specifies the height & width. With Eclipse, I have not created the html document; I just use the menu: Run > Run As > Java Applet, which works OK, but I have to resize the Applet. How do you add the html doc to your project and run it instead of using the Run As command.
Second, it is annoying to have to press both the tab key and the Enter key to use an intellisense suggestion. Can I change the preferences so that the tab key alone selects & uses the current line?
Thanks!Comment
-
I have an open book next week. It'd be nice to see what else is out there thank you for ypur suggestion Sam. Hope all is well with your projects...Got a project due in two weeks, tonight's lab was not too bad can use some examples there. Must code, in a bit...Comment
-
Originally posted by DököllI have an open book next week. It'd be nice to see what else is out there thank you for ypur suggestion Sam. Hope all is well with your projects...Got a project due in two weeks, tonight's lab was not too bad can use some examples there. Must code, in a bit...
The most annoying problem was:
Insert parantheses, if necessary, to make the following statement correct
33 = 3*6-3+2+6*4-4/Math.pow(2,1)
Does she know how many different ways you could insert parens? Argh!
You are blessed to have an Open Book test!Comment
-
Originally posted by SammyB...Does she know how many different ways you could insert parens? Argh!
...
If so, one example should be an adequate answer. She'll be looking for you not to parenthesise a sub-expression which is already hierarchically prioritised.Comment
Comment