Hi, i do have problem with event handling
im done with layouting but the only thing i dont know is what methods of event handling should i use in my program

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.ButtonGroup;



public class Pizza extends Frame implements ActionListener,ItemListener {
	JFrame frame = new JFrame();
	JLabel pizza = new JLabel("Pizza");
	JLabel price = new JLabel("Price");
	JLabel size = new JLabel("Size");
	JTextField space1 = new JTextField(15);
	JTextField space2 = new JTextField(15);
	JLabel space3 = new JLabel("");
	JLabel cost = new JLabel("Cost");
	JButton but = new JButton("Clear");

	JPanel panel_main = new JPanel();
	JPanel panel_toppings = new JPanel();
	JPanel panel_size = new JPanel();
	JPanel panel_upper = new JPanel();
	JPanel panel_lower = new JPanel();
	JPanel panel_center = new JPanel();


	String [] options = {"Hawaiian Overload","All Meat","Vegetarian's Pizza" };
	JComboBox combo =  new JComboBox(options);
	int [] solo = {250,240,220};
	int [] medium = {350,340,300};
	int [] fam = {550,540,400};



	TitledBorder border_size = new TitledBorder("Size");
	JRadioButton rbut1 = new JRadioButton("Solo");
	JRadioButton rbut2 = new JRadioButton("Medium");
	JRadioButton rbut3 = new JRadioButton("Family");

	TitledBorder border_size2 = new TitledBorder("Extra Toppings");
	JCheckBox cbx1 = new JCheckBox("Cheese(25)");
	JCheckBox cbx2 = new JCheckBox("Mushroom(35)");
	JCheckBox cbx3 = new JCheckBox("Pineapple(30)");




    public Pizza() {

    	frame.setVisible(true);
    	frame.setSize(300,200);
    	frame.setResizable(false);
    	frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

    	frame.add(panel_main);
    	panel_main.setLayout(new BorderLayout());
    	panel_main.add(panel_upper);
    	panel_upper.setLayout(new GridLayout(2,2));
    	panel_upper.add(pizza);
    	panel_upper.add(combo);
    	panel_upper.add(price);
    	panel_upper.add(space1);

    	panel_main.add(panel_center);
    	panel_center.setLayout(new GridLayout(1,1));
    	panel_center.add(panel_size);
    	panel_size.setLayout(new GridLayout(3,1));
    	panel_size.setBorder(border_size);
    	panel_size.add(rbut1);
    	panel_size.add(rbut2);
    	panel_size.add(rbut3);

	panel_center.add(panel_toppings);
	panel_toppings.setLayout(new GridLayout(3,1));
	panel_toppings.setBorder(border_size2);
	panel_toppings.add(cbx1);
	panel_toppings.add(cbx2);
	panel_toppings.add(cbx3);

	panel_main.add(panel_lower);
	panel_lower.setLayout(new GridLayout(2,2));
	panel_lower.add(cost);
	panel_lower.add(space2);
	panel_lower.add(space3);
	panel_lower.add(but);
	but.addActionListener(this);


	panel_main.add(panel_upper,BorderLayout.NORTH);
	panel_main.add(panel_center,BorderLayout.CENTER);
	panel_main.add(panel_lower,BorderLayout.SOUTH);

	ButtonGroup bttG = new ButtonGroup();
	bttG.add(rbut1);
	bttG.add(rbut2);
	bttG.add(rbut3);






	}
	public void actionPerformed(ActionEvent event){
		
	}
	public void itemStateChanged(ItemEvent e){

	}

	public static void main(String[]args){
		Pizza $ = new Pizza();

		}
	}

I crate an array to store the prices for each size of pizza.

the default size should be medium and the price textfield should display amount of the currently selected pizza while cost textfield should display the computed sum of price + extra charge

i dont know what are methods should i use :((


to all masters of java pls. help me


woaah this will be pass tom... hoping that you can help me plssssssss....

sorry for my english..

Declare Button's Objects as Global.

In actionPeformed Method do what you want as reaction of buttons

1st get source of event

Object src = ae.getSource();

now check which button is clicked... by using if conditions...

if(src==btn1)
{
thn do what you want... like clear all textfields etc...
}
else if(src==btn2)
{
other functionalities....
}


http://download.oracle.com/javase/tutorial/uiswing/events/intro.html

still having problem let me know...

Declare Button's Objects as Global.

In actionPeformed Method do what you want as reaction of buttons

1st get source of event

Object src = ae.getSource();

now check which button is clicked... by using if conditions...

if(src==btn1)
{
thn do what you want... like clear all textfields etc...
}
else if(src==btn2)
{
other functionalities....
}


http://download.oracle.com/javase/tutorial/uiswing/events/intro.html

still having problem let me know...

yeah thanks man... :)

but what methods should i use to insert the values of my comboBox

for eg. when i click the item of comboBox its automatically get the value of that item :((

pls. help me

Member Avatar for hfx642

Here are some basics that you can get started with...

int myValue;

myCheckBox.addItemListener
(
   new ItemListener ()
   {
      public void itemStateChanged (ItemEvent IE)
      {
         myValue = myCheckBox.isSelected ();
      }  // End of itemStateChanged
   }  // End of ItemListener
);  // End of addItemListener

myRadioButton.addItemListener
(
   new ItemListener ()
   {
      public void itemStateChanged (ItemEvent IE)
      {
         if (IE.getStateChange () == ItemEvent.SELECTED)
         {
            myValue = 1;
         }
      }  // End of itemStateChanged
   }  // End of ItemListener
);  // End of addItemListener

myComboBox.addItemListener
(
   new ItemListener ()
   {
      public void itemStateChanged (ItemEvent IE)
      {
         if (IE.getStateChange () == ItemEvent.SELECTED)
         {
            myValue = myComboBox.getSelectedIndex ();
         }
      }  // End of itemStateChanged
   }  // End of ItemListener
);  // End of addItemListener

myButton.addActionListener
(
   new ActionListener ()
   {
      public void actionPerformed (ActionEvent AE)
      {
         // YOUR custom code here
      }  // End of actionPerformed
   }  // End of ActionListener
);  // End of addActionListener
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.