We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Abusing AWT for menus in Processing
Page Index Toggle Pages: 1
Abusing AWT for menus in Processing (Read 432 times)
Abusing AWT for menus in Processing
Jul 14th, 2007, 2:00am
 
We all already know that strictly speaking, we should never use AWT or Swing stuff inside of Processing.  That said, some of it actually seems to work okay - I just discovered today that at least on OS X you can (apparently) safely set the title bar and add menus as long as you're in application mode, just like you would in a normal AWT app:

Quote:


Menu fm;
MenuItem ol,sl;
boolean action(Event e, Object arg) {
   if (e.target == ol) {
     println("Here's where you would put your file loading code.");
     return true;    
   } else if (e.target == sl) {
     println("And here's where you would save.");
   }
   return super.action(e,arg);
}
void setup(){
 size(400,400);
 this.frame.setTitle("Oh crap, I messed with the title bar!");
 MenuBar mb = new MenuBar();
 mb.add(fm = new Menu("File"));
 fm.add(ol = new RedirectingMenuItem(this,"Open"));
 fm.add(sl = new RedirectingMenuItem(this,"Save"));
 this.frame.setMenuBar(mb);
 background(0);
}
void draw(){
 //nothing for now
}
public class RedirectingMenuItem extends MenuItem {
 private Component event_handler;
 public RedirectingMenuItem(Component event_handler, String label) {
   super(label);
   this.event_handler = event_handler;
 }
 public boolean postEvent(Event e) {
   if (event_handler.isValid()) return event_handler.postEvent(e);
   else return false;
 }
}



I'm not sure if this works in Windows, haven't gotten a chance to check yet; anyhow, see if it works for you, could be useful.
Page Index Toggle Pages: 1