Hi! I have made a POS Sotware. I have used only one JFrame as Main/Home Screen of the software and used JDialogs for all other screens.
In this post I have concern with the 2 screens; Home Screen(which is a Jframe) and Sales Screen(which is a JDialog). As Home Screen appears I instantiate an instance of the Sales Screen in the constructor of Home Screen as :

Sale sale = new Sale();

And on Pressing a Button on Home Screen I called :

sale.visible(true);

In the WindowOpened Event of the "Sale" Screen I load the products data from database and populates a JComboBox. This all works perfectly.

But I face problem , when I dispose() the Sales Screen and Add a new Item on the "Products" Screen and when Return to Sales Screen , that new Item is not added to JComboBox. And I know that's because of window has opened only once, and constructor of sale has called only once.

But I want such a mechanism that when I dispose the "Sale" Screen and Add or delete new products by going to "Products" Screen, When I return to Sales Screen (By pressing the Button on Home Screen) Then the new item should be added to the JComboBox, i-e data should be refreshed and loaded into jComboBox. Kindly guide me how can I achieve this thing? Thanks in advance.

I saw this topic briefy late last night (C.E.S.T.) and it seemed odd. Now in the morning it still seems odd. It's not at all clear what is the problem here.
Whenever you add or delete products you need to update the combo box's contents (add or remove an item, or simply re-load the whole contents). What is it about that that is causing you difficulty?

commented: Thanks for your response James. I have added another reply and explained the problem in detail. Kindly go through it. +3

James bro, consider I have 3 screens, "Home" Screen, containing Menu Buttons, "Items" Screen where user can add or delete his products and "Sale" Screen where user can Sell his Items.
Home Screen is a JFrame and other two screens are JDialogs. I have two buttons on The Home Screen named "Manage Your Items" and "Sale your Items" , By pressing these buttons above mentioned JDiaolgs are opened (i-e "Items" Screen and Sale Screen)." All the items that are available in a table in "Items" Screen are also available in a ComboBox on "Sale" Screen.
When My "Home" Screen instantiates, I initializes the Sales Dialog as follows:

Sale sale = new Sale();

And when the button "Sale your Items" is pressed on Home Screen, The following code runs:

sale.visible(true);

After this code The "Sale" Screen(which is a JDialog) appears. This means that The" WindwoOpened event" of the "Sale" Screen has called. I overrides the "windowOPened Event" and loads all the Products data in ComboBox of "Sale" Screen. This all works perfectly.
But now consider I dismiss/close the "Sale" Screen by calling following code in the "WindowClosing Event Handler" of the Sale Screen:

setVisible(false);
    dispose();

And go to the "Items" Screen and add one more new Item successfully and dismiss/close the "Items" Screen, by calling :

setVisible(false);
dispose();

And go to the "Sale" Screen again by Pressing the "Manage Your Items" button on the Home Screen, the "Sale" Screen becomes visible again but now the ComboBox of "Sale "Screen has not the new Item that I has recently added, It has only previous Items. I hope You understand my problem. If not, then tell me, I will give you my software file so that you can run the file yourself and see the problem.
I will be thankful to you for your guidance.

OK, I get that.
Although the sale window is not visible, it still exists, with all its components. So you can update the contents of its combo box at any time. So when you add or remove items you need to update the combo box immediately. Then whenever you display the sale window the combo box will be up to date.
You just need to ensure that the code where you add or remove items has access to the combo box object... there are multiple ways to do that, which we can discuss if you want.

Yes I want to discuss those methods by which I can access the JcomboBox on the sales Screen from another window or Dialog.

You can start by considering these three options to see which fits your needs best...

  1. Make it public. Very easy, but horrible violation of encapsulation
  2. Have a public method (or methods) in Sale that updates the combo box - eg addItem(Item i) removeItem(Item i). A bit more code, and it encapsulates nicely, but creates an untidy dependency between the main Item list and the Sale window.
  3. Use a Listener/Observer pattern so the Sale window adds itself as a listener to wherever the master list of Items is held. This is the best architecture - classic MVC - but the most code.

Thanks James, For today, I have used your 2nd Mehtod/option i-e making public functions update(item) and remove(item).
But in future I want to use your 3rd Method/option i-e Adding the Sales screen as a listener itself. For this I want an example code or tutorial, if you can provide me, then I will thankful to you.

Sure. I'll get something together tomorrow. Goodnight. J

OK. Step 1: Separate the data from the user interface - ie separate the Model from the View.
You should have a class that loads and holds the master list of Items and has public methods for adding and removing items, getting items etc. It has no UI. The windows should be passed the manager instance into their constructors so they can use it to access whatever data or functionality they need.

Thank you very much James. I understood very well.

Great!
Let me know if/when that's done and I'll help you get the Listener stuff working.
JC

Yes I have done this. But I don't know , how to mark "Solved" this question

Click on "Reply to this topic" and there's a "Question Solved" slide switch at the bottom.

Thanx James Cherill. James cherill I have faced a new problem, I am posting that problem here. I will be thank full to you if you guide me on that.

Now I am making my pos software client - server based software. I am using java derby as the database. On the local host I am running the program successfully. But on the remote server I face an exception. First I tell you, how I am connecting to the remote server below:

I connect my laptop to my pc through LAN Cable. I am using my laptop as client and my desktop PC as Server. On my Server I run the following command to start the Derby Server:

C:\Program Files (x86)\Java\jdk1.7.0_79\db\lib> java -jar derbyrun.jar start server

Above mentioned command starts the derby server on my desktop computer.

I am using following driver and connection string on my client laptop:

// code for driver
String dbdriver = "org.apache.derby.jdbc.ClientDriver";
        Class.forName(dbdriver).newInstance();

// connection string where "192.168.10.125" is ip address of my server PC and "139" is port number of   //my server PC
 con = DriverManager.getConnection("jdbc:derby://192.168.10.125:139/C:\\QuintexDB; create = true"); 

When I run the program, following Exception Occurres:

"java.sql.SQLNonTransientConnectionException: Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 5 bytes. The connection has been terminated."

I am searching this problem on internet since last night but all in vane. I will be thank ful to you if you can guide me on this.

commented: When you have an issue solved, yes, mark it solved. New issue? New post please. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.