Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Hello and Help :p

Name: Anonymous 2007-10-14 13:41

Hello. My name is AxeFalador. I am a newcomer to Java programming.

Now, on to what I need help with.

I'm currently working on my very first fully function Java Swing GUI Application, using Matisse on NetBeans 5.0.

I am writing your basic "electronic magic 8-ball" GUI, with the goal that the user types in a yes/no question in a JTextField, and clicks a JButton, and the program displays, in a separate JTextPane, an answer randomly chosen from a pool of pre-composed answers.

I have programmed a few basic functions into the GUI, but I can't get the last few bumps rolled out, so to speak. I have a fully functional exit button, and the "Ask..." button (the JButton that's supposed to generate the random answer in the separate JTextPane) has only one answer it can display in the JTextPane. I can't seem to figure out just how to make the JTextPane display randomly selected answers when the "Ask..." JButton is clicked. I can only figure out how to display a single answer.

Here is what I have for code, so far (most of it was automatically generated by NetBeans' Matisse GUI Builder):

/*
* cyberspaceoracleui.java
*
* Created on October 13, 2007, 1:37 PM
*/

package my.cyberspaceoracleui;

/**
*
* @author  falador@eastlink.ca
*/
public class cyberspaceoracleui extends javax.swing.JFrame {
  
    /** Creates new form cyberspaceoracleui */
    public cyberspaceoracleui() {
        initComponents();
    }
  
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                        
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("The CyberSpace Oracle");
        jLabel1.setText("Greetings, my dear.");

        jLabel2.setText("What queries dost thou haveth for me this fine day?");

        jLabel3.setText("Please ask only yes/no questions.");

        jButton1.setText("Ask...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextPane1.setEditable(false);
        jScrollPane1.setViewportView(jTextPane1);

        jButton2.setText("Farewell");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel4.setText("Your answer will be displayed below...");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap(10, Short.MAX_VALUE)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton2)))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel4))
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jLabel2))
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jLabel3))
                    .add(layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jButton1)))
                .addContainerGap())
        );

        layout.linkSize(new java.awt.Component[] {jButton1, jButton2}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel4)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton2)
                .addContainerGap())
        );

        layout.linkSize(new java.awt.Component[] {jButton1, jButton2}, org.jdesktop.layout.GroupLayout.VERTICAL);

        pack();
    }// </editor-fold>                      

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        jTextField1.setText("");
        jTextPane1.setText("I'm sorry, my dear, but I am just not mentally prepared to answer that question, right now. Please ask again later.");
    }                                      

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        System.exit(0);
    }                                      
  
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cyberspaceoracleui().setVisible(true);
            }
        });
    }
  
    // Variables declaration - do not modify                    
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration                  
  
}


Any tips, help or advice you could give me would be greatly appreciated! 

Name: Anonymous 2007-10-14 14:07

Wow, that looks very ENTERPRISE.

A)  Don't use Swing.
B)  Don't use Java.
C)  Your name is not AxeFalador.

Name: Anonymous 2007-10-14 14:09

Terrible excuse for a troll or terrible excuse for a human being?

Only one way to find out...


SAGE

Name: Anonymous 2007-10-14 14:36

>>3
How DARE you sage MY thread!?

Name: Anonymous 2007-10-14 14:57

Autogenerated code is TEH BEST

Name: Anonymous 2007-10-15 5:21

bump

Name: Anonymous 2007-10-15 6:08

To learn more about Touhou:
1- Download the windows games in http://www.tsukuru.info/_th_/

2- While downloading, go to the Touhou Wiki(http://www.pooshlmer.com/touhouwiki/index.php/Touhou_Wiki) to know more about the games.

3- Go to the Touhou Image Board(http://pooshlmer.com/wakaba/wakaba.html) and the Maidens of the Kaleidoscope forums (http://www.shrinemaiden.org/forum/index.php)

4-???????????

5- PROFIT!

Name: Anonymous 2007-10-15 7:48

huh

Name: ​​​​​​​​​​ 2010-10-21 19:24

Name: ​​​​​​​​​​ 2010-10-22 15:34

Name: Anonymous 2010-12-17 1:22

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: 2012-01-25 7:19


Don't change these.
Name: Email:
Entire Thread Thread List