Results 1 to 2 of 2
  1. #1
    quinnvanorder is offline Member
    Join Date
    Feb 2012
    Posts
    31
    Rep Power
    0

    Unhappy Issue with getActionCommand

    Hello all, I have a project where I am supposed to create a mock pizza ordering system. I have built a rough layout with tabbed panes and borderlayout managers.

    I have successfully created a set of radio buttons for size (large, medium, small) and am now working on creating the totaling system. Here is where I am running into an issue. I have created an event listener in the pizza.java file and created values for each button, but as soon as I select any of them, eclipse throws tons of errors at me, all that say that line 41 is wrong. I have been smashing my face against the keyboard whilst trying to google-fu my way out of this with no success, so any help would be greatly appreciated.

    First, here is the file that displays everything
    Java Code:
    import javax.swing.*;
    
    public class LayoutDemo
    	{	public static void main (String[] args)
    			{	JFrame frame = new JFrame ("Layout Manager Demo");
    				frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    				JTabbedPane tp = new JTabbedPane();
    				tp.addTab ("Pizza", new Pizza());
    				//      tp.addTab ("Drinks", new Drinks());
    				//      tp.addTab ("Specials", new Specials());
    				frame.getContentPane().add(tp);
    				frame.pack();
    				frame.setVisible(true);
    			}
    	}
    and here is the file that does not like line 41

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Pizza extends JPanel implements ActionListener 
    {	static int large = 5;
    	static int medium = 4;
    	static int small = 3;
      
       public Pizza()
       		{	setLayout (new BorderLayout());
                setBackground (Color.green);
                JPanel b1 = new JPanel(new GridLayout(0,1));
                JRadioButton large = new JRadioButton("Large");
                JRadioButton medium = new JRadioButton("Medium");
                JRadioButton small = new JRadioButton("Small");
                JCheckBox bacon = new JCheckBox("bacon");
                ButtonGroup test = new ButtonGroup();
                test.add(large);
                test.add(medium);
                test.add(small);
               
                //listener
                large.addActionListener(this);
                medium.addActionListener(this);
                small.addActionListener(this);
               
                b1.add(large);
                b1.add(medium);
                b1.add(small);
                b1.add(bacon);
                JButton b2 = new JButton ("Top");
                JButton b3 = new JButton ("Total:");
          
                add (b1, BorderLayout.CENTER);
                add (b2, BorderLayout.NORTH);
                add (b3, BorderLayout.EAST);
                 
       		}
       public void actionPerformed(ActionEvent e) 
       		{	int total=e.getActionCommand();
       		}
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Issue with getActionCommand

    Your code obtains the value returned by getActionCommand() and attempts to assign it to a variable of type int. Read the API for the concerned class and find out the return type of getActionCommand().

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 03:33 AM
  2. How do I fix this issue?
    By m4mm4l in forum New To Java
    Replies: 8
    Last Post: 11-17-2011, 03:49 AM
  3. JSP issue
    By RamaLakshmi in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-21-2011, 01:55 PM
  4. nio issue
    By mawandiadeepak in forum Networking
    Replies: 2
    Last Post: 03-17-2010, 05:23 AM
  5. PDF Box issue
    By jazz2k8 in forum Advanced Java
    Replies: 0
    Last Post: 03-20-2009, 11:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •