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...

public class DataStore
{	
	public int count;
	
	public DataStore()
	{
		count=0;
	}
}
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);
	}
}
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.

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 { ... }
               ...
       }
}

i actually found a buch of info on model/view architecture and rewrote the whole thing. cheers for the tip anyway, much appreciated

This article has been dead for over six months. Start a new discussion instead.