java - ACM Interactors Freeze -
i'm trying make simple program swing , acm interactors. taken directly class handout, not function on computer. when run it, functions fine half second, briefly flashes, reloads, , button , text-field functionality lost. here's code:
import acm.program.*; import java.awt.event.*; import javax.swing.*; public class textfieldexample extends consoleprogram { public void init() { namefield = new jtextfield(15); add(new jlabel("name: "), south); add(namefield, south); namefield.addactionlistener(this); } public void actionperformed(actionevent e) { if (e.getsource() == namefield) { println("hello, " + namefield.gettext()); } } private jtextfield namefield; }
if helps, i'm using java se 1.6 eclipse helios service release 2 on mid-2010 mac pro running mac osx 10.8.4
as workaround, in addition using java 1.5, add field north
. also, may want extend graphicsprogram
.
modified sscce:
import acm.program.*; import java.awt.event.*; import javax.swing.*; public class textfieldexample extends graphicsprogram { @override public void init() { namefield = new jtextfield(15); add(new jlabel("name: "), north); add(namefield, north); namefield.addactionlistener(this); } @override public void actionperformed(actionevent e) { if (e.getsource() == namefield) { println("hello, " + namefield.gettext()); } } private jtextfield namefield; }
Comments
Post a Comment