X-Received: by 10.66.228.162 with SMTP id sj2mr14775809pac.11.1405986127326; Mon, 21 Jul 2014 16:42:07 -0700 (PDT) MIME-Version: 1.0 Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h18no5291622igc.0!news-out.google.com!j6ni11103qas.0!nntp.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 21 Jul 2014 18:42:07 -0500 From: iMatt Subject: Re: Swing actions in separate code files - how Newsgroups: comp.lang.java.gui X-UserIpAddress: X-InternalId: 52817d70-fc91-4b76-90d3-18b201077a57 References: <2qtju5F13feioU1@uni-berlin.de> Message-ID: Date: Mon, 21 Jul 2014 18:42:07 -0500 Lines: 54 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-drRv2jZo48Jw5LI15QGcAsifotqe/InEauK69F2CKPKypJGByhjv2LpeTuYtEBpdmgquyu55uKT7Cgg!HGrhF3zSpJ4FxOt/aedbuvpoLcxEA+n5LttUdWr2YUhvHu1bcx7E5ylxC4QrLE2+XjNGNC+0ufHQ!HQ== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2753 Xref: csiph.com comp.lang.java.gui:5442 I discovered a method which allows a central class to provide data access to satellite classes. I needed a method to separate code into several files, and this has proven effective. The satellite classes have full data access to all but private variables, and can directly change data in the central class. This concept has been tested successfully on a large scale project. See what you think about it. // Get the access of global while retaining priveleges. // You can access variables in one class from another, with provisions. // The primitive must be protected or no modifier (seen in example). // the first class public class farm{ int eggs; // an integer to be set by constructor fox afox; // declaration of a fox object // the constructor inits farm(){ eggs = 4; afox = new fox(); // an instance of a fox object // show count of eggs before the fox arrives System.out.println("Count of eggs before: " + eggs); // call class fox, afox method, pass myFarm as a reference afox.stealEgg(this); // show the farm class, myFarm, primitive value System.out.println("Count of eggs after : " + eggs); } // end constructor public static void main(String[] args){ // instance of a farm class object farm myFarm = new farm(); }; // end main } // end class // the second class public class fox{ // theFarm is the myFarm object instance // any public, protected, or "no modifier" variable is accessible void stealEgg(farm theFarm){ --theFarm.eggs; } } // end class iMatt -- http://compgroups.net/comp.lang.java.gui/