I have an application in C# that I am converting to Java, specifically the C# version consists of a Windows Form (Main Form) that spawns a new form (Secondary Form) via the ShowDialog() method.
The event handler for a button (OK) on the Secondary form sets it's DialogResult to OK when clicked, therefore in the Ma开发者_如何学运维in Form I can check what DialogResult was set and retrieve data from the Secondary Form instance through properties.
I'm using SwingUI with NetBeans and I was wondering how I would go about implementing the same functionality in the Java application.
An example:
The Box to be displayed (Secondary Form):
The behaviour for the Secondary Form:
Then a simple piece of code in the Main Form to get the results:
As you can see it doesn't really take a lot of effort to achieve this in C#, how big of a task would it be to do it in Java?
Thanks for your time.
A dialog that returns a String:
String s = (String)JOptionPane.showInputDialog(
frame,
"Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"ham");
Taken from the Swing Dialog tutorial. You can create a more complex dialog by subclassing the JDialog class and creating accessor methods to get the data.
精彩评论