cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

JLink - Need help with button action listener

MikePhillips
5-Regular Member

JLink - Need help with button action listener

I'm new to JLink and JAVA (and programming). I'm trying to create a
simple GUI for testing/learning. My program creates a simple window
with a button. When I click the button I want a JOptionPane dialog to
pop up displaying the name of the current model in session.



When I click the button the program locks up. If I comment out the
try-catch portion, the "Hello World" works fine so that leads me to
believe the listener is working properly. If I leave the GUI portion of
the program out and place the try-catch code in the start() method, the
message box pops up as expected. Which leads me to believe that portion
of the code is correct. I just can't seem to combine the two. I hope I
have explained this properly.



I hope someone can clue me in on what I'm doing wrong.





My code to register a listener with the button:



JButton goButton = new JButton("GO");

goButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e){

runGoButton();

}

});



My runGoButton() code:



public static void runGoButton(){



try {

Session session = pfcGlobal.GetProESession();

String curModel =
session.GetCurrentModel().GetFileName().toUpperCase();

JOptionPane.showMessageDialog(null, "Model name is: " +
curModel);

}



catch (jxthrowable ex) {

}



JOptionPane.showMessageDialog(null, "Hello World!");

}





Thanks



Mike Phillips



The information contained in this message is privileged and intended only for the recipients named. If the reader is not a representative of the intended recipient, any review, dissemination or copying of this message or the information it contains is prohibited. If you have received this message in error, please immediately notify the sender, and delete the original message and attachments.
1 REPLY 1
MikePhillips
5-Regular Member
(To:MikePhillips)

I think I figured it out. I searched through some old postings and discovered that GUIs for JLink must be modal. I was using a JFrame (which is not modal). I changed my window to a JDialog and used "window.setModal(true);" to make the dialog modal. Now it works!



In Reply to:

I'm new to JLink and JAVA (and programming). I'm trying to create a
simple GUI for testing/learning. My program creates a simple window
with a button. When I click the button I want a JOptionPane dialog to
pop up displaying the name of the current model in session.



When I click the button the program locks up. If I comment out the
try-catch portion, the "Hello World" works fine so that leads me to
believe the listener is working properly. If I leave the GUI portion of
the program out and place the try-catch code in the start() method, the
message box pops up as expected. Which leads me to believe that portion
of the code is correct. I just can't seem to combine the two. I hope I
have explained this properly.



I hope someone can clue me in on what I'm doing wrong.





My code to register a listener with the button:



JButton goButton = new JButton("GO");

goButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e){

runGoButton();

}

});



My runGoButton() code:



public static void runGoButton(){



try {

Session session = pfcGlobal.GetProESession();

String curModel =
session.GetCurrentModel().GetFileName().toUpperCase();

JOptionPane.showMessageDialog(null, "Model name is: " +
curModel);

}



catch (jxthrowable ex) {

}



JOptionPane.showMessageDialog(null, "Hello World!");

}





Thanks



Mike Phillips



The information contained in this message is privileged and intended only for the recipients named. If the reader is not a representative of the intended recipient, any review, dissemination or copying of this message or the information it contains is prohibited. If you have received this message in error, please immediately notify the sender, and delete the original message and attachments.
Announcements
Attention: Creo 7.0 Customers
Please consider upgrading
End of Life announcement here.

NEW Creo+ Topics:
PTC Control Center
Creo+ Portal
Real-time Collaboration