java - I need to hold this window until the done button has been pressed :/ -
the first code here comes prerec of main code cannot figure out.
boolean companyloaded, startingnum = true; firstcheck newwin = new firstcheck(); public collectnumbers() { if (startingnum = true) firstcheck = newwin.firstcheck(); <----runs firstcheck okay if (companyloaded = true) loadcompany();
from here on out have firstcheck class i'll post below. have tried abstract overiding actionperformed, have tried thread sleep, wait, , cannot figure out how firstcheck() method wait until actionperformed() homecoming string(int). help appreciated!
import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.io.*; import java.util.*; abstract class firstcheck extends jframe implements actionlistener { static int num; static boolean bnum = true; jtextfield numberentry; toolkit tools = toolkit.getdefaulttoolkit(); dimension windowlocvar = tools.getscreensize(); public int firstcheck() { jframe frame = new jframe(); numberentry = new jtextfield(); jbutton done = new jbutton("done"); done.addactionlistener(this); jlabel label = new jlabel("starting check number?"); label.setverticaltextposition(jlabel.bottom); label.sethorizontaltextposition(jlabel.center); jpanel panel = new jpanel(); panel.setlayout(new gridlayout(3,1)); panel.add(numberentry); panel.add(label); panel.add(done); frame.add(panel); frame.pack(); frame.setvisible(true); frame.setsize(250,150); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setlocation(windowlocvar.width/2-300,windowlocvar.height/2-100); //try { // thread.sleep(5000); // } //catch(interruptedexception e) { // // restore interrupted status // thread.currentthread().interrupt(); // } } public int actionperformed(actionevent e) { bnum = false; num = integer.parseint(numberentry.gettext()); homecoming num; } }
instead of jframe frame = new jframe()
utilize jdialog frame = new jdialog((frame)null, true)
.
this create modal dialog block code execution @ the point of of frame.setvisible(true)
until dialog closed.
take @ how utilize dialogs more information.
in actionperformed
method, need store "return" value can interrogated application 1 time dialog closed...
public void actionperformed(actionevent e) { bnum = false; num = integer.parseint(numberentry.gettext()); object source = e.getsource(); if (source instanceof component) { // close dialog.... swingutilities.getwindowancestor((component)source).dispose(); } }
updated
equally, utilize joptionpane
instead...
take at
display array in joptionpane joptionpane , reading integers - beginner javaas couple of examples
java swing user-interface actionlistener
No comments:
Post a Comment