wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Problems with Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problems with Method" Watch "Problems with Method" New topic
Author

Problems with Method

Joe Pettit
Ranch Hand

Joined: Aug 16, 2012
Posts: 33

Hi everybody! I'm having a bit of trouble with a refresh table method (to refresh a jtable) I've wrote - here's what I have:



The method works just fine when called within the same class (mainWindow) but when I try to call it from another class (addAssignment) the method does not seem to work. The class seems to be instantiated properly...



Am I doing this wrong - or is there something I'm not considering here? Thanks for any help / insight you folks can provide!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Well, updating the table in a new mainWindow is hardly likely to affect an already existing mainWindow.

By the way, learn to follow the Java coding conventiona. Class names should start with an uppercase letter.


luck, db
There are no new questions, but there may be new answers.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7520
    
  18

Darryl Burke wrote:By the way, learn to follow the Java coding conventiona. Class names should start with an uppercase letter.

And tokenizedAssNames might lead one to believe that there are peculiar practises going on at your company...particularly as it's an array.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Joe Pettit
Ranch Hand

Joined: Aug 16, 2012
Posts: 33

Darryl Burke wrote:Well, updating the table in a new mainWindow is hardly likely to affect an already existing mainWindow.

By the way, learn to follow the Java coding conventiona. Class names should start with an uppercase letter.


Doh! Wow, I hadn't even considered that...would there be another way of doing what I'm trying to do?

Btw, thanks for the info on the naming convention - I realize I've been doing it wrong and I do plan to go back through and fix everything using proper naming convention.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Joe Pettit wrote:Doh! Wow, I hadn't even considered that...would there be another way of doing what I'm trying to do?


Well, there's the normal way where you get "main" to contain a reference to the MainWindow you want to update, and then call its updateTable method. There might be other ways but there's really no point in looking for them when the normal way is simple and straightforward.
Joe Pettit
Ranch Hand

Joined: Aug 16, 2012
Posts: 33

I've been trying to figure out how I can accomplish what I'm trying to do but I'm having trouble. I have an instance of the mainWindow class running and I need to pass this to the addAssignment class. I've tried a couple combinations of "this" but nothing seems to work properly. Can anybody point me towards information on the syntax to accomplish this?

Currently, the addAssignment accepts an instance of mainWindow as an argument - but I would need to pass the current instance of the mainWindow class to the addAssignment class to call the updateTable method appropriately.

Thanks again!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Joe Pettit wrote:Currently, the addAssignment accepts an instance of mainWindow as an argument - but I would need to pass the current instance of the mainWindow class to the addAssignment class to call the updateTable method appropriately.


Okay. So you need a controller to go along with your model and view components. The controller could be the code which sets up the other components, but at any rate it needs to have a reference to your MainWindow object (the current instance you referred to, although I don't see why there would be more than one instance) and a reference to the AddAssignment object (not the class, the object is going to do the work).

Then the controller would simply call the method of the AddAssignment object and pass it the reference to the MainWindow object.
Joe Pettit
Ranch Hand

Joined: Aug 16, 2012
Posts: 33

Paul Clapham wrote:
Joe Pettit wrote:Currently, the addAssignment accepts an instance of mainWindow as an argument - but I would need to pass the current instance of the mainWindow class to the addAssignment class to call the updateTable method appropriately.


Okay. So you need a controller to go along with your model and view components. The controller could be the code which sets up the other components, but at any rate it needs to have a reference to your MainWindow object (the current instance you referred to, although I don't see why there would be more than one instance) and a reference to the AddAssignment object (not the class, the object is going to do the work).

Then the controller would simply call the method of the AddAssignment object and pass it the reference to the MainWindow object.


I refer to a particular instance of the class because of the way netbeans seems to initialize GUI elements. I call the mainwindow from a splashscreen class (which just displays a splash screen) - this is a new instance of the mainwindow object. The mainwindow class has this code for it's main method:



This creates a new instance of the mainwindow object which is throwing me off. I originally attempted to pass the mainwindow object created in the splashscreen class from that class, to the mainwindow class, and then from the mainwindow class to the addassignment class, which should achieve what I'm trying to do. But because of how netbeans initializes the class above, a new instance is created when the mainwindow main method is called. So I'm passing instance A, but the instance shown is actually instance B - so I'm trying to figure out how to send instance B.

I've never really heard of the controller class you suggested below - is this an implementation of a class that already exists or is it just a concept of what I need to do?

Thanks for your help Paul - I really appreciate it! I've learned a lot here so far :)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8



Here you are creating a new "mainWindow" object which is going to be part of your GUI. Code in other classes, you say, needs to work with this object. But you aren't even keeping a reference to it, so no other objects can possibly work with it.

Creating another mainWindow object isn't going to be helpful, because that second object isn't the one you need to work with. So if you have other code which works with "mainWindow", it shouldn't create any more objects. It should just work with the one you already have.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Joe Pettit wrote:I've never really heard of the controller class you suggested below - is this an implementation of a class that already exists or is it just a concept of what I need to do?


Model–view–controller
Joe Pettit
Ranch Hand

Joined: Aug 16, 2012
Posts: 33

Paul Clapham wrote:

Here you are creating a new "mainWindow" object which is going to be part of your GUI. Code in other classes, you say, needs to work with this object. But you aren't even keeping a reference to it, so no other objects can possibly work with it.

Creating another mainWindow object isn't going to be helpful, because that second object isn't the one you need to work with. So if you have other code which works with "mainWindow", it shouldn't create any more objects. It should just work with the one you already have.


Woohoo! Success! I can't believe I overlooked that! Thanks so much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with Method
 
Similar Threads
JTable renderer - Change the backColor of 2 specific rows.
how to pass input to java program using ant ?
need help regarding POI workbook ?
Clone JTable
JTable, reloading the table...