0

I am trying to make a form page in a java applet. Now after making textbox and submit button, how can I validate this text-box? Anyone if can tell me if I can link JS code to applet and if yes, then how?

package com.tcs.applet;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

import javax.swing.JButton;

public class MyApplet extends Applet  { 
TextField inputLine = new TextField(15);  
private JButton button = new JButton("Submit");
public MyApplet() {
    add(inputLine);
   add(button);
}
}

2 Answers 2

0

Package netscape.javascript provides Java code(your applet code) the ability to access the JavaScript engine in the web browser.

for more info you can check following

Netscape Doc

0

On the action performed of the JButton do your validation.

If there is wrong input in textfield then throw a acception.

4
  • Thanks...Means I need to validate it here in applet code only or shall I create a seperate JS file for that including this function? Dec 6, 2013 at 7:37
  • Yes, Validate it here only. That is good practice for learner.
    – AJ.
    Dec 6, 2013 at 7:39
  • I have to start countdown in next page and this countdown shud start from the digit entered in the textbox. For example, if I enter 8, then countdown should start from 8 in the new window, down to 0 and then the window should get closed automatically.. I am not getting any idea regarding this... :( Plz help. Dec 6, 2013 at 8:09
  • for that you need thread.Read the data from textfield using getText(). Parse your getText() output into Integer. Now give this integer value to your window. Apply thread implimentation in your window. use sleep() method of thread and keep dicreasing the counter. If counter reaches to 0 then dispose your window using dispose() method.
    – AJ.
    Dec 6, 2013 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.