开发者

Display one form and return text to another - Java

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):

Display one form and return text to another - Java

The behaviour for the Secondary Form:

Display one form and return text to another - Java

Then a simple piece of code in the Main Form to get the results:

Display one form and return text to another - Java

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜