13 Replies - 436 Views - Last Post: 31 May 2011 - 06:16 AM Rate Topic: -----

#1 lazyajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-May 11

Java not reading other IF statement

Posted 26 May 2011 - 06:05 AM

 if(DefinitionBox1 != VocabBox1){
            AnswerBox.setText("incorrect");
        }
        if(DefinitionBox1 == VocabBox1){
            AnswerBox.setForeground(Color.green);
        }   



Im trying to make a vocab program but when i do this to check if its right or wrong, the program only reads the first IF statement.
HELP!
Is This A Good Question/Topic? 0
  • +

Replies To: Java not reading other IF statement

#2 n8schatten  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 263
  • Joined: 07-December 10

Re: Java not reading other IF statement

Posted 26 May 2011 - 06:10 AM

Please post some more code.
What is the type of DefinitionBox1 and VocabBox1?
If they are Objects, you most probably don't wnt to use == (testing whether they are the same), but equals() (testing whether they are equal).
Was This Post Helpful? 1
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7644
  • View blog
  • Posts: 12,890
  • Joined: 19-March 11

Re: Java not reading other IF statement

Posted 26 May 2011 - 06:24 AM

if(DefinitionBox1 != VocabBox1)
{
AnswerBox.setText("incorrect");
}
if(DefinitionBox1 == VocabBox1)
{
AnswerBox.setForeground(Color.green);
}


Our shadowy friend is correct to point out that it's usually incorrect to use == or != with Objects - the only exception is when you want to establish whether the two objects are in fact the same objects, ie, two references to the same thing. (ie, the morning star== the evening star, since both are references to Venus)
If you want to test whether they are "equal" in the sense of meaning the same thing, then you have to use .equals


Now, how do you know the program is not reading the second if statement? In fact, you don't know that - as posted, the second if statement is read, period, but what makes you think that it's not reading it? Have you tried some tests? For example, replace the condition in the second if statement with if(true) and see what happens.
Was This Post Helpful? 0
  • +
  • -

#4 lazyajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-May 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 04:47 AM

 import java.awt.Color;
import java.util.*;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VocabPractice.java
 *
 * Created on May 18, 2011, 8:30:12 AM
 */

/**
 *
 * @author 5929578
 */
public class VocabPractice extends javax.swing.JFrame {

    /** Creates new form VocabPractice */
    public VocabPractice() {
        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.
     */
    @SuppressWarnings("unchecked")
     int temp;
     int[] Definition;

     Scanner scan = new Scanner (System.in);
     ArrayList Word = new <String> ArrayList();
     ArrayList definition = new <String> ArrayList();

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        five = new javax.swing.JRadioButton();
        ten = new javax.swing.JRadioButton();
        fithteen = new javax.swing.JRadioButton();
        VocabBox1 = new javax.swing.JTextField();
        VocabBox2 = new javax.swing.JTextField();
        VocabBox3 = new javax.swing.JTextField();
        VocabBox4 = new javax.swing.JTextField();
        VocabBox5 = new javax.swing.JTextField();
        VocabBox6 = new javax.swing.JTextField();
        VocabBox7 = new javax.swing.JTextField();
        VocabBox8 = new javax.swing.JTextField();
        VocabBox9 = new javax.swing.JTextField();
        VocabBox10 = new javax.swing.JTextField();
        DefinitionBox10 = new javax.swing.JTextField();
        DefinitionBox8 = new javax.swing.JTextField();
        DefinitionBox9 = new javax.swing.JTextField();
        DefinitionBox6 = new javax.swing.JTextField();
        DefinitionBox7 = new javax.swing.JTextField();
        DefinitionBox5 = new javax.swing.JTextField();
        DefinitionBox2 = new javax.swing.JTextField();
        DefinitionBox1 = new javax.swing.JTextField();
        DefinitionBox4 = new javax.swing.JTextField();
        DefinitionBox3 = new javax.swing.JTextField();
        VocabBox11 = new javax.swing.JTextField();
        VocabBox12 = new javax.swing.JTextField();
        VocabBox13 = new javax.swing.JTextField();
        VocabBox14 = new javax.swing.JTextField();
        VocabBox15 = new javax.swing.JTextField();
        DefinitionBox11 = new javax.swing.JTextField();
        DefinitionBox12 = new javax.swing.JTextField();
        DefinitionBox13 = new javax.swing.JTextField();
        DefinitionBox14 = new javax.swing.JTextField();
        DefinitionBox15 = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        definitionBox = new javax.swing.JTextField();
        AnswerBox = new javax.swing.JTextField();
        RandomizeButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        CheckButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        five.setText("5");
        five.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fiveActionPerformed(evt);
            }
        });

        ten.setText("10");
        ten.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tenActionPerformed(evt);
            }
        });

        fithteen.setText("15");
        fithteen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fithteenActionPerformed(evt);
            }
        });

        VocabBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VocabBox1ActionPerformed(evt);
            }
        });

        DefinitionBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DefinitionBox1ActionPerformed(evt);
            }
        });

        definitionBox.setEditable(false);

        AnswerBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AnswerBoxActionPerformed(evt);
            }
        });

        RandomizeButton.setText("Randomize");
        RandomizeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RandomizeButtonActionPerformed(evt);
            }
        });

        jLabel1.setText("Definition:");

        jLabel2.setText("Answer:");

        CheckButton.setText("CHECK");
        CheckButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CheckButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Vocabulary:");

        jLabel4.setText("Definition:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(VocabBox8, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(VocabBox9, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(VocabBox14, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(VocabBox15, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(VocabBox13, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(VocabBox12, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(VocabBox11, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(VocabBox1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(VocabBox2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(VocabBox3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(VocabBox4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(VocabBox5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(VocabBox6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(VocabBox7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(VocabBox10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(30, 30, 30)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(DefinitionBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox2, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox3, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox4, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox5, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox6, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox7, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox8, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox9, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox10, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox11, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox12, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox13, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox14, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(DefinitionBox15, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                                    .addComponent(jLabel4)))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(definitionBox, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1)
                                    .addComponent(RandomizeButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(CheckButton)
                                    .addComponent(jLabel2)
                                    .addComponent(AnswerBox, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(five)
                        .addGap(18, 18, 18)
                        .addComponent(ten)
                        .addGap(12, 12, 12)
                        .addComponent(fithteen)
                        .addGap(130, 130, 130))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addContainerGap(333, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fithteen)
                    .addComponent(ten)
                    .addComponent(five))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(VocabBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(VocabBox9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(VocabBox10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(DefinitionBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DefinitionBox9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(DefinitionBox10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(VocabBox11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DefinitionBox11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(VocabBox12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DefinitionBox12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(VocabBox13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DefinitionBox13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(VocabBox14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DefinitionBox14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(VocabBox15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DefinitionBox15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(definitionBox, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AnswerBox, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CheckButton)
                    .addComponent(RandomizeButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        
       int an;
       String inData;



    private void fiveActionPerformed(java.awt.event.ActionEvent evt) {                                     
        temp = 5;
        ten.setSelected(false);
        fithteen.setSelected(false);

        VocabBox6.setVisible(false);
        VocabBox7.setVisible(false);
        VocabBox8.setVisible(false);
        VocabBox9.setVisible(false);
        VocabBox10.setVisible(false);
        VocabBox11.setVisible(false);
        VocabBox12.setVisible(false);
        VocabBox13.setVisible(false);
        VocabBox14.setVisible(false);
        VocabBox15.setVisible(false);

        DefinitionBox6.setVisible(false);
        DefinitionBox7.setVisible(false);
        DefinitionBox8.setVisible(false);
        DefinitionBox9.setVisible(false);
        DefinitionBox10.setVisible(false);
        DefinitionBox11.setVisible(false);
        DefinitionBox12.setVisible(false);
        DefinitionBox13.setVisible(false);
        DefinitionBox14.setVisible(false);
        DefinitionBox15.setVisible(false);

   
    }                                    

    private void tenActionPerformed(java.awt.event.ActionEvent evt) {                                    
        temp = 10;
        five.setSelected(false);
        fithteen.setSelected(false);


        VocabBox6.setVisible(true);
        VocabBox7.setVisible(true);
        VocabBox8.setVisible(true);
        VocabBox9.setVisible(true);
        VocabBox10.setVisible(true);
        VocabBox11.setVisible(false);
        VocabBox12.setVisible(false);
        VocabBox13.setVisible(false);
        VocabBox14.setVisible(false);
        VocabBox15.setVisible(false);

        DefinitionBox6.setVisible(true);
        DefinitionBox7.setVisible(true);
        DefinitionBox8.setVisible(true);
        DefinitionBox9.setVisible(true);
        DefinitionBox10.setVisible(true);
        DefinitionBox11.setVisible(false);
        DefinitionBox12.setVisible(false);
        DefinitionBox13.setVisible(false);
        DefinitionBox14.setVisible(false);
        DefinitionBox15.setVisible(false);
    }                                   

    private void fithteenActionPerformed(java.awt.event.ActionEvent evt) {                                         
        temp = 15;
        five.setSelected(false);
        ten.setSelected(false);


        VocabBox1.setVisible(true);
        VocabBox2.setVisible(true);
        VocabBox3.setVisible(true);
        VocabBox4.setVisible(true);
        VocabBox5.setVisible(true);
        VocabBox6.setVisible(true);
        VocabBox7.setVisible(true);
        VocabBox8.setVisible(true);
        VocabBox9.setVisible(true);
        VocabBox10.setVisible(true);
        VocabBox11.setVisible(true);
        VocabBox12.setVisible(true);
        VocabBox13.setVisible(true);
        VocabBox14.setVisible(true);
        VocabBox15.setVisible(true);

        DefinitionBox1.setVisible(true);
        DefinitionBox2.setVisible(true);
        DefinitionBox3.setVisible(true);
        DefinitionBox4.setVisible(true);
        DefinitionBox5.setVisible(true);
        DefinitionBox6.setVisible(true);
        DefinitionBox7.setVisible(true);
        DefinitionBox8.setVisible(true);
        DefinitionBox9.setVisible(true);
        DefinitionBox10.setVisible(true);
        DefinitionBox11.setVisible(true);
        DefinitionBox12.setVisible(true);
        DefinitionBox13.setVisible(true);
        DefinitionBox14.setVisible(true);
        DefinitionBox15.setVisible(true);

        
    }                                        

    private void VocabBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
            String B = scan.nextLine();

            B = inData;
    }                                         

    private void RandomizeButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                

        System.out.println(inData);
        if(temp == 5){

        definition.add(DefinitionBox1.getText());
        definition.add(DefinitionBox2.getText());
        definition.add(DefinitionBox3.getText());
        definition.add(DefinitionBox4.getText());
        definition.add(DefinitionBox5.getText());

        Word.add(VocabBox1.getText());
        Word.add(VocabBox2.getText());
        Word.add(VocabBox3.getText());
        Word.add(VocabBox4.getText());
        Word.add(VocabBox5.getText());
       
        for(int i = 1; i<=1; i++){
            Collections.shuffle(definition);
            
            definitionBox.setText(String.valueOf(definition.get(i)));
        }
        }

           if(temp == 10){

        definition.add(DefinitionBox1.getText());
        definition.add(DefinitionBox2.getText());
        definition.add(DefinitionBox3.getText());
        definition.add(DefinitionBox4.getText());
        definition.add(DefinitionBox5.getText());
        definition.add(DefinitionBox6.getText());
        definition.add(DefinitionBox7.getText());
        definition.add(DefinitionBox8.getText());
        definition.add(DefinitionBox9.getText());
        definition.add(DefinitionBox10.getText());

        Word.add(VocabBox1.getText());
        Word.add(VocabBox2.getText());
        Word.add(VocabBox3.getText());
        Word.add(VocabBox4.getText());
        Word.add(VocabBox5.getText());
        Word.add(VocabBox6.getText());
        Word.add(VocabBox7.getText());
        Word.add(VocabBox8.getText());
        Word.add(VocabBox9.getText());
        Word.add(VocabBox10.getText());



        for(int i = 1; i<=1; i++){
            Collections.shuffle(definition);

            definitionBox.setText(String.valueOf(definition.get(i)));
        }
        }

                   if(temp == 10){

        definition.add(DefinitionBox1.getText());
        definition.add(DefinitionBox2.getText());
        definition.add(DefinitionBox3.getText());
        definition.add(DefinitionBox4.getText());
        definition.add(DefinitionBox5.getText());
        definition.add(DefinitionBox6.getText());
        definition.add(DefinitionBox7.getText());
        definition.add(DefinitionBox8.getText());
        definition.add(DefinitionBox9.getText());
        definition.add(DefinitionBox10.getText());
        definition.add(DefinitionBox11.getText());
        definition.add(DefinitionBox12.getText());
        definition.add(DefinitionBox13.getText());
        definition.add(DefinitionBox14.getText());
        definition.add(DefinitionBox15.getText());

        Word.add(VocabBox1.getText());
        Word.add(VocabBox2.getText());
        Word.add(VocabBox3.getText());
        Word.add(VocabBox4.getText());
        Word.add(VocabBox5.getText());
        Word.add(VocabBox6.getText());
        Word.add(VocabBox7.getText());
        Word.add(VocabBox8.getText());
        Word.add(VocabBox9.getText());
        Word.add(VocabBox10.getText());
        Word.add(VocabBox11.getText());
        Word.add(VocabBox12.getText());
        Word.add(VocabBox13.getText());
        Word.add(VocabBox14.getText());
        Word.add(VocabBox15.getText());



        for(int i = 1; i<=1; i++){
            Collections.shuffle(definition);

            definitionBox.setText(String.valueOf(definition.get(i)));
        }
        }

        VocabBox1.setVisible(false);
        VocabBox2.setVisible(false);
        VocabBox3.setVisible(false);
        VocabBox4.setVisible(false);
        VocabBox5.setVisible(false);
        VocabBox6.setVisible(false);
        VocabBox7.setVisible(false);
        VocabBox8.setVisible(false);
        VocabBox9.setVisible(false);
        VocabBox10.setVisible(false);
        VocabBox11.setVisible(false);
        VocabBox12.setVisible(false);
        VocabBox13.setVisible(false);
        VocabBox14.setVisible(false);
        VocabBox15.setVisible(false);
        DefinitionBox1.setVisible(false);
        DefinitionBox2.setVisible(false);
        DefinitionBox3.setVisible(false);
        DefinitionBox4.setVisible(false);
        DefinitionBox5.setVisible(false);
        DefinitionBox6.setVisible(false);
        DefinitionBox7.setVisible(false);
        DefinitionBox8.setVisible(false);
        DefinitionBox9.setVisible(false);
        DefinitionBox10.setVisible(false);
        DefinitionBox11.setVisible(false);
        DefinitionBox12.setVisible(false);
        DefinitionBox13.setVisible(false);
        DefinitionBox14.setVisible(false);
        DefinitionBox15.setVisible(false);

        AnswerBox.setText("");
        AnswerBox.setForeground(Color.black);
    }                                               

    private void CheckButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            

       if (DefinitionBox1.equals(VocabBox1)){
            AnswerBox.setText("correct");
        }
   
    if (DefinitionBox1!=(VocabBox1)){
        AnswerBox.setText("int");
    }


    }                                           

    private void AnswerBoxActionPerformed(java.awt.event.ActionEvent evt) {                                          
     
    }                                         

    private void DefinitionBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                               
        String A =scan.nextLine();

        A= inData;
    }                                              

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VocabPractice().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTextField AnswerBox;
    private javax.swing.JButton CheckButton;
    private javax.swing.JTextField DefinitionBox1;
    private javax.swing.JTextField DefinitionBox10;
    private javax.swing.JTextField DefinitionBox11;
    private javax.swing.JTextField DefinitionBox12;
    private javax.swing.JTextField DefinitionBox13;
    private javax.swing.JTextField DefinitionBox14;
    private javax.swing.JTextField DefinitionBox15;
    private javax.swing.JTextField DefinitionBox2;
    private javax.swing.JTextField DefinitionBox3;
    private javax.swing.JTextField DefinitionBox4;
    private javax.swing.JTextField DefinitionBox5;
    private javax.swing.JTextField DefinitionBox6;
    private javax.swing.JTextField DefinitionBox7;
    private javax.swing.JTextField DefinitionBox8;
    private javax.swing.JTextField DefinitionBox9;
    private javax.swing.JButton RandomizeButton;
    private javax.swing.JTextField VocabBox1;
    private javax.swing.JTextField VocabBox10;
    private javax.swing.JTextField VocabBox11;
    private javax.swing.JTextField VocabBox12;
    private javax.swing.JTextField VocabBox13;
    private javax.swing.JTextField VocabBox14;
    private javax.swing.JTextField VocabBox15;
    private javax.swing.JTextField VocabBox2;
    private javax.swing.JTextField VocabBox3;
    private javax.swing.JTextField VocabBox4;
    private javax.swing.JTextField VocabBox5;
    private javax.swing.JTextField VocabBox6;
    private javax.swing.JTextField VocabBox7;
    private javax.swing.JTextField VocabBox8;
    private javax.swing.JTextField VocabBox9;
    private javax.swing.JTextField definitionBox;
    private javax.swing.JRadioButton fithteen;
    private javax.swing.JRadioButton five;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JRadioButton ten;
    // End of variables declaration                   

}



Here is the full code still having problems tellin it if its = do this and if not do this it just does one if statement.
Was This Post Helpful? 0
  • +
  • -

#5 n8schatten  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 263
  • Joined: 07-December 10

Re: Java not reading other IF statement

Posted 31 May 2011 - 04:51 AM

Despite the fact that generated code looks really creepy, please tell us why you think that only on if-statement is taken into account. What are the symptoms you are observing?
Was This Post Helpful? 0
  • +
  • -

#6 lazyajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-May 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 04:59 AM

When ever i use
 if (DefinitionBox1.equals(VocabBox1)){
            AnswerBox.setText("correct");
  }
   
 if (DefinitionBox1!=(VocabBox1)){
        AnswerBox.setText("int");
 } 
it just does the second if statement no matter what i put in the box its int
Was This Post Helpful? 0
  • +
  • -

#7 n8schatten  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 263
  • Joined: 07-December 10

Re: Java not reading other IF statement

Posted 31 May 2011 - 05:05 AM

When both of the conditions are evaluated to be true, you are setting the text of AnswerBox so fast to "int" that you don't see the "correct" to be there.
You can simply verify that by putting System.out.println("some text") inside of both ifs.
Was This Post Helpful? 0
  • +
  • -

#8 lazyajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-May 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 05:15 AM

@n8schatten still same issue it only says incorrect
Was This Post Helpful? 0
  • +
  • -

#9 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7644
  • View blog
  • Posts: 12,890
  • Joined: 19-March 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 05:41 AM

if (DefinitionBox1.equals(VocabBox1)){
           AnswerBox.setText("correct");
 }


this will evaluate to true iff DefinitionBox1.equals returns true. I don't know for sure what that method returns, but that's when you'll get that effect.


if (DefinitionBox1!=(VocabBox1)){
       AnswerBox.setText("int");
} 




This condition will evaluate to true, and the branch will fire, just in case the memory address contained on the stack with the label "DefinitionBox1" is not equal to the memory address contained on the stack with the label "VocabBox1". This will only be false if you have set the two objects to be equal. I don't think you've done this, so this will always fire, meaning, as nachtchatten says, it will obscure the effect of the previous setText().

To reiterate: put println statements in each branch, and see what happens. Or use this form:
AnswerBox.setText(AnswerBox.getText()+" branch2 fired");


which will put something indicative in the box you're looking at.

This post has been edited by jon.kiparsky: 31 May 2011 - 05:42 AM

Was This Post Helpful? 0
  • +
  • -

#10 lazyajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-May 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 05:55 AM

im still havin the same issue.... the program is for a user to put defintion in box1 and the word that matchs in vocab box which makes it either correct or wrong when the check button is pressed.
Was This Post Helpful? 0
  • +
  • -

#11 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7644
  • View blog
  • Posts: 12,890
  • Joined: 19-March 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 06:00 AM

if (DefinitionBox1!=(VocabBox1)){


This is the wrong test to use. == tests for identity of objects, .equals tests for semantic equality. Now you've got a further problem, because you're testing for semantic equality of two containers, instead of testing for semantic equality of their contents.
Suppose you have a box of matches and a box of matches - is one box equal to the other box? Or are the contents of the one box equal to the contents of the other box.

Try comparing contents instead of containers.

[EDIT: First by a whisker!]

This post has been edited by jon.kiparsky: 31 May 2011 - 06:01 AM

Was This Post Helpful? 1
  • +
  • -

#12 n8schatten  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 263
  • Joined: 07-December 10

Re: Java not reading other IF statement

Posted 31 May 2011 - 06:00 AM

Then perhaps you should try to compare the text of DefinitionBox1 and VocabBox1 instead comparing the boxes themselves. Maybe something like:
if (DefinitionBox1.getText().equals(VocabBox1.getText())){
           AnswerBox.setText("correct");
}
if (!DefinitionBox1.getText().equals(VocabBox1.getText())){
           AnswerBox.setText("incorrect");
 }


Furthermore, since the entered text is either correct or incorrect, why don't you use an if-else instead of two ifs? E.g.
if (DefinitionBox1.getText().equals(VocabBox1.getText())){
           AnswerBox.setText("correct");
}
else {
           AnswerBox.setText("incorrect");
}

This post has been edited by n8schatten: 31 May 2011 - 06:00 AM

Was This Post Helpful? 1
  • +
  • -

#13 lazyajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-May 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 06:11 AM

nothing tried both ways and it still just gets one of the if.....now it just says correct using
if(DefinitionBox1.getText().equals(VocabBox1.getText())){
    AnswerBox.setText("Correct");
}
if(!DefinitionBox1.getText().equals(VocabBox1.getText())){
    AnswerBox.setText(" InCorrect");
}


Was This Post Helpful? 0
  • +
  • -

#14 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7644
  • View blog
  • Posts: 12,890
  • Joined: 19-March 11

Re: Java not reading other IF statement

Posted 31 May 2011 - 06:16 AM

There's little in this world that you can believe in as firmly as ! (a && !a). Try using non-equal values in DefBox and VocabBox
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1