It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes communicating/affecting another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "communicating/affecting another class" Watch "communicating/affecting another class" New topic
Author

communicating/affecting another class

Andrew Evans
Greenhorn

Joined: Jun 16, 2011
Posts: 9
I am trying to develop a sudoku solver and have developed the GUI class and i want a seperate Button class which affects the 9x9
grid in the GUI class.
How does the communication take place is it through passing arguements via methods or some other way?

Any help would be gratefully appreciated.


GUI CLASS



BUTTON CLASS
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Andrew Evans wrote:How does the communication take place is it through passing arguements via methods?


Yes, that's how it should be done.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

If you've developed that GUI, adding an extra button should be a piece of cake.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38108
    
  22
If this is a GUI question, I shall move it to our GUIs forum.
Andrew Evans
Greenhorn

Joined: Jun 16, 2011
Posts: 9
The gui as it is does what i want it to do. My problem is trying to get the New Puzzle button to communicate with the GUI
from the ButtonControl class. Paul Clapham has said it is through arguements being passed via methods, but i'm
still not sure how it is to be done.

In the Button class do i need the public ButtonControl() part or is there another way of implementing this?

Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Is your ButtonControl class supposed to be a separate JFrame from your main application? Why does it extend Gui?

Do you want it to instantiate a new Gui, or just to start a new game? If the former, you will have a reference to the Gui from when you instanitate it, so you can call methods on it directly. If you create your ButtonControl instance from a Gui instance, you can give your ButtonControl constructor a Gui argument, and pass "this" in the constructor call. Then have your ButtonControl store this instance as a private variable, so it can reference its "parent".

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: communicating/affecting another class
 
Similar Threads
Sudoku grid shading
adding a picture
How can I get the GridLayout to work in this program
How do I access my field data?
Java text fields on a panel in a 2d array