views:

199

answers:

3

Is it possible to capture the text of say a Edit Box or Label control on a Java Applet?

In a more traditional Win32 program this can be accomplished using FindWindow, FindWindowEx together with things like GetWindowText.

I have investigated with WinSpy but the Java Applet is just one large window with no children.

I am wondering if there is some similar method, perhaps specific to Java, that we could use for a Java Applet.

Thanks.

A: 

You need to look up the API docs for javax.swing.JLabel and javax.swing.JTextArea. These are the classes that implement a text box or a label. These classes provide mechanisms for getting the value from the controls.

For example:

    String val = myText.getText();

Will get the text entered in the text area.

Vincent Ramdhanie
Apologies. I probably should have made it clear that I am needing to do this from an external program. In my case, a C# .NET program.Also the Java Applet is not "ours" so we can't modify it in any way.
NathanE
A: 

This information should be available for accessibility. I am not a Microsoft platform person, but there is the Java Access Bridge for Microsoft Windows.

Tom Hawtin - tackline
Just in case there is something screwy around what your trying to do, and the Bridge won't work. The other option in this case would be to use JNI. So you can use a dll to pass the info from Applet to OS. This would prob be over complicated but still another option.
Knife-Action-Jesus
A: 

For example u created

private JLabel lblText; lblText= new JLabel("Hello World");

to get text from the label:

lblText.getText();

to set text;

lblText.setText("new text");

Jason