Win a copy of Event Streams in Action this week in the Java in General 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Calling function

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am calling function in one class from another class. The Class 1(Answer1 in below code) allows user to enter their answer in the text box. Once the answer is entered and submit button is clicked I want the control to come back to jeopardy class from where it is called and continues with the next step.
From Jeopardy when I am calling a.an() the control does not come back ansd execute the next step which is String input = a.get_s(); In Jeopardy class,  I  need help .

Thank!

Below is the code....

 
Marshal
Posts: 65057
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch sorry nobody has replied earlier.

Nice to see properly indented code, but I think some of your lines (146‑152) are too long. Rather than using drawString(), consider using a JLabel with all the help text passed as a constructor argument.
I am afraid there is a lot more to say, most of it not good.
Why are you using an Applet? Applets are obsolete.
I think you have some other design problems about how many classes you have. There are very few instances where you should inherrit from a GUI display class. And it is usually a bod idea to make display classes implement ActionListener. It is better to add an action listener to a button. It is also usually a bad idea to make a display class play a game.
I think you need to change a lot:-
  • 1: Write the game in its own classes. Get it working without any GUI classes at all.
  • 2: Make sure you have enough classes. Lines 115‑136 don't suggest object‑orientation to me. I would have a Player class, with a certain number of instances, and a way of moving those instances into and out of play as they take turns.
  • 3: Make your methods much much smaller. If you have a ten‑line method, try and refactor it into two five‑line methods.
  • 4: No static variables. I don't know whether that is the cause of your problem, but it is a mistake to make anything static without a good reason.
  • 5: Make all fields except those used as global constants private.
  • 6: No GUIs until all that lot is working. Only then should you even think of a GUI.
  • You only need one Scanner instance per application, so I often make Scanners static, but why are you using a Scanner at all? If you have a GUI, use that to receive any information from the users.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!