How to implement Action Listener

don't know how to get the vakues in Jbutton,JRadioBox,JTExtFeild,C

Page 1 of 1

1 Replies - 5634 Views - Last Post: 06 October 2008 - 12:56 AM Rate Topic: -----

#1 ailaine   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-October 08

How to implement Action Listener

Post icon  Posted 06 October 2008 - 12:20 AM

help me pls...it's urgent..I've been doin' this for a long time..but,still I cannot figure it out how..
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class aiai_pizza extends JFrame 
{

		public JPanel panel1,panel2,panel3,panel4,paneltop,paneltop2,pbutton,pbutton2;
		public JPanel money,money2,panelDis,panelDis2,result;
		public JComboBox cb1;
		public JRadioButton rbsSize,yes,no;
		public ButtonGroup dinnerGrp,gcrust,yesno;
		public JRadioButton rb1,rb2,rb3,rb4;
		public JRadioButton htossed,tcrust,ddish;
		public JCheckBox sausage,pepperoni,cheese,ham,olive,mushroom,pineapple; 
		public JLabel l1,l2,l3,topings,c,dis,dis2,dis3,totamt,tenamt,sukli;
		public JTextArea text;
		public JButton reset,add;
		public JTextField dcount,tot,ten,cha;
		public JScrollBar scroll;
		public JLabel textko;
		public JLabel out;
		
		public void wahhh()
		{
			setTitle("Pizza Order Form");
			setSize(340,600);
			setResizable(false);
			setLocationRelativeTo(null);
			setLayout(new GridLayout(0,1));

//////////////////////panel_declarations////////////////	
		
			panel1 = new JPanel(new FlowLayout()); 
			panel4 = new JPanel(new FlowLayout());
			
			paneltop = new JPanel(new GridLayout(4,2));
			paneltop2 = new JPanel(new BorderLayout());
			panel2 = new JPanel(new BorderLayout());
			
			
			panelDis=new JPanel(new FlowLayout());
			panelDis2=new JPanel(new BorderLayout());
			
			pbutton=new JPanel(new FlowLayout());
			pbutton2=new JPanel(new BorderLayout());
			
			result=new JPanel(new BorderLayout());
			
			money=new JPanel(new GridLayout(3,2));
			money2=new JPanel(new BorderLayout());	

////////////////////quantity///////////////////////////////
			
			l1 = new JLabel("Quantity");
			l3 = new JLabel("Box(es)														");
			
			cb1 = new JComboBox();
			for(int x=1;x<101;x++)
			{
				cb1.addItem(x);
			}
			
		
////////////////////size/////////////////////////			
			
			l2 = new JLabel("   Size");
			
			dinnerGrp = new ButtonGroup();
			rb1 = new JRadioButton("Small");
		 	rb2 = new JRadioButton("Medium");
			rb3 = new JRadioButton("Large");
			rb4 = new JRadioButton("Family Size");

			dinnerGrp.add(rb1);
			dinnerGrp.add(rb2);
			dinnerGrp.add(rb3);
			dinnerGrp.add(rb4);

//panel1 (quan_size)
			panel1.add(l1);			
			panel1.add(cb1);
			panel1.add(l3);
			panel1.add(l2);			
			panel1.add(rb1);
			panel1.add(rb2);
			panel1.add(rb3);
			panel1.add(rb4);
			
/////////////////////toppings////////////////////////////
			
			topings = new JLabel("	Toppings		");
			
			sausage = new JCheckBox("Sausage ");
			pepperoni = new JCheckBox("Pepperoni");
			cheese = new JCheckBox("Cheese");
			ham = new JCheckBox("Ham");
			olive = new JCheckBox("Olive");
			mushroom = new JCheckBox("Mushroom");
			pineapple = new JCheckBox("Pineapple");
			

//Panel2 (toppings) 	(paneltop and paneltop2)	
		
			paneltop.add(sausage);
			paneltop.add(pepperoni);	
			paneltop.add(cheese);	
			paneltop.add(ham);	
			paneltop.add(olive);				
			paneltop.add(mushroom);
			paneltop.add(pineapple);
			
			paneltop2.add(topings,BorderLayout.NORTH);
			
			panel2.add(paneltop2,BorderLayout.WEST);
			panel2.add(paneltop,BorderLayout.CENTER);

///////////////////crust///////////////

			gcrust = new ButtonGroup();
			
			c=new JLabel("Crust");
			htossed = new JRadioButton("Hand-tossed");
		 	tcrust = new JRadioButton("Thin-crust");
			ddish = new JRadioButton("Deep Dished");

			gcrust.add(htossed);
			gcrust.add(tcrust);
			gcrust.add(ddish);
			
//Panel4(crust)
			panel4.add(c);
			panel4.add(htossed);
			panel4.add(tcrust);
			panel4.add(ddish);
			
			
////////////////////Discount///////////////////////

			dis=new JLabel("   Discount");
			dis2=new JLabel("		   If Yes,");
			dis3=new JLabel("%");
			
			
			yes=new JRadioButton("Yes");
			no=new JRadioButton("No");
			dcount=new JTextField(5);
			
			yesno=new ButtonGroup();
			
			yesno.add(yes);
			yesno.add(no);
			
//panelDis(discount)

			panelDis.add(dis);
			panelDis.add(yes);
			panelDis.add(no);
			panelDis.add(dis2);
			panelDis.add(dcount);
			panelDis.add(dis3);
			
			panelDis2.add(panelDis,BorderLayout.WEST);

////////////////////Buttons////////////////////////
				
			reset=new JButton("Reset");
			add=new JButton("Add");
			
//pbuttons	
			pbutton.add(reset);
			pbutton.add(add);
			pbutton2.add(pbutton,BorderLayout.EAST);

////////////////////textArea////////////////////////
			textko=new JLabel("  Qty			Size			 Crust			 Price			 Subtotal");
			text=new JTextArea(60,60);
			text.setLineWrap(true);
			scroll=new JScrollBar(Adjustable.VERTICAL);
			
//result (text area)
			result.add(textko,BorderLayout.NORTH);
			result.add(text,BorderLayout.CENTER);
			result.add(scroll,BorderLayout.EAST);
			
////////////////////Total////////////////////////
			
			totamt=new JLabel("Total Amount");
			tenamt=new JLabel("Tendered Amount");
			sukli=new JLabel("Change");
			
			tot=new JTextField(10);
			ten=new JTextField(10);
			cha=new JTextField(10);
			
//money (panel for money)
			money.add(totamt);
			money.add(tot);
			money.add(tenamt);
			money.add(ten);
			money.add(sukli);
			money.add(cha);
			money2.add(money,BorderLayout.EAST);
		
			
//////////////////FINAL_ADDITION!yeah!///////////////			
		
			add(panel1);
			add(panel2);
			add(panel4);
			add(panelDis2);
			add(pbutton2);
			add(result);
			add(money2);
			setVisible(true);
				
		}
			
	public static void main(String[]args)
	{
		aiai_pizza ako = new aiai_pizza();
		ako.wahhh();
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: How to implement Action Listener

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3601
  • View blog
  • Posts: 16,472
  • Joined: 20-September 08

Re: How to implement Action Listener

Posted 06 October 2008 - 12:56 AM

See

http://java.sun.com/...onlistener.html

but it's actually preferable to use an Action in Swing:

http://java.sun.com/...isc/action.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1