Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to receive notify

 
David Chan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have encountered a problem that if I code in this way, the getController()method always get null because the dialog is still waiting the user to
public class AFrame extends JFrame {
public void aMethod() {
operatingModeDialog = new OperatingModeDialog(this);
}
}
public class operatingModeDialog extend JDialog
{

public action
}
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

I have encountered a problem that if I code in this way, the getController()method always get null because the dialog is still waiting the user...

I cannot see your code posted, but I guess you can do it in this way.
1. When the system starts, a dialog pops up.
(This is the ONLY thing the system does during starts up)
2. After the user input some configurations, check it.
3. Start the GUIController only after the system makes sure the config is correct.
In this way, you will not have the case that, when the system waiting for the user input, it creates some object instances too early.
Nick.
 
David Chan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The previous message I posted does not contain the whole question. It is my mistake to send a incomplete message because I pressed tab (want to new a line) and space, then the form was submited...
My GUI design is to create a dialog and let the user to select Network mode or Non-network mode. The code is shown as below: (Any code which is not related to the problem is removed)
public class AFrame extends JFrame {
public void aMethod() {
OperatingModeDialog operatingModeDialog
= new OperatingModeDialog(this);
/*** Here is the problem ***/
Controller controller = operating.getController();
}
}
public class OperatingModeDialog extend JDialog
implements ActionListener
{
private Controller controller;
JButton connectButton;
public OperatingModeDialog(JFrame frame) {
super(frame);
connectButton = new JButton("Connect");
connectButton.addActionListener(this);
...
}

public actionPerformed(ActionEvent e) {
if (e.getSource() == connectButton) {
controller = new Controller();
}
...
}
public Controller getController() {
return controller;
}
}
However, I have encountered a problem that if I code in this way, the getController() method always get null because the dialog is still open and waiting the user to select the operating mode. The controller instance at that moment have not created yet. How can receive a notify to know the dialog closed? or is there another solution to solve this problem? Thanks for your help.

David
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
As I said before, I do not care how the code be, in order to avoid the problem, you should change your design, so that the connection will only be get AFTER the connection is made.
For your code, I think you can fix it in this way:

AFrame class has a private member Controller, and it is instantiated ONLY AFTER connect button is clicked, and the connection is done.
By doing so, you can forsee that the controller will NOT be null after connect, and the exception will not be thrown in aMethod().
Nick.
[ December 30, 2003: Message edited by: Nicholas Cheung ]
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is the change I made to the above code correct? Otherwise I don't know what the "operating" object is.
I think the problem may be that you never close the dialog when you handle the connect button press. I imagine that when the user presses the Connect button you wish the dialog to close. So for instance,

That's my guess anyway.
- George
[ December 31, 2003: Message edited by: George Marinkovich ]
 
Terry Martinson
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or another way to do something like George suggested at the end of his post:

TJ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic