Nested classes and GUI integration
I have a GUI class called ArenaHelperGUI and an ArenaHelperRunner that's supposed to store the data taken from the text fields in the GUI and later do some calculations on it. The GUI is nested within the runner, but it can't do anything to the runner's variables, or call its functions.
Here's the runner:
package arenahelper;
* @author Greg
public class ArenaHelperRunner {
ArenaHelperGUI gui;
String args[];
String[] oneTwo;
String[] fourFive;
String[] sixSeven;
String[] nineTen;
String[] elevenTwelve;
String[] fourteenFifteen;
String[] sixteenSeventeen;
String[] nineteenTwenty;
ArenaHelperRunner()
gui = new ArenaHelperGUI();
gui.main(args);
oneTwo = new String[4];
fourFive = new String[4];
sixSeven = new String[4];
nineTen = new String[4];
elevenTwelve = new String[4];
fourteenFifteen = new String[4];
sixteenSeventeen = new String[4];
nineteenTwenty = new String[4];
public void test()
System.out.println("TEST");
} The GUI was generated by Netbeans, and it's supposed to interact with the variables in the runner when one of the buttons is pressed:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
test();
System.out.println(oneTwo[0]);
} The call to test and println both give "cannot find symbol".
If anyone knows how to fix this or can suggest a better way to implement it, I'll be very grateful =)
farshmak wrote:
I have a GUI class called ArenaHelperGUI and an ArenaHelperRunner that's supposed to store the data taken from the text fields in the GUI and later do some calculations on it. The GUI is nested within the runner, but it can't do anything to the runner's variables, or call its functions.
ArenaHelperRunner()
gui = new ArenaHelperGUI();
gui.main(args);
oneTwo = new String[4];
fourFive = new String[4];
sixSeven = new String[4];
nineTen = new String[4];
elevenTwelve = new String[4];
fourteenFifteen = new String[4];
sixteenSeventeen = new String[4];
nineteenTwenty = new String[4];
}Spot the magic number. I suggest setting a variable size = 4 and initializing each array to size. It will make your code more elegant and easier to maintain.
The call to test and println both give "cannot find symbol".Its good to separate the GUI and logic however you can't call a non static method from Class A within Class B without instantiating an instance of Class A first.
e.g. within Class B
ArenaHelperRunner runner = new ArenaHelperRunner();
runner.test();Mel
Similar Messages
-
Nested Classes and Static Methods
I was perusing the Java Tutorials on Nested Classes and I came across this...
[http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html|http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html]
I was reading the documentation and I read a slightly confusing statement. I was hoping some further discussion could clarify the matter. The documentation on "Nested Classes" says (I highlighted the two statements, in bold, I am having trouble piecing together.)
Static Nested Classes
As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class ? it can use them only through an object reference.
Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
int i;
static class Bar {
int j = i; // WRONG! Bar class is static context
}~ -
Compiling Nested Classes and Interfaces
I am looking for documentation about compiling nested classes and interfaces. I have found something in the JVM Specification, but there does not explain how a nested class is compiled and what is included in the top level class to mark a "place holder" to the nested class. The JVM Specification in this topic cite the web page http://java.sun.com/products/jdk/1.1/docs/guide/innerclasses/spec/innerclasses.doc.html that does not exists any more.
My root problem is that: I am compiling a class with a private nested class, but in the class file generated TopLevelClass$NestedClass.class the class does not have the private modifier. So I am not understanding why the "private" modifier was removed during compilation.
I performed the same test with a protected nested class and the result was the nested class with the public modifier. So I am not understanding why the "protected" modifier was changed to "public".
Thanks in advance,
Mardoqueu.This should not be happening. What compiler are you using? If it's a reasonably recent Sun compiler, could you post a minimal example?
-
Nested classes and separate files in Javadoc...
Hello. I am writing an application, and it has several .java files, and some of the classes contained therein contain nested classes, for example
ClassOne.java
class ClassOne
// stuff
class innerClassOne
//more stuff
}ClassTwo.java
class ClassTwo
// stuff
class innerClassTwo
//more stuff
}What I want to do is generate documentation like the online java documentation for my app, that is, documentation that will contain ALL the classes and nested classes involved, and link everything that comes in java already to the sun online java docs.
I've figured out the -link command for javadoc, and I can make that work, but I've run into some other snags.
1.) Javadoc isn't finding or documenting my nested classes, despite them being marked up. Google does not wish to help.
2.) Some classes reference other classes of mine that aren't conatined in the same .java file, but do exist in their own .java files in the dame local directory. Javadoc does not like this, and gives errors.
3.) Running javadoc on one file at a time overwrites the old file's documentation, thus I cannot seem to get an index.html javadoc file that links to all my classes, nor can I get the classes to link to each other.
What do I need to do to fix these?So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
int i;
static class Bar {
int j = i; // WRONG! Bar class is static context
}~ -
Extending a nested class and parent access
I want the child of the abstract inner class to have access to the inner classes parent's variables. I know that an inner class can access it's parent's variables and methods with the "[ParentClass].this.[var/method]" syntax. What's the appropriate syntax for the situation I'm describing?
My setup is like this:
class Canister {
int a = 0;
public abstract class Behavior
class Lonely Behavior extends Behavior
public int getParentVariable() {
return Canister.this.a;
}Thanks!
-stephenThe correction to my code is:
class Canister
int a = 0;
public abstract class Behavior
class LonelyBehavior extends Canister.Behavior
public int getParentVariable() {
return Canister.this.a;
}The compiler doesn't have a problem with me extending Canister.Behavior because it's public inside of Canister. But as I explained, the "[ParentClass].this.[var/method]" syntax doesn't work.
This is inconsistent with inheritance: you'd think that if you extend an inner class, you would inherit the abilities and characteristics of that inner class, just as you would in other cases of inheritance. It's also inconvenient: if the inner class is abstract because you want programmers to extend and upgrade it, those programmers have to change the source code of the enclosing class to include the new classes.
Anyway, thanks for the info. -
JIT compiler and nested classes
Q1. how does JIT compile on fly and improve the performance ?
Q2. how is system.out.println(argument) implemented in java ? is it that system is a class in which out is a static nested class and println is a static method in out?Hello rishiluvsjava,
Q1. How does JIT compile on fly and improve the performance?
The following answer was taken from "The Java HotSpot Performance Engine Architecure: A White Paper About Sun's Second Generation Performance Technology" to view the full document go to:
http://java.sun.com/products/hotspot/whitepaper.html
Just-In-Time (JIT) compilers are essentially fast traditional compilers that translate the Java-technology bytecodes into native machine code on-the-fly. A JIT runs on the end-user's machine which actually executes the bytecodes, and compiles each method the first time it is executed.
Q2. How is System.out.println(argument) implemented in java ? is it that system is a class in which out is a static nested class and println is a static method in out?
From the Java docs:
System is a public final class in the java.lang package. It has three fields:
static PrintStream err // The "standard" error output stream.
static InputStream in // The "standard" input stream.
static PrintStream out //The "standard" output stream.println is one of the methods in the java.io.PrintStream class.
-Merwyn,
Developer Technical Support,
http://www.sun.com/developers/support. -
Static nested class VS non-static nested class ??
we know static method can be called without creating an object and static variables are shared among objects.
what is the difference between static nested class and non-static nested class ? When do we use them? what is the advantages of static nested class over non-static nested class in term of performance?From the JLS, chapter 8:
A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.
This chapter discusses the common semantics of all classes-top level (?7.6) and nested (including member classes (?8.5, ?9.5), local classes (?14.3) and anonymous classes (?15.9.5)).
So "nested" iff "not top level".From the JLS, chapter 8:
An inner class is a nested class that is not explicitly or implicitly declared static.
So a "static" nested class is a bit redundant, since a "non-static" nested class -- a nested class is either static or it isn't -- is more specifically referred to as an "inner class". That's my story and I'm sticking to it. :o)
~ -
Trying to pass parameters between GUI classes and methods
Hi All.
I have been working on a rather large final year project in college and it is getting close to the deadline. It looks as though I need to "tidy up" my code as it contains too many static methods, variables and other bad programming habits. My package consists of many different GUI's and classes. Up until now I have been calling different GUI's with guiName.NameOfMethod. I have been told this is bad practice so I am trying to fix this. Also instead of passing parameters correctly I have been creating static variables in my main class and using them. So for example if one class needed to pass a variable to the other I would first myGlobalVariable = X; in the first class. And then the second class can use this. This is also bad, right?
So I guess im really just looking for a good example or tutorial on how to pass parameters between classes and methods, GUI if possible. Here is an example of how my GUI classes look:
public class anotherGUI extends JFrame implements ActionListener {
private JTextField a, b, c;
private JButton button1, button2;
JPanel p, p1;
public anotherGUI() {
LayOutAnotherGUI();
setLocationRelativeTo(DnDMain.pictureArray[a]);
setTitle("Example");
setVisible(true);
pack();
private void LayOutAnotherGUI(int c) {
//GUI is layed out here
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == submit)
clickOK();
public void clickOK(){
//Here is where I have been accessing and modifying static global variables. (But this needs to change).
public void showanotherGUI() {
new anotherGUI();
}This is more or less how I have been going about creating my GUI's. These are used as pop ups. The user enters a value and then it is closed.
To be honest I have been able to pass a variable correctly from one class to a GUI class but I have still having difficulty. For example in my code above I can pass the variable into this class but I cannot pass it into clickOK(). An this is where it is needed.
Can anyone please help?
I hope I have explained my problem well.
Thanks in advance.I dont think that is what I need. An example of what I do in my program is:
I have a main GUI with an array of images. There are a number of other small GUI's that appear for certain functions when the user clicks on an image or does some other function. I am trying to pass a value into the GUI class that is used for the smaller "pop up" GUI. So lets say the user has clicked the image in array[12]. Then a GUI is displayed. I need to pass the integer 12 into this class.
Thanks. -
ABAP DT for OS X: problems with GUI integration
Anyone there able to make it work on OS X? Your help will be much appreciated.
I've tried HANA Studio bundled from SAP, vanilla Juno and Kepler installations with tools.hana.ondemand.com repos and cannot make the SAP GUI integration to work in any of them.
Every time I select option "Open with SAP GUI" I receive the empty tab and error message in log:
Unable to create class 'org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor' from bundle '1154'
Unhandled event loop exception
and so on.
I have to GUIs installed 7.20rev11 and 7.30.Now, it works for me.
Previously I have had updated the Java SE 7 only (Default with java.com site) But the JDK version is needed. I have now installed JDK 1.7-51 and SAPGUI 7.30rev7 and it works fine. -
Oracle Portal and Discoverer Integration
Portal Version: 9.0.2.0.1
RDBMS Versjion: 9.0.1.3
OS/Vers. Where Portal is Installed:: Suse 7 SLES
Error Number(s)::
Oracle Portal and Discoverer Integration
We're trying to integrate Discoverer with Portal unsuccessfully.
We made many things in accordance with oracle's documentation until add discoverer portlets (worksheet and list of workbooks) in a test page.
In view mode, the worksheet portlet shows the error:
"The portlet has not been defined. The publisher must define the portlet by clicking on Edit Defaults for the portlet on the edit mode of this page. Please contact the publisher of this page."
We think we have to edit properties before. Is this? Anyway edit worksheet portlet crashes between step 1 and 2. The error is: "The listener returned the following Message: 500 Internal Server Error".
We have a public conection created in EM and a discoverer application which can be viewed using plus or viewer.
Furthermore, it's not possible delete the added portlets neither the page that contain it. The error at delete is:
Error: An unexpected error occurred: User-Defined Exception (WWC-44082)
(WWC-00000)
An unexpected error has occurred in portlet instances: User-Defined Exception (WWC-
44846)
An unexpected error occurred: User-Defined Exception (WWC-43000)
The following error occurred during the call to Web provider:
oracle.portal.provider.v2.PortletNotFoundException
at oracle.portal.utils.v2.ContainerException.fillInStackTrace(Unknown Source)
at java.lang.Throwable.<init>(Throwable.java:78)
at java.lang.Exception.<init>(Exception.java:29)
at oracle.portal.utils.v2.ContainerException.<init>(Unknown Source)
at oracle.portal.provider.v2.PortletException.<init>(Unknown Source)
at oracle.portal.provider.v2.PortletNotFoundException.<init>(Unknown Source)
at oracle.disco.portlet.provider.DiscoPortletPersonalizationMgr.destroy
(DiscoPortletPersonalizationMgr.java:65)
at oracle.portal.provider.v2.DefaultPortletInstance.deregister(Unknown Source)
at oracle.webdb.provider.v2.adapter.soapV1.ProviderAdapter.deregisterPortlet
(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at oracle.webdb.provider.v2.utils.soap.SOAPProcessor.doMethodCall(Unknown Source)
at oracle.webdb.provider.v2.utils.soap.SOAPProcessor.processInternal(Unknown Source)
at oracle.webdb.provider.v2.utils.soap.SOAPProcessor.process(Unknown Source)
at oracle.webdb.provider.v2.adapter.SOAPServlet.doSOAPCall(Unknown Source)
at oracle.webdb.provider.v2.adapter.SOAPServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
at com.evermind.server.http.ResourceFilterChain.doFilter
(ResourceFilterChain.java:59)
at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:283)
at com.evermind.server.http.ServletRequestDispatcher.invoke
(ServletRequestDispatcher.java:523)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal
(ServletRequestDispatcher.java:269)
at com.evermind.server.http.HttpRequestHandler.processRequest
(HttpRequestHandler.java:735)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:151)
at com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:64)
(WWC-43147)
Edit properties for portlet List of Workbook works but in view mode we have the error in the portlet area:
"Failed to refresh portlet. Please verify that the information used to create the
portlet instance or customization is still valid. Otherwise, please contact your
iAS administrator. oracle.discoiv.controller.FatalControllerException:
DiscoNetworkException - Nested exception: org.omg.CORBA.OBJECT_NOT_EXIST: minor
code: 0 completed: No null"
Any ideas?
ThanksHi there,
Have you applied any patches to 9ias since it was first installed? We had the same problem and had to apply a couple of patches to get the portlets working.
1. Apply the 9.0.2.53.16 one-off patch for Oracle 9iAS Discoverer which takes Discoverer up to 9.0.2.53.16. This patch appears to be password protected and you need to get someone at Oracle support to give you a password.
2. Apply the Discoverer Portlet Provider: 9.0.2.53.00c patch (patch no. 2595444) which gives you a new discportal.xsl file that actually works. It's this second step that solves your problem but you need to do step 1 before this. This is password protected as well.
3. As you've upgraded Disco on the server to 9.0.2.53, you'll need to upgrade Disco Admin & Desktop within your 9iDS installation using patch no. 2555265. This is because Disco 9.0.2.53 uses an upgraded EUL that Disco Admin & Desktop need to be patched to use.
This was the course of action Oracle support advised us about nine months ago. Of course they may have released a further patch to Disco that does 1 & 2 in one go, but we regularly carry out steps 1 and 2 on servers we use and we can use the Disco portlets successfully.
Hope this helps
Mark Rittman
[email protected] -
Question regarding MM and FI integration
Hi Experts
I have a question regarding MM and FI integration
Is the transaction Key in OMJJ is same as OBYC transaction key?
If yes, then why canu2019t I see transaction Key BSX in Movement type 101?
ThanksNo, they are not the same. The movement type transaction (OMJJ) links the account key and account modifier to a specific movement types. Transaction code (OBYC) contains the account assignments for all material document postings, whether they are movement type dependent or not. Account key BSX is not movement type dependent. Instead, BSX is dependent on the valuation class of the material, so it won't show in OMJJ.
thanks, -
Question about the property of the nested class.
"Nested classes may be declared static. In this case, the nested class has no reference to an enclosing instance"
Can any one demonstrate the above through an code example?? thanksthanks jverd.
Then why dont you answer my other thread??You have several threads. I've said what I have tosay in all the ones that I know about, am interested
in, and have the time to answer. Last one I lookedat, you were in Monica's very capable hands, so I had
nothing to add.
Thanks!I may not be the sharpest knife in the drawer, but I know better than to piss of her what's gonna administer the dread Blueberry Pie Torture. -
Flex RPC mapping Java nested classes to ActionScript classes
We are calling a Java method in our project using
RemoteObject the value returned by the java method is a ArrayList
containing instances of a class say ParentClass with some nested
classes.
The structure of ParentClass(Java) is something like this
class ParentClass {
//some primitives
private ChildClassA childAInstance;
private ChildClassB childBInstance;
//getters setters
We have created similar class structure on the ActionScript
side, the ActionScript classes(ParentClass,ChildClassA
,ChildClassB) have been properly annotated with the [RemoteClass]
metadata tag,
The problem is that though i'm getting the primitive data
members of the ParentClass through RPC in my corresponding AS
ParentClass class i'm getting an runtime exception trying to access
ChildClassA,ChildClassB members.
Am i missing something, exactly the same scenario is
mentioned in this article
http://www.adobe.com/devnet/flex/articles/complex_data.html
But the Object.registerClass method mentioned in the tutorial
is giving me compilation error, the sample code attached with the
article is corrupt zip too.
Please help me out on thisJAXB will create classes from an XML schema, SAX is a parser library and JAXP is a library of XML a bunch of XML tools.
I don't care for JAXB too much. I would skip it and go right to the JAX-RPC spec (WebServices). -
Loading XML using a custom class and accessing it from other classes?
I began with a class for a movie clip rollover function
FigureRollOver. It works marvellously. Three things happen:
1) it loads XML from a file "mod1_fig1.xml" and uses another
class, XMLMember, to retool the scoping of the XML so that I can
get at it
2) an onload call inside of XMLMember calls the myOnLoad
function and transfers the XML into an array.
3) so long as the array is finished building, rolling over a
movie clip attaches a new movie clip with the rollover text in it.
But I don't want all those functions in one because I need it
to be more dynamic, starting with being able to load any old xml
file instead of just "mod1_fig1.xml", plus it seems like
overbuilding to have all of that in one class, so I've separated
out the loading of the XML and building of the array into its own
class, FigureXMLLoader. FigureRollOver is then left to just attach
the rollover with text in it, extracted from the array built by the
new class.
Problem is, though the array builds inside FigureXMLLoader, I
can't figure out how to make it available outside the class. I know
that I'm constructing things in the wrong order, and that the array
needs to be somehow built inside the class function to be
available, but I can't figure out how to do that. A cruddy
work-around is to put a function call at the end of the building of
the array, which calls yet ANOTHER function on the main timeline of
my .swf to put the array I've just built into a new variable. This
works, but it's messy. It seems like I should be able to have one
line of script in the .swf that generates an array on the main
timeline (or just a public array) which I can then access from my
FigureRollOver class:
var myRollOvers:Array = new FigureXMLLoader("mod1_fig1.xml");
Here is FigureXMLLoader (see comments in the code for more
details) which obviously does not return an array as it is, because
of all the working around I've had to do. Note the "testing"
variable, which can be traced from the main timeline of the .swf,
but I will get "not what I want" because of course the array hasn't
been built yet, and never will be, inside of the declaration as it
is. How do I get it in there so I can return an array?
Thanks!Suggest you ask this question in the Actionscript forum as
this forum is
more tuned to database integration questions.
You can create arrays outside a class and pass them into it
by reference and
visa versa build arrays inside a class and pass out via
reference.
The preferred approach is to place the array in a class and
not expose it.
Then add methods to use the array or should we say to use the
class.
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
"maija_g" <[email protected]> wrote in
message
news:ed4i43$9v0$[email protected]..
> Update: I've now put this on the main timeline of the
.swf:
>
> myRollOversLoaded = false;
> var myRollOvers:Array;
> var roll_content = new FigureXMLLoader("mod1_fig1.xml");
>
> And inside the "myOnLoad" function in FigureXMLLoader,
just after the
> while
> loop I've put this:
>
> _root.myRollOversLoaded = true;
> _root.myRollOvers = figure_arr;
>
> The movie clip rollover won't act until
myRollOversLoaded is true. It
> works,
> but it still seems klugey. Any suggestions for a more
elegant solution
> would be
> appreciated.
> -
When we will go for an abstract class and when we will go for an interface?
it's always some what confusing to choose an abstract class and an interface,can anybody post a suitable answer for this.
jwenting wrote:
with experience and the insight it brings, you will know which to use when.
Without it, it can't be explained.
More often than not there's no X OR Y anyway.It's fortunate that there are posters here who possess the insight and experience necessary to explain this. The principal differences between an abstract class and an interface are,
1. An abstract class can carry implementation, whereas an interface cannot.
2. An abstract class is singly inherited, wheras an interface is multiply inherited.
So use an abstract class when the implementation it can carry outweights the fact that it cannot be multiply inherited That's the gist of it.
The inheritance relationship where this happens is when the supertype is a general concept of which all potential subtypes are special cases. This is called a specialization (or sometimes a generalization) relationship. For example Apple and Banana are Fruit. Or Car and Bike are Vechicle. The Fruit and Vechicle supertypes are general concepts of which their subtypes are special cases. In this case make Fruit and Vechicle abstract classes because the subtypes will benefit from a shared implementation.
If you don't have a clearcut specialization/generalization relationship make the supertype an interface. An example could be the Comparable supertype. The potential subtypes aren't supposed to be specializations of the Comparable concept, they're suppose to become Comparable (and make this property an integral part of their being). This is not a specialization/generalization relationship. Instead the supertype is intended to add character to the subtypes. The subtypes are unlikely to benefit from an inherited implementation. So make Comparable an interface.
Maybe you are looking for
-
WebGain, Inc. Launches WebGain Studio(TM) a Powerful Integrated E-Commerce Development Solution VisualCafe and Other Industry Leading Products Help Customers Rapidly Build E-Businesses CUPERTINO, Calif., March 22 -- WebGain Inc., today announced WebG
-
Compilation problem with JSP: i am sure this is easy but cant figure out
this is my jsp file: <@ page import="java.sql.*, com.simpleneasy.*" errorPage="error.jsp"; %> <jsp:useBean id="c" class="ConnectionBean"></jsp:useBean> <html> <% String sql = "select * from test;"; ResultSet rs; c.establishConnection()
-
Why I must send payment information (credit card number) if the app is free (gratis)?
-
VIP folder vs. Smart Mailbox Folder - Why won't they behave similarly?
My poorly formatted question is this. Why in the VIPs folder you can view ALL the emails in one view from the people you add to this list when you click on the root VIPS text...HOWEVER...when you create a Smart Mailbox Folder like "Employees" and the
-
Free Mountain Lion for mbp september 2012?
My son bought a macbook pro in september 2012. It came with lion. He realized he should have Mountain Lion and contacted Apple but apparently the program to get this installed for free has been cancelled in march 2013. He never was notified of this.