This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

The method (method) is undefined for the type (project)  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tester class:


List of errors: Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method setDefaultCloseOperation(int) is undefined for the type Calculator
The method setVisible(boolean) is undefined for the type Calculator
The method setSize(int, int) is undefined for the type Calculator
The method setTitle(String) is undefined for the type Calculator
The method getContentPane() is undefined for the type Calculator

at calcTester.main(calcTester.java:13)


 
Master Rancher
Posts: 4072
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the first thing is you really shouldn't be running code that has compilation issues.

You haven't quite got the code tags correct.
The code should go inbetween the two tags.
Without that it's a bit difficult to see what the issue is.
 
Saloon Keeper
Posts: 3250
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Elliot,

welcome to the Ranch and enjoy the stay!

You have not mentioned anything about a package. Are you using the default package? If so, is it possible that you somewhere have another class Calculator that does not extend JFrame?

I copied your code into my IDE, albeit that I put all the classes in the same file (removing the 'public' from the classes) and it ran without any problems.
 
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again.

I have gone back and corrected your code tags. That link tells you how they work. Doesn't it look better but it shows formatting problems. You have too many empty lines. Only put empty lines between successive methods/constructors or logical subdivisions of the code. Also be consistent with indentation. Get your IDE/editor to set up automatic indentation and automatically change tab characters to (?4) spaces.
Don't use GridBagConstraints directly. Find a copy of Core Java by Cay Horstmann and find out about his GBC class. There is a brief introduction to GBC here. GBC can save hundreds of lines of code in a large GUI.

Piet Souris wrote:. . . is it possible that you somewhere have another class Calculator . . .? . . .

How can you have two classes with the same name in the same package? More likely there is another class called JFrame, minus the setDefaultCloseOperation() method.

I am afraid I can see all sorts of problems with your code. The first is that I don't think you should subclass most GUI components. A calculator ISN'T‑A frame, but a calculator USES‑A frame. So I worry whenever I see class XYZ extends JFrame. In faact, you should write the calculator with no GUI at all, but methods like add(...) or getResult(), and then only add the GUI when you get the calculator working.
Line 8: Why did you use that serialVersionUID? Don't simply believe Eclipse's warnings without understanding them.
Lines 9‑12: Declare each variable on a line by itself. Give all fields private access. Actually, I think those variables don't need to be fields. I think most of them can be changed to become local variables in the constructor. Be careful with names of variables; sqrt appears several times in your code, with at least three different meanings, and followed in line 170 by squrt.
See code below. Note that the constructor includes code to make the GUI visible, so the GUI will appear if you execute new CalculatorGUI() anywhere.Don't write “^2” Write “\u00b2”. This is \u00b2: ² On a Linux box, try AltGr‑2 instead.
Don't make your frame implement action listener. Add different action listeners to the buttons. The method you have with multiple ifs is a maintenance problem. Unfortunately it is difficult if you use one button to set the operation, enter the numbers, and then use the “=” button to do the calculation. You will end up with code like this:-If you are feeling ambitious, there is a much more object‑oriented solution. Look in the Java® Language Specification, where you will find a ready‑made calculator application , which you can alter to suit your requirements.
 
Piet Souris
Saloon Keeper
Posts: 3250
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell wrote:How can you have two classes with the same name in the same package? More likely there is another class called JFrame, minus the setDefaultCloseOperation() method.


Unlikely. But wanna make a bet on it?    
 
Campbell Ritchie
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:. . . Unlikely. But wanna make a bet on it?    

This is BJ where the unlikeliest things in the programming universe happen

I shall move this discussion to the GUIs forum.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!