# Textbox problem in java applet!



## kntsoe (Jan 22, 2008)

When i run the java applet in browser, the first two characters of the text box /text field can't be seen.
Pls let me know why .
eg . t.setText("Happy World);
Ha can't be seen at runtime.
ur help would be much appreciated.
Best Rgds,
kntsoe


----------



## NeonFx (Oct 22, 2008)

Hi there. Could you copy and paste the relevant parts of your code for me? I need to know what Class you are using for the text field GUI and the applet's paint method to determine where the problem lies. It is most probably just that you set your text field to be painted in such a way that its first two characters are "off grid".

Heres a very simple applet with text:



> import java.awt.Graphics; ​ public class SimpleJavaApplet extends java.applet.Applet {​  public void paint(Graphics g) {​  g.drawString("This is a simple java applet!", 5, 25);​  }​ }​


And the HTML:



> ​ Hello to Everyone!​ ​
> 
> My Java applet says:​ ​ ​ ​


----------



## kntsoe (Jan 22, 2008)

Thanks a lot for ur interest in helping with this.Here's my code.

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

public class SimpleTextField extends Applet {
Button b= new Button("Set text");
TextField t = new TextField("Starting text",30);
String s = new String("abc");
public void init() {
add(b);
add(t);
}
public boolean action(Event evt, Object arg) {
if(evt.target.equals(b)) {
t.setText("Inserted String " +s);
}
return super.action(evt,arg);
return true;
}
}

here's the applet code

and i also want to know the detail instructions to create .jar file.
pls also help me about this. )))))))))
wish u a very happy and prosperous new year
kntsoe


----------



## JimmySeal (Sep 25, 2007)

The first two letters can't be seen because the text box is wider than your applet. So make the applet wider, make the text box smaller, or use a layout manager that takes care of the component sizes.

Also, the action() method was deprecated in 1997 and you shouldn't use it. Instead, have your applet implement the ActionListener interface and call b.addActionListener(this) in the init() method.


----------



## kntsoe (Jan 22, 2008)

hello ,
yes, i made the applet wider and my problem was solved.
thanks a lot for ur help and ur advice.
best regards,
kntsoe


----------

