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; }
}