basic java GUI problem

Reply

Join Date: May 2005
Posts: 2
Reputation: callow is an unknown quantity at this point 
Solved Threads: 0
callow callow is offline Offline
Newbie Poster

basic java GUI problem

 
0
  #1
May 16th, 2005
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...

  1. public class DataStore
  2. {
  3. public int count;
  4.  
  5. public DataStore()
  6. {
  7. count=0;
  8. }
  9. }

  1. import BreezySwing.*;
  2. import javax.swing.*;
  3.  
  4. public class test1 extends GBFrame
  5. {
  6.  
  7. public DataStore D1;
  8.  
  9. JButton testButton = addButton ("test" ,1,1,1,1);
  10. JButton anotherButton = addButton ("anotherTEST" ,2,1,1,1);
  11.  
  12. public test1()
  13. {
  14. D1 = new DataStore();
  15. }
  16.  
  17. public void buttonClicked(JButton buttonObj)
  18. {
  19. if(buttonObj==testButton)
  20. {
  21. D1.count++;
  22. messageBox(D1.count);
  23.  
  24. }
  25. if(buttonObj==anotherButton)
  26. {
  27. test2 gpo = new test2();
  28. gpo.setSize(500,500);
  29. gpo.setVisible(true);
  30. this.setVisible(false);
  31. }
  32. }
  33.  
  34. public static void main (String args[])
  35. {
  36. test1 tpo = new test1();
  37. tpo.setSize(500,500);
  38. tpo.setVisible(true);
  39. }
  40. }

  1. import BreezySwing.*;
  2. import javax.swing.*;
  3. import DataStore.*;
  4. //import test1.*;
  5.  
  6. public class test2 extends GBFrame
  7. {
  8. JButton test2Button = addButton ("<<test2>>" ,3,1,1,1);
  9.  
  10. public void buttonClicked(JButton buttonObj)
  11. {
  12. if(buttonObj==test2Button)
  13. {
  14. D1.count--;
  15. messageBox(D1.count);
  16. }
  17. }
  18. }

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...
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 10
Reputation: miri is an unknown quantity at this point 
Solved Threads: 0
miri miri is offline Offline
Newbie Poster

Re: basic java GUI problem

 
0
  #2
May 19th, 2005
You can use static objects
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 30
Reputation: yassar is an unknown quantity at this point 
Solved Threads: 0
yassar's Avatar
yassar yassar is offline Offline
Light Poster

Re: basic java GUI problem

 
0
  #3
May 19th, 2005
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.


  1. import BreezySwing.*;
  2. import javax.swing.*;
  3.  
  4. public class test1 extends GBFrame {
  5.  
  6. ....
  7. DataStore D1;
  8. public test1 { ... test2 tmp = new test2 ....}
  9. ....
  10.  
  11. private class test2 extends GBFrame {
  12. ....
  13. D1. whatever // Inside a method surely
  14. public test2 { ... }
  15. ...
  16. }
  17. }
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 2
Reputation: callow is an unknown quantity at this point 
Solved Threads: 0
callow callow is offline Offline
Newbie Poster

Re: basic java GUI problem

 
0
  #4
May 20th, 2005
i actually found a buch of info on model/view architecture and rewrote the whole thing. cheers for the tip anyway, much appreciated
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC