Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: "If" statement not working

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default "If" statement not working

    Hi. I have an if statement that checks if a string matches the title of a radiobutton. If it does, it sets the radiobutton's selectedValue to true. If not, it disregards the string and puts it into a textbox. The problem is, the if statement simply doesn't work. I've checked what the value of the String is, and it matches what the if statement should pick up.

    I've included a ZIP archive with my source code and a runnable JAR. Can anyone tell me why the if statement doesn't pick up? Thanks.

    The if statement is in edit.java, in the setup() sub. I have it so the textbox displays what the variable is. Don't worry about the textbox, I can program that fine, I just need to get the if statement to set the radioButton values.

    Thanks!

    src.zip


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "If" statement not working

    an if statement that checks if a string matches the title of a radiobutton
    Are you using the equals method to compare the contents of two Strings?

    If would be better if you posted the code here so we could see the statement that is the problem.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: "If" statement not working

    	 public static void setup(){
    		String message;
    		String colour;
    		String movement;
    		String original;
    		String temp = new String();
    		int count;
    		boolean colourbool = false;
    		boolean movementbool = false;
     
    		original = main.list1.getItem(main.list1.getSelectedIndex());
     
     
     
    		count = original.indexOf(":");
    		temp = original.substring(0, count);
    		txtText.setText(temp);
    		if(temp == "Red"){
    			rdbtnRed.setSelected(true);
    		}else if(temp == "White"){
    			rdbtnWhite.setSelected(true);
    		}else if(temp == "Green"){
    			rdbtnGreen.setSelected(true);
    		}else if(temp == "Purple"){
    			rdbtnPurple.setSelected(true);
    		}else if(temp == "Cyan"){
    			rdbtnCyan.setSelected(true);
    		}else if(temp == "Flash1"){
    			rdbtnFlash1.setSelected(true);
    		}else if(temp == "Flash2"){
    			rdbtnFlash2.setSelected(true);
    		}else if(temp == "Flash3"){
    			rdbtnFlash3.setSelected(true);
    		}else if(temp == "Glow1"){
    			rdbtnGlow1.setSelected(true);
    		}else if(temp == "Glow2"){
    			rdbtnGlow2.setSelected(true);
    		}else if(temp == "Glow3"){
    			rdbtnGlow3.setSelected(true);
    		}else if(temp == "Wave"){
    			rdbtnWave.setSelected(true);
    		}else if(temp == "Wave2"){
    			rdbtnWave2.setSelected(true);
    		}else if(temp == "Scroll"){
    			rdbtnScroll.setSelected(true);	
    		}else if(temp == "Shake"){
    				rdbtnShake.setSelected(true);
    		}else if(temp == "Slide"){
    				rdbtnSlide.setSelected(true);
    		}else{
    			JOptionPane.showMessageDialog(null, "Didnt do anytin (like normal)");
    		}
     
    		if(temp == "Wave"){
    			rdbtnWave.setSelected(true);
    		}else if(temp == "Wave2"){
    			rdbtnWave2.setSelected(true);
    		}else if(temp == "Scroll"){
    			rdbtnScroll.setSelected(true);	
    		}else if(temp == "Shake"){
    				rdbtnShake.setSelected(true);
    		}else if(temp == "Slide"){
    				rdbtnSlide.setSelected(true);
    		}
     
     
    	}

    The problem is, it always runs else, like it doesn't equal the temp variable string.
    But, it says in the textbox that "temp" equals what i have in the "if" statement, and should be caught in the if statement.

    Sorry if its hard to understand

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "If" statement not working

    You need to use the equals() method when comparing the contents of String objects. The == operator tests if the two variables refer to the same object.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Kanyon (September 14th, 2011)

  6. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: "If" statement not working

    so, like this?:

    if(temp.equals("Red") == true){

    }

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "If" statement not working

    The '== true' is redundant. The equals method returns a boolean.
    if(temp.equals("Red")) {

  8. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: "If" statement not working

    Okay, thank you. That seemed to work. I didn't notice it because the RadioButtons don't change value for some reason. Thanks for your help though!!!

  9. #8
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: "If" statement not working

    Would the Radiobuttons not changing have anything to do with being declared as Static? They are. Here is my entire edit class:

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.TitledBorder;
    import javax.swing.ButtonGroup;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.JRadioButton;
    import javax.swing.LayoutStyle.ComponentPlacement;
    import javax.swing.JButton;
    import javax.swing.UIManager;
     
     
    public class edit extends JFrame {
     
    	private JPanel contentPane;
    	public static JTextField txtText = new JTextField();
        static JRadioButton rdbtnNone = new JRadioButton("None");
    	static JRadioButton rdbtnRed = new JRadioButton("Red");
    	static JRadioButton rdbtnNone2 = new JRadioButton("None");
    	static  JRadioButton rdbtnScroll = new JRadioButton("Scroll");
    	static  JRadioButton rdbtnWave = new JRadioButton("Wave");
    	static  JRadioButton rdbtnWave2 = new JRadioButton("Wave 2");
    	static  JRadioButton rdbtnShake = new JRadioButton("Shake");
    	static  JRadioButton rdbtnSlide = new JRadioButton("Slide");
    	static  JRadioButton rdbtnWhite = new JRadioButton("White");
    	static  JRadioButton rdbtnGreen = new JRadioButton("Green");
    	static  JRadioButton rdbtnPurple = new JRadioButton("Purple");
    	static  JRadioButton rdbtnCyan = new JRadioButton("Cyan");
    	static  JRadioButton rdbtnFlash1 = new JRadioButton("Flash 1");
    	static  JRadioButton rdbtnFlash2 = new JRadioButton("Flash 2");
    	static  JRadioButton rdbtnFlash3 = new JRadioButton("Flash 3");
    	static  JRadioButton rdbtnGlow1 = new JRadioButton("Glow 1");
    	static  JRadioButton rdbtnGlow2 = new JRadioButton("Glow 2");
    	static  JRadioButton rdbtnGlow3 = new JRadioButton("Glow 3");
     
    	static JButton btnCancel = new JButton("Cancel");
    	/**
    	 * Launch the application.
    	 */
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					edit frame = new edit();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	setup();
    	}
     
    	/**
    	 * Create the frame.
    	 */
    	public edit() {
    		addWindowListener(new WindowAdapter() {
    			@Override
    			public void windowClosing(WindowEvent arg0) {
    				main.frmRunescapeAutotyper.setVisible(true);
    			}
    		});
    		setTitle("Edit Message");
    		setResizable(false);
    		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		setBounds(100, 100, 451, 244);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
     
     
    		btnCancel.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				dispose();
    				main.frmRunescapeAutotyper.setVisible(true);
    			}
    		});
     
    		txtText.setColumns(10);
     
    		JLabel lblMessage = new JLabel("Message:");
     
    		JPanel panel = new JPanel();
    		panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Colour:", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
     
    		JPanel panel_1 = new JPanel();
    		panel_1.setBorder(new TitledBorder(null, "Movement:", TitledBorder.LEADING, TitledBorder.TOP, null, null));
     
    		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
    		gl_panel_1.setHorizontalGroup(
    			gl_panel_1.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_panel_1.createSequentialGroup()
    					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
    						.addGroup(gl_panel_1.createSequentialGroup()
    							.addComponent(rdbtnNone2)
    							.addPreferredGap(ComponentPlacement.UNRELATED)
    							.addComponent(rdbtnWave2))
    						.addGroup(gl_panel_1.createSequentialGroup()
    							.addComponent(rdbtnScroll)
    							.addPreferredGap(ComponentPlacement.UNRELATED)
    							.addComponent(rdbtnShake))
    						.addGroup(gl_panel_1.createSequentialGroup()
    							.addComponent(rdbtnWave)
    							.addPreferredGap(ComponentPlacement.RELATED)
    							.addComponent(rdbtnSlide)))
    					.addGap(22))
    		);
    		rdbtnNone2.setSelected(true);
    		gl_panel_1.setVerticalGroup(
    			gl_panel_1.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_panel_1.createSequentialGroup()
    					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnNone2)
    						.addComponent(rdbtnWave2))
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnScroll)
    						.addComponent(rdbtnShake))
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnWave)
    						.addComponent(rdbtnSlide))
    					.addContainerGap(78, Short.MAX_VALUE))
    		);
    		panel_1.setLayout(gl_panel_1);
     
     
    		JButton btnAdd = new JButton("Change");
     
     
    		GroupLayout gl_contentPane = new GroupLayout(contentPane);
    		gl_contentPane.setHorizontalGroup(
    			gl_contentPane.createParallelGroup(Alignment.TRAILING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(4)
    							.addComponent(lblMessage)
    							.addPreferredGap(ComponentPlacement.RELATED)
    							.addComponent(txtText))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addContainerGap()
    							.addComponent(panel, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE)
    							.addPreferredGap(ComponentPlacement.RELATED)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
    								.addComponent(btnAdd, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    								.addComponent(btnCancel, GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
    							.addPreferredGap(ComponentPlacement.RELATED)
    							.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 158, GroupLayout.PREFERRED_SIZE)))
    					.addContainerGap())
    		);
    		gl_contentPane.setVerticalGroup(
    			gl_contentPane.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    						.addComponent(lblMessage)
    						.addComponent(txtText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(55)
    							.addComponent(btnAdd)
    							.addPreferredGap(ComponentPlacement.RELATED)
    							.addComponent(btnCancel))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addPreferredGap(ComponentPlacement.RELATED)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(panel, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)
    								.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE))))
    					.addGap(3))
    		);
     
     
     
    		GroupLayout gl_panel = new GroupLayout(panel);
    		gl_panel.setHorizontalGroup(
    			gl_panel.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_panel.createSequentialGroup()
    					.addContainerGap()
    					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
    						.addGroup(gl_panel.createSequentialGroup()
    							.addComponent(rdbtnCyan)
    							.addGap(18)
    							.addComponent(rdbtnGlow3))
    						.addGroup(gl_panel.createSequentialGroup()
    							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
    								.addComponent(rdbtnNone)
    								.addComponent(rdbtnRed)
    								.addComponent(rdbtnWhite)
    								.addComponent(rdbtnGreen)
    								.addComponent(rdbtnPurple))
    							.addGap(14)
    							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
    								.addComponent(rdbtnGlow2)
    								.addComponent(rdbtnGlow1)
    								.addComponent(rdbtnFlash3)
    								.addComponent(rdbtnFlash2)
    								.addComponent(rdbtnFlash1))))
    					.addContainerGap(16, Short.MAX_VALUE))
    		);
    		rdbtnNone.setSelected(true);
    		gl_panel.setVerticalGroup(
    			gl_panel.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_panel.createSequentialGroup()
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnNone)
    						.addComponent(rdbtnFlash1))
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnRed)
    						.addComponent(rdbtnFlash2))
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnWhite)
    						.addComponent(rdbtnFlash3))
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnGreen)
    						.addComponent(rdbtnGlow1))
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnPurple)
    						.addComponent(rdbtnGlow2))
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
    						.addComponent(rdbtnCyan)
    						.addComponent(rdbtnGlow3))
    					.addContainerGap(9, Short.MAX_VALUE))
    		);
    		panel.setLayout(gl_panel);
    		contentPane.setLayout(gl_contentPane);
     
     
     
    		ButtonGroup group = new ButtonGroup();
    		group.add(rdbtnNone);
    		group.add(rdbtnRed);
    		group.add(rdbtnWhite);
    		group.add(rdbtnGreen);
    		group.add(rdbtnPurple);
    		group.add(rdbtnCyan);
    		group.add(rdbtnFlash1);
    		group.add(rdbtnFlash2);
    		group.add(rdbtnFlash3);
    		group.add(rdbtnGlow1);
    		group.add(rdbtnGlow2);
    		group.add(rdbtnGlow3);
    		ButtonGroup group2 = new ButtonGroup();
    		group2.add(rdbtnNone2);
    		group2.add(rdbtnScroll);
    		group2.add(rdbtnWave);
    		group2.add(rdbtnWave2);
    		group2.add(rdbtnShake);
    		group2.add(rdbtnScroll);
    		group2.add(rdbtnSlide);
    		btnAdd.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				edit();
    			}
    		});
    	}
     
     
    	public static void edit(){
    		int originalindex = main.list1.getSelectedIndex();
    		main.list1.delItem(originalindex);
    		String colour = null;
    		String movement = null;
    		Boolean error = false;
    		if(rdbtnNone.isSelected() == true){
    			colour = "";
    		}else if(rdbtnRed.isSelected() == true){
    			colour = "Red:";
    		}else if(rdbtnWhite.isSelected() == true){
    			colour = "White:";
    		}else if(rdbtnGreen.isSelected() == true){
    			colour = "Green:";
    		}else if(rdbtnPurple.isSelected() == true){
    			colour = "Purple:";
    		}else if(rdbtnCyan.isSelected() == true){
    			colour = "Cyan:";
    		}else if(rdbtnFlash1.isSelected() == true){
    			colour = "Flash1:";
    		}else if(rdbtnFlash2.isSelected() == true){
    			colour = "Flash2:";
    		}else if(rdbtnFlash3.isSelected() == true){
    			colour = "Flash3:";
    		}else if(rdbtnGlow1.isSelected() == true){
    			colour = "Glow1:";
    		}else if(rdbtnGlow2.isSelected() == true){
    			colour = "Glow2:";
    		}else if(rdbtnGlow2.isSelected() == true){
    			colour = "Glow3:";
    		}else {
    			JOptionPane.showMessageDialog(null, "No colour selected!", "Error", JOptionPane.INFORMATION_MESSAGE, null);
    			error = true;
    		}
     
    		if(rdbtnNone2.isSelected() == true){
    			movement = "";
    		}else if(rdbtnWave2.isSelected() == true){
    			movement = "Wave2:";
    		}else if(rdbtnWave.isSelected() == true){
    			movement = "Wave:";
    		}else if(rdbtnScroll.isSelected() == true){
    			movement = "Scroll:";
    		}else if(rdbtnShake.isSelected() == true){
    			movement = "Shake:";
    		}else if(rdbtnSlide.isSelected() == true){
    			movement = "Slide:";
    		}else{
    			JOptionPane.showMessageDialog(null, "No movement selected!", "Error", JOptionPane.INFORMATION_MESSAGE, null);
    			error = true;
    		}
     
    		if(error == false){
    			main.list1.addItem(colour + movement + txtText.getText(), originalindex);
    			main.list1.select(originalindex);
    			btnCancel.doClick();
    		}
    	}
     
     
    	 public static void setup(){
    		String message;
    		String colour;
    		String movement;
    		String original;
    		String temp = new String();
    		int count;
    		boolean colourbool = false;
    		boolean movementbool = false;
     
    		original = main.list1.getItem(main.list1.getSelectedIndex());
     
     
     
    		count = original.indexOf(":");
    		temp = original.substring(0, count);
    		txtText.setText(temp);
    		if(temp.equals("Red")){
    			rdbtnRed.setSelected(true);
    		}else if(temp == "White"){
    			rdbtnWhite.setSelected(true);
    		}else if(temp == "Green"){
    			rdbtnGreen.setSelected(true);
    		}else if(temp == "Purple"){
    			rdbtnPurple.setSelected(true);
    		}else if(temp == "Cyan"){
    			rdbtnCyan.setSelected(true);
    		}else if(temp == "Flash1"){
    			rdbtnFlash1.setSelected(true);
    		}else if(temp == "Flash2"){
    			rdbtnFlash2.setSelected(true);
    		}else if(temp == "Flash3"){
    			rdbtnFlash3.setSelected(true);
    		}else if(temp == "Glow1"){
    			rdbtnGlow1.setSelected(true);
    		}else if(temp == "Glow2"){
    			rdbtnGlow2.setSelected(true);
    		}else if(temp == "Glow3"){
    			rdbtnGlow3.setSelected(true);
    		}else if(temp == "Wave"){
    			rdbtnWave.setSelected(true);
    		}else if(temp == "Wave2"){
    			rdbtnWave2.setSelected(true);
    		}else if(temp == "Scroll"){
    			rdbtnScroll.setSelected(true);	
    		}else if(temp == "Shake"){
    				rdbtnShake.setSelected(true);
    		}else if(temp == "Slide"){
    				rdbtnSlide.setSelected(true);
    		}else{
    			JOptionPane.showMessageDialog(null, "Didnt do anytin (like normal)");
    		}
     
    		if(temp == "Wave"){
    			rdbtnWave.setSelected(true);
    		}else if(temp == "Wave2"){
    			rdbtnWave2.setSelected(true);
    		}else if(temp == "Scroll"){
    			rdbtnScroll.setSelected(true);	
    		}else if(temp == "Shake"){
    				rdbtnShake.setSelected(true);
    		}else if(temp == "Slide"){
    				rdbtnSlide.setSelected(true);
    		}
     
     
    	}
    }

  10. #9
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: "If" statement not working

    Oh, nevermind. That is a rather big error that should go in a separate thread. Thanks for the help!

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "If" statement not working

    Would the Radiobuttons not changing
    Please explain what the problem is? What is supposed to change and what is to make it change?

  12. #11
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: "If" statement not working

    In the code above, I have the Radiobuttons declared as class-wide variables. For some reason, I cannot set their checked value from a sub that they weren't added to the JFrame. This has something to do with threading, I think.

    Anyway, I fixed it by taking my code from setup() and adding it to the bottom of edit()

    Thanks so much for your help, been stuck on these errors for a week now! You solved them all!

  13. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "If" statement not working

    You should NOT use statics to get around passing references to objects.

  14. #13
    Junior Member
    Join Date
    Sep 2011
    Posts
    19
    My Mood
    Fine
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: "If" statement not working

    Okay, I have no idea what that means

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: "If" statement not working

    Remove all the static variables from your code except the one on the main method.

Similar Threads

  1. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  2. using if statement on string System.getProperty("os.name") not working
    By sauyon in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 29th, 2011, 12:09 PM
  3. first itteration of "for" statement acts differntly to all the rest, why?
    By SPACE MONKEY in forum Java Theory & Questions
    Replies: 4
    Last Post: March 1st, 2011, 11:06 AM
  4. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM