0

I'm currently building a system that takes an order for snacks. The system has a GUI interface, with the application code stored in a model package. so Ive done the main windows and it consists of three radio button and one sale button. so the radio buttons are "MAINS" , "SIDES" , "DRINKS". the problem i have is how do i code the action listener for each of the buttons in conjuction to the model package. this what I have.

import java.text.*;
import java.util.*;
import model.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class LeftPanel extends JPanel 
{

    private ButtonGroup group = new ButtonGroup();

    private String groupName;

    public LeftPanel(Groups groups)
    {

        setup();
        build();
    }

    private void setup()
    {
        setLayout(new GridLayout(3,1));

    }

    private void build()
    {
        Box box = Box.createVerticalBox();
        box.add(Box.createHorizontalStrut(65));

        add(button("Mains", new MainsListener()));
        add(button("Sides", new SidesListener()));
        add(button("Drinks", new DrinksListener()));

    }
    private JRadioButton button(String s, ActionListener listener)
    {
        JRadioButton button = new JRadioButton(s);
        button.addActionListener(listener);
        group.add(button);
        return button;
    }
    private class MainsListener implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {

            groupName = e.getActionCommand();
            Groups groups = Groups.groups(groupName);
            new StockWindow(group);

        }
    }

private class SidesListener implements ActionListener

    {

public void actionPerformed(ActionEvent e)

{

groupName = e.getActionCommand();

Groups groups = Groups.groups(groupName);

new StockWindow(group);

}

}

private class DrinksListener implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            groupName = e.getActionCommand();
            Groups groups = Groups.groups(groupName);
            new StockWindow(group);
        }
    }

}

Groups is in the model package which reads the stock

package model;


import java.util.*;


public class Groups extends Viewable 

{   

private LinkedList<Group> groups = new LinkedList<Group>();

    public Groups()          
    {   Group group = new Group("Mains");
        group.add(new Snack("burger"));
        group.add(new Snack("wrap"));
        groups.add(group);
        group = new Group("Sides");
        group.add(new Snack("fries"));
        group.add(new Snack("muffin"));
        group.add(new Snack("hashBrown"));
        groups.add(group);
        group = new Group("Drinks");
        group.add(new Snack("coke"));
        group.add(new Snack("koffee"));
        group.add(new Snack("slurpee"));
        group.add(new Snack("tea"));
        group.add(new Snack("juice"));
        groups.add(group);  }

    public LinkedList<Group> groups()
    {   return groups;    }
}
  • I'm pretty sure this has nothing to do with Android... – MadProgrammer Oct 28 '14 at 05:29
  • Sounds like you need a `CardLayout`, see [How to Use CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) for more details and some kind of `Map` to manage the groups, see [Collections Trail](http://docs.oracle.com/javase/tutorial/collections/) for more details – MadProgrammer Oct 28 '14 at 05:33
  • More on Swing MVC [here](http://stackoverflow.com/a/3072979/230513). – trashgod Oct 28 '14 at 09:51

0 Answers0