java - Displaying text in a field -
i making simple true or false quiz game, dont know text field should use display quiz questions. tried jtextfield can edit text in it.. want question strings taken question class , displayed in text area.
quiz class
public class quiz { private jframe frame; private jbutton yesbutton; private jbutton nobutton; /** * creates game interface */ public quiz() { makeframe(); } /** * receive notification of action. */ public void actionperformed(actionevent event) { system.out.println("menu item: " + event.getactioncommand()); } /** * quits application. */ private void quit() { system.exit(0); } /** * pop up. */ private void about() { joptionpane.showmessagedialog(frame, "quiz game version 1.0", "about quiz", joptionpane.information_message); } /** * pop up. */ private void howtoplay() { joptionpane.showmessagedialog(frame, "this simple quiz game answer questions pressing yes or no buttons", "how play", joptionpane.information_message); } /** * enable's or disable's buttons. */ private void setbuttonsenabled(boolean status) { yesbutton.setenabled(status); nobutton.setenabled(status); } /** * creates frame , content. */ private void makeframe() { frame = new jframe("quiz"); container contentpane = frame.getcontentpane(); makemenubar(frame); //jpanel jpanel panel = new jpanel(); panel.setlayout(new gridlayout(1, 0)); yesbutton = new jbutton("true"); panel.add(yesbutton); nobutton = new jbutton("false"); panel.add(nobutton); contentpane.add(panel,borderlayout.center); // end of jpanel //score jlabel label = new jlabel("score: "); contentpane.add(label, borderlayout.north); //end of score //combo box jcombobox noofplayers = new jcombobox(); contentpane.add(noofplayers, borderlayout.south); noofplayers.additem("1 player"); noofplayers.additem("2 player"); noofplayers.additem("3 player"); noofplayers.additem("4 player"); noofplayers.additem("5 player"); // end of combo box // // //shows frame , places frame @ center of screen frame.pack(); setbuttonsenabled(false); //makes application start in center of screen dimension d = toolkit.getdefaulttoolkit().getscreensize(); frame.setlocation(d.width/2 - frame.getwidth()/2, d.height/2 - frame.getheight()/2); frame.setvisible(true);
you can't edit text in jtextfield if call seteditable(false)
. can't tab onto if call setfocusable(false)
on well.
edit
ask:
where set it? tried jtextfield qtext = new jtextfield(seteditable(false)); not working.. or have make new method , call method?
your qtext field should private instance field. can call methods in quiz class's constructor.
Comments
Post a Comment