//will be executed the next time the mt4j thread runs.
instance.invokeLater(new Runnable() {
public void run() {
MTRectangle r = new MTRectangle(0,0,ToolsMath.getRandom(50, 250),ToolsMath.getRandom(50, 250), instance);
r.setFillColor(new MTColor(ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255)));
r.addGestureListener(DragProcessor.class, new InertiaDragAction());
instance.getCurrentScene().getCanvas().addChild(r);
r.setPositionGlobal(new Vector3D(ToolsMath.getRandom(0, instance.width), ToolsMath.getRandom(0, instance.height)));
}
});
}
}
});
menu.add(addRectItem);
JMenuItem addRoundRectItem = new JMenuItem("MTRoundRectangle", KeyEvent.VK_E);
addRoundRectItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (instance.getCurrentScene() != null){
//If we want to modify the MT4j applet from the swing thread
//we should wrap the actions into an invokeLater runnable which
//will be executed the next time the mt4j thread runs.
instance.invokeLater(new Runnable() {
public void run() {
float arc = ToolsMath.getRandom(8, 25);
MTRoundRectangle r = new MTRoundRectangle(0,0,0, ToolsMath.getRandom(50, 250),ToolsMath.getRandom(50, 250), arc, arc, instance);
r.setFillColor(new MTColor(ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255)));
r.addGestureListener(DragProcessor.class, new InertiaDragAction());
instance.getCurrentScene().getCanvas().addChild(r);
r.setPositionGlobal(new Vector3D(ToolsMath.getRandom(0, instance.width), ToolsMath.getRandom(0, instance.height)));
}
});
}
}
});
menu.add(addRoundRectItem);
JMenuItem addEllItem = new JMenuItem("MTEllipse", KeyEvent.VK_E);
addEllItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (instance.getCurrentScene() != null){
//If we want to modify the MT4j applet from the swing thread
//we should wrap the actions into an invokeLater runnable which
//will be executed the next time the mt4j thread runs.
instance.invokeLater(new Runnable() {
public void run() {
MTEllipse e = new MTEllipse(instance, new Vector3D(0,0), ToolsMath.getRandom(50, 150),ToolsMath.getRandom(50, 150));
e.setFillColor(new MTColor(ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255)));
e.addGestureListener(DragProcessor.class, new InertiaDragAction());
instance.getCurrentScene().getCanvas().addChild(e);
e.setPositionGlobal(new Vector3D(ToolsMath.getRandom(0, instance.width), ToolsMath.getRandom(0, instance.height)));
}
});