what i'm trying to do is create a basic question box that can be reused and already its looking imposable ( the reused part and the return info to the main program
i have it set so that i call the classthen on the next line instead of the 6 0ther things u'd normal use u'd just tell it to make the QBoxQBox q = new QBox();but when i try to get the answerq.ask("the question");it come out blank . and even after it shows it doesn't show the next questionSystem.out.println(q.awnser);q.ask("new question");
heres the 2 codes i have ( 1 was mostly generated with visual swing for eclipse )
test/main
package userInterface; public class Test { public static void main(String[] args){ QBox q = new QBox(); q.ask("Will this work?"); System.out.println(q.awnser); q.ask("this never even runs :( "); } }
package userInterface; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.UIManager; import org.dyno.visual.swing.layouts.Bilateral; import org.dyno.visual.swing.layouts.Constraints; import org.dyno.visual.swing.layouts.GroupLayout; import org.dyno.visual.swing.layouts.Leading; import org.dyno.visual.swing.layouts.Trailing; //VS4E -- DO NOT REMOVE THIS LINE! public class QBox extends JFrame { private String question = ""; public String awnser =""; private static final long serialVersionUID = 1L; private JButton jButton0; private JTextField jTextField0; private JLabel jLabel0; private static final String PREFERRED_LOOK_AND_FEEL = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"; public QBox() { } // this is where i started editing public void ask(String q) { installLnF(); // ----- moved this from the main this.question = q; setLayout(new GroupLayout()); add(getJButton0(), new Constraints(new Trailing(12, 30, 250), new Trailing(9, 64, 64))); add(getJTextField0(), new Constraints(new Bilateral(12, 83, 6), new Trailing(12, 38, 38))); add(getJLabel0(), new Constraints(new Leading(12, 307, 12, 12), new Leading(12, 40, 44, 44))); setSize(331, 92); this.setDefaultCloseOperation(QBox.EXIT_ON_CLOSE); // ------ as well as all of these below here this.setTitle("Question"); this.getContentPane().setPreferredSize(this.getSize()); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); } private JLabel getJLabel0() { if (jLabel0 == null) { jLabel0 = new JLabel(); jLabel0.setText(question); } return jLabel0; } private JTextField getJTextField0() { if (jTextField0 == null) { jTextField0 = new JTextField(); } return jTextField0; } private JButton getJButton0() { if (jButton0 == null) { jButton0 = new JButton(); jButton0.setText("Send"); jButton0.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent event) { jButton0MouseMouseReleased(event); } }); } return jButton0; } private static void installLnF() { try { String lnfClassname = PREFERRED_LOOK_AND_FEEL; if (lnfClassname == null) lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName(); UIManager.setLookAndFeel(lnfClassname); } catch (Exception e) { System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL + " on this platform:" + e.getMessage()); } } // -------- and this should close the window and set the awnser var to what was in the text box private String jButton0MouseMouseReleased(MouseEvent event) { this.setVisible(false); this.removeAll(); return jTextField0.getText(); } }