GregD
unread,Apr 18, 2012, 10:00:05 AM4/18/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to monkeybars-mvc
Here is a snippet of Java code that implements a custom action
listener on multiple panels when initialized.
protected void initContent()
{
int
x = 10,
y = 325,
w,
h,
pad = 5;
String
level = "";
int
laneNo = 0;
PnlPackLaneDisplay
pnlDisplay;
......
lstLanes = new ArrayList<PnlPackLaneDisplay>();
for(int i = 0; i < 2; i++)
{
for(int j = 1; j <= 8; j++)
{
laneNo++;
pnlDisplay = new PnlPackLaneDisplay(laneNo, level, c);
rl.setLayoutConstraints(pnlDisplay, new Rectangle(x, y, 100,
200 ));
add(pnlDisplay);
lstLanes.add(pnlDisplay);
PackPanelButtonListener ppbl = new
PackPanelButtonListener(pnlDisplay);
pnlDisplay.addPanelActionListener(ppbl);
x = x + 100 + pad;
}
//was "A" level = "B";
y = 120; // + 200 + 5;
x = 10;
}
.....
}
public class PnlPackLaneDisplay extends JPanel
{
.....
public PnlPackLaneDisplay(int laneNo, String level )
{
this(laneNo, level, Color.pink);
}
public PnlPackLaneDisplay(int laneNo, String level, Color
titleColor)
{
super();
this.level = level;
this.laneNo = laneNo;
this.titleColor = titleColor;
init();
}
protected void init()
{
....
}
....
public void addPanelActionListener(ActionListener al)
{
btnPack.addActionListener(al);
btnContents.addActionListener(al);
btnOrder.addActionListener(al);
}
}
/**
* Action listener for buttons on lane display panels; each panel
* gets its own listener object
*/
public class PackPanelButtonListener implements ActionListener
{
protected PnlPackLaneDisplay
pnl;
public PackPanelButtonListener(PnlPackLaneDisplay pnl)
{
this.pnl = pnl;
}
public void actionPerformed(ActionEvent e)
{
String
cmd;
cmd = e.getActionCommand();
if(cmd.equals("contents"))
{
....
}
else if(cmd.equals("pack"))
{
Integer
i;
i = Integer.class.cast(pnl.getCurrentQty());
Tracer.msg(TRACER_PACK_STATION, "Current PACK LOCATION = " +
pnl.getLocationId());
Tracer.msg(TRACER_PACK_STATION, "Current QTY = " +
i.intValue());
sendPackMessage(pnl.getLocationId(), i);
}
}
}
I'd like to implement the a similar thing using ruby and not java.
Is it possible to create a custom listener in the controller or they
always <component>_<event_type>?