java - Using JTextField in a JApplet -
this first time messing japplet.. i'm trying make jtextfield() work properly... no matter cant show on page!
import java.awt.*; import javax.swing.*; public class hangman extends japplet{ private static final long serialversionuid = -3966472303224962681l; public void paint(graphics g){ super.paint(g); container c = getcontentpane(); jtextfield input = new jtextfield(20); c.setbackground(color.black); g.setcolor(color.white); g.setfont(new font("arial", font.bold, 30)); g.drawstring("welcome hagman applet web!", 20, 30); g.setfont(new font("arial", font.italic, 18)); g.drawstring("also available on android.", 20, 50); c.add(input); input.gettext(); } }
you should not add components applet in "paint" method. f.e. in constructor:
public hangman() { container c = getcontentpane(); c.setbackground(color.black); jtextfield input = new jtextfield(20); c.setlayout(new borderlayout()); c.add(input, borderlayout.south); }
Comments
Post a Comment