• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with Method

 
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Joe Pettit
Ranch Hand
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 33
C++ Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic