8 Replies - 31770 Views - Last Post: 02 March 2009 - 04:53 PM Rate Topic: -----

#1 alexriverajr   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 25-February 09

Clearing/Resetting Checkboxes and Radiobuttons

Posted 25 February 2009 - 01:50 PM

I have been working on this order manger for about a week. The structure is one Main GUI file that call on the other files for panels. What i'm trying to accomplish is a clear/reset of checkboxes and radiobuttons. I have a million things on this topic but can't find the solutions. First is the Main GUI code followed by a checkbox code from another file that I call:

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import javax.swing.JLabel;
import java.awt.ComponentOrientation;
import java.awt.Dimension;


public class ManagerGUI extends JFrame {

	private JPanel jContentPane = null;
	private inOrOutPanel inOrOutPanel = null;
	private FillingsPanel fillingsPanel = null;
	private GreetingPanel greetingPanel = null;
	private BreadsPanel breadsPanel = null;
	private SoftDrinkPanel softDrinkPanel = null;
	private JButton exitButton = null;
	private JButton calculateButton = null;
	private final double TAX_RATE = 0.06; // Sales tax rate
	private JTextField jTextField1 = null;
	private JLabel Total = null;
	private double subtotal, tax, total; 
	private double number1 = 0;
	private double changeDue;
	private String input;
	private JTextField Subtotalbeforetaxes = null;
	private JTextField Taxes = null;
	private JLabel subTotallabel = null;
	private JLabel Tax = null;
	private JButton orderReset = null;
	
	/**
	 * This is the default constructor
	 */
	public ManagerGUI() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(657,410);
		this.setContentPane(getJContentPane());
		this.setTitle("Order Manager");
		
		// Set Main Panel Color
		setBackground(new Color (189, 213, 252));
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
			gridBagConstraints13.gridx = 5;
			gridBagConstraints13.gridwidth = 0;
			gridBagConstraints13.anchor = GridBagConstraints.EAST;
			gridBagConstraints13.gridy = 7;
			GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
			gridBagConstraints41.gridx = 7;
			gridBagConstraints41.anchor = GridBagConstraints.WEST;
			gridBagConstraints41.gridwidth = 0;
			gridBagConstraints41.insets = new Insets(0, 0, 0, 0);
			gridBagConstraints41.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints41.gridy = 7;
			Tax = new JLabel();
			Tax.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			Tax.setForeground(Color.red);
			Tax.setText("State Tax 6%:");
			Tax.setFont(new Font("Lucida Grande", Font.BOLD, 13));
			GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
			gridBagConstraints31.gridx = 7;
			gridBagConstraints31.gridwidth = 0;
			gridBagConstraints31.insets = new Insets(0, 26, 0, 1);
			gridBagConstraints31.anchor = GridBagConstraints.WEST;
			gridBagConstraints31.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints31.gridy = 6;
			subTotallabel = new JLabel();
			subTotallabel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			subTotallabel.setForeground(Color.red);
			subTotallabel.setText("SubTotal:");
			subTotallabel.setFont(new Font("Lucida Grande", Font.BOLD, 13));
			GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
			gridBagConstraints22.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints22.gridy = 7;
			gridBagConstraints22.weightx = 1.0;
			gridBagConstraints22.ipadx = 0;
			gridBagConstraints22.insets = new Insets(0, 0, 0, 95);
			gridBagConstraints22.anchor = GridBagConstraints.CENTER;
			gridBagConstraints22.gridwidth = 0;
			gridBagConstraints22.gridx = 7;
			GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
			gridBagConstraints12.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints12.gridy = 6;
			gridBagConstraints12.weightx = 0.0;
			gridBagConstraints12.ipadx = 0;
			gridBagConstraints12.insets = new Insets(0, 0, 0, 95);
			gridBagConstraints12.anchor = GridBagConstraints.CENTER;
			gridBagConstraints12.gridwidth = 0;
			gridBagConstraints12.gridx = 7;
			GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
			gridBagConstraints11.gridx = 6;
			gridBagConstraints11.gridwidth = 0;
			gridBagConstraints11.insets = new Insets(0, 51, 0, 0);
			gridBagConstraints11.anchor = GridBagConstraints.WEST;
			gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints11.gridy = 9;
			Total = new JLabel();
			Total.setText("Total:");
			Total.setFont(new Font("Lucida Grande", Font.BOLD, 13));
			Total.setForeground(Color.red);
			Total.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			GridBagConstraints gridBagConstraints81 = new GridBagConstraints();
			gridBagConstraints81.gridy = 9;
			gridBagConstraints81.anchor = GridBagConstraints.CENTER;
			gridBagConstraints81.gridwidth = 0;
			gridBagConstraints81.ipadx = 0;
			gridBagConstraints81.insets = new Insets(0, 0, 0, 95);
			gridBagConstraints81.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints81.gridx = 7;
			GridBagConstraints gridBagConstraints71 = new GridBagConstraints();
			gridBagConstraints71.fill = GridBagConstraints.VERTICAL;
			gridBagConstraints71.gridy = 6;
			gridBagConstraints71.weightx = 1.0;
			gridBagConstraints71.gridx = 7;
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.gridx = 5;
			gridBagConstraints5.gridwidth = 0;
			gridBagConstraints5.insets = new Insets(0, 0, 2, 4);
			gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints5.gridy = 5;
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.gridx = 5;
			gridBagConstraints4.gridwidth = 0;
			gridBagConstraints4.anchor = GridBagConstraints.EAST;
			gridBagConstraints4.insets = new Insets(0, 0, 0, 0);
			gridBagConstraints4.gridy = 9;
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.gridx = 0;
			gridBagConstraints3.gridwidth = 0;
			gridBagConstraints3.anchor = GridBagConstraints.EAST;
			gridBagConstraints3.insets = new Insets(0, 0, 0, 0);
			gridBagConstraints3.weightx = 0.0;
			gridBagConstraints3.ipadx = 0;
			gridBagConstraints3.gridy = 6;
			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
			gridBagConstraints21.gridx = 6;
			gridBagConstraints21.gridy = 5;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.BOTH;
			gridBagConstraints.gridy = 4;
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.weighty = 1.0;
			gridBagConstraints.gridx = 5;
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.gridx = 5;
			gridBagConstraints2.gridy = 6;
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.gridx = 4;
			gridBagConstraints8.gridwidth = 0;
			gridBagConstraints8.ipady = 0;
			gridBagConstraints8.fill = GridBagConstraints.BOTH;
			gridBagConstraints8.weighty = 0.0;
			gridBagConstraints8.insets = new Insets(0, 0, 2, 7);
			gridBagConstraints8.gridy = 0;
			GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
			gridBagConstraints7.gridx = 4;
			gridBagConstraints7.gridwidth = 0;
			gridBagConstraints7.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints7.insets = new Insets(0, 0, 0, 4);
			gridBagConstraints7.gridy = 3;
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.gridx = 7;
			gridBagConstraints6.insets = new Insets(0, 0, 2, 4);
			gridBagConstraints6.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints6.gridwidth = 0;
			gridBagConstraints6.anchor = GridBagConstraints.CENTER;
			gridBagConstraints6.ipadx = 0;
			gridBagConstraints6.gridy = 2;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 4;
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
			gridBagConstraints1.gridwidth = 2;
			gridBagConstraints1.ipadx = 7;
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
			gridBagConstraints1.insets = new Insets(0, 0, 2, 0);
			gridBagConstraints1.gridy = 2;
			jContentPane = new JPanel();
			jContentPane.setLayout(new GridBagLayout());
			jContentPane.add(getGreetingPanel(), gridBagConstraints8);
			jContentPane.add(getInOrOutPanel(), gridBagConstraints1);
			jContentPane.add(getBreadsPanel(), gridBagConstraints6);
			jContentPane.add(getFillingsPanel(), gridBagConstraints7);
			jContentPane.add(getSoftDrinkPanel(), gridBagConstraints5);
			jContentPane.add(getCalculateButton(), gridBagConstraints3);
			jContentPane.add(getExitButton(), gridBagConstraints4);
			jContentPane.add(getOrderReset(), gridBagConstraints13);
			jContentPane.add(getJTextField1(), gridBagConstraints81);
			jContentPane.add(Total, gridBagConstraints11);
			jContentPane.add(getSubtotalbeforetaxes(), gridBagConstraints12);
			jContentPane.add(getTaxes(), gridBagConstraints22);
			jContentPane.add(subTotallabel, gridBagConstraints31);
			jContentPane.add(Tax, gridBagConstraints41);
		}
		return jContentPane;
	}

	/**
	 * This method initializes inOrOutPanel	
	 * 	
	 * @return inOrOutPanel	
	 */
	private inOrOutPanel getInOrOutPanel() {
		if (inOrOutPanel == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setHgap(0);
			inOrOutPanel = new inOrOutPanel();
			inOrOutPanel.setBorder(BorderFactory.createTitledBorder(null, "Dining Preference", TitledBorder.LEADING, TitledBorder.TOP, new Font("Lucida Grande", Font.BOLD, 13), Color.black));
			inOrOutPanel.setLayout(gridLayout);
		}
		return inOrOutPanel;
	}

	/**
	 * This method initializes fillingsPanel	
	 * 	
	 * @return FillingsPanel	
	 */
	private FillingsPanel getFillingsPanel() {
		if (fillingsPanel == null) {
			fillingsPanel = new FillingsPanel();
			fillingsPanel.setBorder(BorderFactory.createTitledBorder(null, "Fillings", 
				TitledBorder.LEADING, TitledBorder.TOP, new Font("Lucida Grande", Font.BOLD, 13), Color.black));
		}
		return fillingsPanel;
	}

	/**
	 * This method initializes greetingPanel	
	 * 	
	 * @return GreetingPanel	
	 */
	private GreetingPanel getGreetingPanel() {
		if (greetingPanel == null) {
			FlowLayout flowLayout = new FlowLayout();
			flowLayout.setVgap(5);
			greetingPanel = new GreetingPanel();
			greetingPanel.setLayout(flowLayout);

		}
		return greetingPanel;
	}

	/**
	 * This method initializes breadsPanel	
	 * 	
	 * @return BreadsPanel	
	 */
	private BreadsPanel getBreadsPanel() {
		if (breadsPanel == null) {
			breadsPanel = new BreadsPanel();
			breadsPanel.setBorder(BorderFactory.createTitledBorder(null, "Breads", TitledBorder.LEADING, TitledBorder.TOP, new Font("Lucida Grande", Font.BOLD, 13), Color.black));
		}
		return breadsPanel;
	}

	/**
	 * This method initializes softDrinkPanel	
	 * 	
	 * @return SoftDrinkPanel	
	 */
	private SoftDrinkPanel getSoftDrinkPanel() {
		if (softDrinkPanel == null) {
			FlowLayout flowLayout1 = new FlowLayout();
			flowLayout1.setHgap(0);
			flowLayout1.setVgap(0);
			softDrinkPanel = new SoftDrinkPanel();
			softDrinkPanel.setToolTipText("Please select the customer's Soft Drink.");
			softDrinkPanel.setBorder(BorderFactory.createTitledBorder(null, "Soft Drinks", TitledBorder.LEADING, 
					TitledBorder.TOP, new Font("Lucida Grande", Font.BOLD, 13), Color.black));
			softDrinkPanel.setLayout(flowLayout1);
		}
		return softDrinkPanel;
	}

	/**
	 * This method initializes Subtotalbeforetaxes	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getSubtotalbeforetaxes() {
		if (Subtotalbeforetaxes == null) {
			Subtotalbeforetaxes = new JTextField();
			Subtotalbeforetaxes.setColumns(6);
			Subtotalbeforetaxes.setForeground(Color.black);
			Subtotalbeforetaxes.setVisible(true);
			Subtotalbeforetaxes.setEditable(false);
			Subtotalbeforetaxes.setToolTipText("This box will display the subtotal prior to taxation.");
			Subtotalbeforetaxes.setHorizontalAlignment(JTextField.CENTER);
			Subtotalbeforetaxes.setName("");
		}
		return Subtotalbeforetaxes;
	}

	/**
	 * This method initializes Taxes	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTaxes() {
		if (Taxes == null) {
			Taxes = new JTextField();
			Taxes.setColumns(6);
			Taxes.setForeground(Color.black);
			Taxes.setVisible(true);
			Taxes.setEditable(false);
			Taxes.setToolTipText("This box will display the total tax amount.");
			Taxes.setHorizontalAlignment(JTextField.CENTER);
			Taxes.setName("");
		}
		return Taxes;
	}
	
	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setForeground(Color.black);
			jTextField1.setVisible(true);
			jTextField1.setEditable(false);
			jTextField1.setToolTipText("This box will display the total.");
			jTextField1.setName("Total");
			jTextField1.setHorizontalAlignment(JTextField.CENTER);
			jTextField1.setColumns(6);
			jTextField1.setName("");

		}
		return jTextField1;
	}

	/**
	 * This method initializes exitButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getExitButton() {
		if (exitButton == null) {
			exitButton = new JButton();
			exitButton.setText("Exit Program");
			exitButton.setHorizontalTextPosition(SwingConstants.CENTER);
			exitButton.setToolTipText("Click here to  exit program.");
			exitButton.addActionListener(new ExitButtonListener());
		}
		return exitButton;
	}
	
	   /**
	Private inner class that handles the event when
	the user clicks the Exit button.
 */

 private class ExitButtonListener implements ActionListener
 {
	public void actionPerformed(ActionEvent e)
	{
		JOptionPane.showConfirmDialog(null,
				"Are you sure you want to quit?", 
				"System Warning", JOptionPane.YES_NO_OPTION);
		

		
		
		if (!(0 == JOptionPane.YES_OPTION))
		{
			System.exit(0);
		}

	}
 }


	/**
	 * This method initializes calculateButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getCalculateButton() {
		if (calculateButton == null) {
			calculateButton = new JButton();
			calculateButton.setText("Calculate");
			calculateButton.setPreferredSize(new Dimension(124, 29));
			calculateButton.setBackground(new Color(238, 238, 238));
			calculateButton.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			calculateButton.setToolTipText("Click here to Calculate the Total.");
			calculateButton.addActionListener(new calculateButtonListener());
		}
		return calculateButton;
	}
	
	public class calculateButtonListener implements ActionListener
	   {
		  public void actionPerformed(ActionEvent e)
		  {
			 // Variables to hold the subtotal, tax, and total
			 //double subtotal, tax, total; 
			 //double number1 = 0;
			 //double changeDue;
			 //String input;

			  
			// Create a DecimalFormat object to format output.
				 DecimalFormat dollar = new DecimalFormat("0.00");

			 // Calculate the subtotal.
			 subtotal = breadsPanel.getbreadsCost() + 
						fillingsPanel.getFillingCost() +
						softDrinkPanel.getSoftDrinkCost() +
						inOrOutPanel.getdiningpreferenceCost();
			 Subtotalbeforetaxes.setText(String.valueOf(dollar.format(subtotal)));

			 // Calculate the sales tax.
			 tax = subtotal * TAX_RATE;
			 Taxes.setText(String.valueOf(dollar.format(tax)));

			 // Calculate the total.
			 total = subtotal + tax;
			 jTextField1.setText(String.valueOf(dollar.format(total)));			

			 // Display the charges.
			 input = JOptionPane.showInputDialog(null, "\n\nPlease enter the tendered amount.");
			 number1 = Double.parseDouble(input);

			 
			 changeDue = number1 - total;
			 JOptionPane.showMessageDialog(null, "The total change due is: $" + dollar.format(changeDue));
			 
			 

			 // This will close the entire application. I would like to close only the current window.
			 //System.exit(0);
			 
		  }
	   }


	[b]/**
	 * This method initializes orderReset	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getOrderReset() {
		if (orderReset == null) {
			orderReset = new JButton();
			orderReset.setHorizontalTextPosition(SwingConstants.CENTER);
			orderReset.setText("Reset Order");
			orderReset.setToolTipText("Click this button to clear the order form.");
			orderReset.setPreferredSize(new Dimension(124, 29));
			orderReset.addActionListener(new orderResetListener());
			
		}
		
		return orderReset;
	}
	
	public class orderResetListener implements ActionListener
	   {
		  public void actionPerformed(ActionEvent e)
		  {
			 [color=#FF0000] jTextField1.setText("");
			  Taxes.setText("");
			  Subtotalbeforetaxes.setText("");[/color]
			  
				[color=#000099][quote]**These are the methods that I have tried to make the clearing/resetting work: 
				  //fillingsPanel.setState(JCheckbox whiteCheese);
			  //fillingsPanel
			  //inOrOutPanel.clearSelection(ButtonGroup bg, true); //clearing radio buttong
			  //boolean BreadsPanel.isSelected(false);
			  //boolean isSelected() 
			  //b3.setEnabled(true);
			  //inOrOutPanel.setSelected(false);
			  //fillingsPanel.setSelected(false); 
[/quote][/color]
		  }
	   }[/b]

	

	   }  //  @jve:decl-index=0:visual-constraint="72,-15"

[b][color=#FF0000]Second is the code with the checkboxes.

[code]
import javax.swing.*;

import java.awt.*;

/**
   The ToppingPanel class allows the user to select
   the toppings for the bagel.
*/

public class FillingsPanel extends JPanel
{
   // The following constants are used to indicate
   // the cost of toppings.
   public final double WHITECHEESE = 0.50;
   public final double GOUDACHEESE = 0.50;
   public final double CHEDDERCHEESE = 0.50;
   public final double TURKEY = 1.00;
   public final double HAM = 1.00;
   public final double SALAMI = 1.00;
   public final double SMOKEDCHICKEN = 1.00;
   public final double LETTUCE = 0.50;
   public final double TOMATO = 0.50;
   public final double REDONIONS = 0.25;

   private JCheckBox whiteCheese;  // To select cream cheese
   private JCheckBox goudaCheese;	   // To select butter
   private JCheckBox chedderCheese;   // To select peach jelly
   private JCheckBox turkey; // To select blueberry jam
   private JCheckBox ham;
   private JCheckBox salami;
   private JCheckBox smokedchicken;
   private JCheckBox lettuce;
   private JCheckBox tomato;
   private JCheckBox redOnions;
   
   /**
	  Constructor
   */

   public FillingsPanel()
   {
	   
	  // Create a GridLayout manager with 
	  // four rows and one column.
	  setLayout(new GridLayout(4, 4));
	  
	  // Create the check boxes.
	  whiteCheese = new JCheckBox("White Cheese", true);
	  goudaCheese = new JCheckBox("Gouda Cheese");
	  chedderCheese = new JCheckBox("Chedder Cheese");
	  turkey = new JCheckBox("Turkey");
	  ham = new JCheckBox("Ham");
	  salami = new JCheckBox("Salami");
	  smokedchicken = new JCheckBox("Smoked Chicken");
	  lettuce = new JCheckBox("Lettuce");
	  tomato = new JCheckBox("Tomato");
	  redOnions = new JCheckBox("Red Onions");
	  
	  // Add a border around the panel.
	  setBorder(BorderFactory.createTitledBorder("Fillings"));
	 
	  // Add the check boxes to the panel.
	  add(whiteCheese);
	  add(goudaCheese);
	  add(chedderCheese);
	  add(turkey);
	  add(ham);
	  add(salami);
	  add(smokedchicken);
	  add(lettuce);
	  add(tomato);
	  add(redOnions);
	  
   }


/**
	  getfillingCost method
	  @return The cost of the selected fillings.
   */

   public double getFillingCost()
   {
	  double fillingCost = 0.0;

	  if (whiteCheese.isSelected())
		 fillingCost += WHITECHEESE;
	  if (goudaCheese.isSelected())
		 fillingCost += GOUDACHEESE;
	  if (chedderCheese.isSelected())
		 fillingCost += CHEDDERCHEESE;
	  if (turkey.isSelected())
		 fillingCost += TURKEY;
	  if (ham.isSelected())
		 fillingCost += HAM;
	  if (salami.isSelected())
		 fillingCost += SALAMI;
	  if (smokedchicken.isSelected())
		 fillingCost += SMOKEDCHICKEN;
	  if (lettuce.isSelected())
		 fillingCost += LETTUCE;
	  if (tomato.isSelected())
		 fillingCost += TOMATO;
	  if (redOnions.isSelected())
		 fillingCost += REDONIONS;

	  return fillingCost;
   }



}



Edited by PBL to add the correct code tag

This post has been edited by pbl: 26 February 2009 - 06:45 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Clearing/Resetting Checkboxes and Radiobuttons

#2 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 25 February 2009 - 02:13 PM

First, for the love of God, use code tags.

For the checkBox:

checkBoxName.setSelected(false);
//or if that doesn't do what you want:
checkBoxName.doClick(); //simulates a click



As for the radio buttons, make an invisible radio button and make that be set when the "clear" is pressed.
Was This Post Helpful? 0
  • +
  • -

#3 alexriverajr   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 25-February 09

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 26 February 2009 - 12:24 PM

Yes I know.....Have some mercy on me, I'm just learning the whole java thing and this was my first post......Learning has occurred. I will try your suggestions . Thanks..
Was This Post Helpful? 0
  • +
  • -

#4 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 26 February 2009 - 06:52 PM

This has been discussed many times before... and here you have a typical example
This the code produced by a Java IDE for a student who just start programming in Java
75% of the code was generated by the IDE
How do you think the poor fellow can follow and correct the problem

That is why GUI generator within an IDE is NOT a good idea for beginners
and now us, who try to help here, are going to read to understand the hundreds of lines generated by the GUI generator to decipher the problem. The code could have been written in 10 times less lines by a programmer and would have been readable.



Better to post your Netbeans (or whatever) project directly
Was This Post Helpful? 0
  • +
  • -

#5 alexriverajr   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 25-February 09

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 27 February 2009 - 06:10 PM

First,

I would like to say that I'm grateful for any help that I receive while in these forums. I'm not an expert in java and learning occurs with any interaction I have with all you real world experts. I really appreciate it!!

Now in response to the above-mentioned posting. If it bothers you how students learn java then I recommend that you don't post or respond. Having been an educator myself I realize that students have many different of learning methods. While using a GUI builder isn't the most preferred way of learning programming, it helped me out allot in understand many methods. It taught how to properly use and create some items that where in terms difficult for me to understand straight from the text. Through some reverse engineering I could now go back and simplify my work because I now have a better understanding of the fundamental concepts in java. Your ridicule on my work; I don't need, its the help that is most important. If you choose not help that fine, but I don't need your comment on the best learning methods. Remember learning occurs through education and mentoring, not the I told you so. Thanks


View Postpbl, on 26 Feb, 2009 - 05:52 PM, said:

This has been discussed many times before... and here you have a typical example
This the code produced by a Java IDE for a student who just start programming in Java
75% of the code was generated by the IDE
How do you think the poor fellow can follow and correct the problem

That is why GUI generator within an IDE is NOT a good idea for beginners
and now us, who try to help here, are going to read to understand the hundreds of lines generated by the GUI generator to decipher the problem. The code could have been written in 10 times less lines by a programmer and would have been readable.



Better to post your Netbeans (or whatever) project directly

Was This Post Helpful? 0
  • +
  • -

#6 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 27 February 2009 - 09:36 PM

I don't ridicule your work at all. Sorry if you misunderstood me.
I just say that it is almost impossible for a human being to understand the thousand of lines of code generated by a GUI builder in an IDE. Then to find a problem into those lines....
OK you can argue that all VB Programmers learn that way.

In Java don't know many programmers that would use a GridBagLayout unless really forced to do so because it is really complicated. In seven years of extensive Java programming I always manage to stay away from it.
A group of us, at DIC, had this discussion many times: should we use a GUI builder or not ? And if so which one is the best ?
I have presented my arguments a few times in these discussions. Here is your post that proves exactly my arguments... so I took your post as an example. Sorry if it offuscate you.. my scincere apologies.

But the major point is: if somebody has the time and courage to analyse your IDE/GUI generated code to find your problem good for you (and good for him it is a challenging issue) but do not put too much faith in hoping to receive an answer to your question... you are asking us a very difficult question.

You are throwing at us thousand lines of code, that you haven't written (it is the IDE which wrote them for you), and you ask us: "Can you fix it ?"
In a sense you are right. I could have, and should have according to your reaction, simply ignore your post but your post is a good example of the problems caused by GUI generators. Sorry again if being quote as an example insult you. That was not my intention at all. We are here to help newbies (and some times even professionals) to fix their Java problems and I think that we do a real good job at it (hundreds of thank you messages and even gifts received prove it) but please don't ask us to fix your IDE problem.

Sorry if I put your topic, as an example, into the middle of completly different discussion where you were not involved. I guess it would have been more politically correct to have replied in the other topics, where these issues were discussed, and just mention this topic as an example rather than having put the reply here.

I have replied to more than 4000 questions in this forum since the last year and be thanked more than 300 times (and the "This post was usefull" feature was implemented months after I joinded that forum) so I think that my replies are appreciated and so give me a break if your "tuition" phylosophy does not match mine

This post has been edited by pbl: 01 March 2009 - 04:33 PM

Was This Post Helpful? 0
  • +
  • -

#7 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 28 February 2009 - 09:51 PM

We should have a policy about that...
same problem have a look here:

http://www.dreaminco...wtopic89655.htm
Was This Post Helpful? 0
  • +
  • -

#8 alexriverajr   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 25-February 09

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 02 March 2009 - 12:36 AM

Just want to say that I really appreciate your wisdom. I understand that GUI generators make alot of extra code and can be difficult to sift through, however in this case it was just a learning tool. I wasn't asking for someone to fix my code just asking for advice on how to accomplish a particular task. Again thanks and ill keep in mind about using GUI builder.
Was This Post Helpful? 0
  • +
  • -

#9 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Clearing/Resetting Checkboxes and Radiobuttons

Posted 02 March 2009 - 04:53 PM

View Postalexriverajr, on 1 Mar, 2009 - 11:36 PM, said:

Just want to say that I really appreciate your wisdom. I understand that GUI generators make alot of extra code and can be difficult to sift through, however in this case it was just a learning tool. I wasn't asking for someone to fix my code just asking for advice on how to accomplish a particular task. Again thanks and ill keep in mind about using GUI builder.

No problem and you will always be welcomed
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1