Results 1 to 4 of 4
- 05-16-2011, 02:07 PM #1
switch data between jfram and jdialog
hi all ,
i have a class InventoryGUI in that i'm implements Observer and from the update method i'm updating the jtable row with new values.
in the InventoryGUI i'm calling a LIstener class which extends observable and it addobserver with the values that are getting from a socket program.
if a client send a data to a pport that is listening by the LIstener class.
i had added a button to start the listening see the code in the class InventoryGUI
Java Code:if (jButton1.getText().trim().equals("Start Listening")) { jButton1.setForeground(Color.red); jButton1.setText("Stop Listening"); listner = new Listner(); Observer observer = new InventoryGUI(); listner.addObserver(observer); thread = new Thread(listner); thread.start(); }
and LIstener implements Runnable
so it start lisning the port and when the data came it call setChanged() and notifyObservers(data);
ok that will show the value in the jtable's 1st column
ok
now i add a new tab and it will call a class InventorySales
that class when calling it will also do the same
Java Code:listner = new Listner(); Observer observer = new InventorySales(); listner.addObserver(observer); thread = new Thread(listner); thread.start(); }
but if this code is added in my that pop up a jdialog window and show the data that are listening ,but it shows "Address already in use: JVM_Bind"
if i changed listner = new SalesListner(); maeans a new class for that listening then also the same eror
and if i send data to the second (jdialog) the data will go to the first frame InventoryGUI ,but the button on InventoryGUI is not clicked then there is no problem
so how can i recognise that the if jdialog is popup then the observer has to send data to the jdialog
please expalin me correctly ,i hope all of you go my problem
thanks in advanceLast edited by Fubarable; 05-17-2011 at 12:59 AM. Reason: code tags added
-
I'm not sure I fully understand what you're doing and what your problem is, but I suspect that you want both Obsevers to listen to the same Observable and this may not be happening because you are creating another Observable. It seems that your Listner variable, listner is a class field, and that you initialize it when jButton1 is pressed (please rename this variable to something that makes sense since "jButton1" tells us and you nothing about the button's function). The problem may be coming when you create a new Listner object in your second bit of code, and then start a new thread with this object. What if you don't create a new object and use the current one and just add your new Observer to it, perhaps something like so?:
Java Code:if (listner != null) { // listner = new Listner(); Observer observer = new InventorySales(); listner.addObserver(observer); // thread = new Thread(listner); // thread.start(); } else { // your listner is null and perhaps you do need to create a new one and start a thread. }
Best of luck!
- 05-17-2011, 09:49 AM #3
i will clear the problem
thanks for reply
See class A implemts runnable and in run method accepts the values from a port in that setchanged and notifyObservers(data); methods are there.
class B implements Observer which uses a button and onclick will call the thread to start like this
Java Code:listner = new Listner(); Observer observer = b; listner.addObserver(observer); thread = new Thread(listner); thread.start();
in the same class B a jmenuitem on select
just call new C().main();(where C is another class and for the eas of use remove the String args[] from the main)
and in the main()
Java Code:c= new C(); Listner listner = new Listner(); Observer observer = c; listner.addObserver(observer); // used the same listner Thread thread = new Thread(listner); thread.start(); c.setVisible(true);
what is the problem and how can i correct it
thanks in advance
-
Did you read my reply? Have you tried what I suggested?
Similar Threads
-
I am trying to use the enter button from the jscroll so that it can link to the jfram
By mad_indian1 in forum AWT / SwingReplies: 1Last Post: 03-28-2011, 07:19 AM -
JDialog
By frenk_castle in forum AWT / SwingReplies: 3Last Post: 05-11-2010, 01:28 PM -
how to make Broswe button in jfram form to attache file
By ibrahimyoussof in forum AWT / SwingReplies: 3Last Post: 04-12-2010, 09:40 PM -
Returning data from a JFrame/JDialog?!
By Joe2003 in forum AWT / SwingReplies: 6Last Post: 01-08-2009, 01:14 AM -
help with jdialog
By leonard in forum AWT / SwingReplies: 1Last Post: 08-05-2007, 06:37 AM
Bookmarks