• 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

object references as an instance variable in a class; setting default size of JFrame

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all --

Just reading the chapter on serialization, and one of the pages mentions an instance variable that is an object reference.

Could someone give me some examples of this?  Maybe I forgot about this, but I'm just curious how one could put an object reference is an instance variable.  

Also, how would you set the default size of a JFrame to the screen size of your computer, like my MB pro?
Staff note (Paul Clapham) :

It would be helpful if the second question here could be posted as a separate question in the Swing forum.

 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A "String" variable is a reference to a string.
 
Christopher Laurenzano
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it possible to include a reference to an specific object of a class you created?  May be a stupid question, but just curious.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes but if you want the including class to be serializable then the reference needs to also refer to a serializable class.
 
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

Christopher Laurenzano wrote:is it possible to include a reference to an specific object of a class you created?  May be a stupid question, but just curious.



The type of a variable is either a primitive type (int, char, double, long, byte, boolean, float, or short.) or else it's a reference type. If it's the latter, then the variable can contain either the null value or a reference to an object of that type. You seem to feel like there's all kinds of restrictions stacked up around that rule. But no. The type can be anything defined by anybody, and the variable can refer to any object of that type, no matter how it was created and where it came from.
 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christopher,

and instance variable is a non static variable that is global inside of he class itself, if you define that same variable as static it becomes a class variable.  you can make it a reference to any object.



for an example of where an instance variable is a reference to the same class of object look at Linked Lists, each next is a reference to the next object and is of the same type of object.

btw: the Toolkit lines in JTitleJunk() is how you get the dimensions of your screen... lookup Toolkit in the API.
 
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic