| | |
basic java GUI problem
![]() |
•
•
Join Date: May 2005
Posts: 2
Reputation:
Solved Threads: 0
ive been trying to figure this out for hours, and would appreciate any help. im clumsy with java, have only really had c++ experience and am at a bit of a loss trying to figure out GUI's, my problem goes like this.....
basically i need to create different frames or windows that can access the same data, its pretty obvoius from the code what im trying to do... if someone can give me a hand or some advice i would GREATLY appreciate it...
my 2 problems are:
why are the buttons from the first frame (test1) still there after setting tpo.setVisible(false)
and....
how can i access the same DataStore object (D1) from the second form (test2)
elegance of code is not an issue, neither is encapsulation or good programming practice, i just need it to work.....
any help would be GREATLY appreciated.....
apollogies if i made no sense but its late and this has been driving me mad...
basically i need to create different frames or windows that can access the same data, its pretty obvoius from the code what im trying to do... if someone can give me a hand or some advice i would GREATLY appreciate it...
Java Syntax (Toggle Plain Text)
public class DataStore { public int count; public DataStore() { count=0; } }
Java Syntax (Toggle Plain Text)
import BreezySwing.*; import javax.swing.*; public class test1 extends GBFrame { public DataStore D1; JButton testButton = addButton ("test" ,1,1,1,1); JButton anotherButton = addButton ("anotherTEST" ,2,1,1,1); public test1() { D1 = new DataStore(); } public void buttonClicked(JButton buttonObj) { if(buttonObj==testButton) { D1.count++; messageBox(D1.count); } if(buttonObj==anotherButton) { test2 gpo = new test2(); gpo.setSize(500,500); gpo.setVisible(true); this.setVisible(false); } } public static void main (String args[]) { test1 tpo = new test1(); tpo.setSize(500,500); tpo.setVisible(true); } }
Java Syntax (Toggle Plain Text)
import BreezySwing.*; import javax.swing.*; import DataStore.*; //import test1.*; public class test2 extends GBFrame { JButton test2Button = addButton ("<<test2>>" ,3,1,1,1); public void buttonClicked(JButton buttonObj) { if(buttonObj==test2Button) { D1.count--; messageBox(D1.count); } } }
my 2 problems are:
why are the buttons from the first frame (test1) still there after setting tpo.setVisible(false)
and....
how can i access the same DataStore object (D1) from the second form (test2)
elegance of code is not an issue, neither is encapsulation or good programming practice, i just need it to work.....
any help would be GREATLY appreciated.....
apollogies if i made no sense but its late and this has been driving me mad...
You can define one of tthose frames as an inner class under another one with private access (Actually you can't make an inner class public). THen you can use D1 in both of them. And you can use the constructor of the public one to instantiate the inner frame class. might sound silly but it would work i guess.
Java Syntax (Toggle Plain Text)
import BreezySwing.*; import javax.swing.*; public class test1 extends GBFrame { .... DataStore D1; public test1 { ... test2 tmp = new test2 ....} .... private class test2 extends GBFrame { .... D1. whatever // Inside a method surely public test2 { ... } ... } }
![]() |
Similar Threads
- Java / GUI Developer Needed (UK) (Software Development Job Offers)
- java gui libraries (Java)
- Java GUI problem... contents of JFrame is invisible... (Java)
- two Java GUI problems - please help (Java)
Other Threads in the Java Forum
- Previous Thread: arrays
- Next Thread: what does this error mean
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows





