FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Integration
(Moderators: fry, REAS)
   popup menu for use in p5?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: popup menu for use in p5?  (Read 977 times)
_C


popup menu for use in p5?
« on: Dec 6th, 2004, 9:02pm »

hi  
 
is there a way to use java PopupMenus inside  
the p5 api? this could be pretty useful for  
many applications written in p5. i tried but  
it was so unsatisfying.
 
thanks for any hints
c
 
michael05

WWW
Re: popup menu for use in p5?
« Reply #1 on: Dec 9th, 2004, 6:56pm »

you can use the awt menu items. i tried it months ago. here is my unfinished sketch:
Code:

TextField inputLine = new TextField("inputLine", 15);
TextArea inputArea = new TextArea("inputArea", 5, 20);
 
void setup() {
  size(640, 480);
 
  //setBounds(0,0,100,100);
  add(inputLine);
  add(inputArea);
}
 
void loop()
{
  background(255);
}
 
void mousePressed()
{
  String iLine = inputLine.getText();
  String iArea = inputArea.getText();
  println("inputLine: " + iLine);
  println("inputArea: " + iArea);
}
 

°°°°°°°°°°°°°°°°°°°°
http://www.m05.de
michael05

WWW
Re: popup menu for use in p5?
« Reply #2 on: Dec 9th, 2004, 6:59pm »

ressources:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/PopupMenu.html
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/TextField.html
 
i had some major problems to arrange them on the screen.
 

°°°°°°°°°°°°°°°°°°°°
http://www.m05.de
_C


Re: popup menu for use in p5?
« Reply #3 on: Dec 10th, 2004, 3:51pm »

thank you michael. just wanted to build  
a little menu that pops up downwards if you  
click on the little arrow on the right,  
also because building gui in p5 is not  
really fun.  
 
c
 
michael05

WWW
Re: popup menu for use in p5?
« Reply #4 on: Dec 12th, 2004, 2:01pm »

i think that's you are looking for:
 
Code:

public PopupMenu popup;
 
void setup()
{
  size(640, 480);
 
  popup = new PopupMenu("Popup Sample");
  MenuItem m = new MenuItem("first entry");
  m.setActionCommand("first");
  MenuItem n = new MenuItem("second entry");
  popup.add(m);
  popup.add(n);
  add(popup);
}
 
void loop()
{
  background(255);
}
 
void mousePressed()
{
  //popup.show(this,mouseX,mouseY);
  //or
  popup.show(this,100,100);
}

 
it does not look nice but it is a kind of pulldown menu. in ths code there is a no actionlistener interface implemented. in order to recognize the clicked item you have to implement the actionlstener to your applet:
 
Code:

public class mySketch() extends BApplet implements ActionListener
{
   void setup()
   ...
 
   void loop()
   ...
 
   public void actionPerformed(ActionEvent event)
   {
 if (event.getActionCommand()=="first") {
    // the method to do when clicked
    println("first item clicked");
 }
   }
}
« Last Edit: Dec 12th, 2004, 6:07pm by michael05 »  

°°°°°°°°°°°°°°°°°°°°
http://www.m05.de
_C


Re: popup menu for use in p5?
« Reply #5 on: Dec 12th, 2004, 4:28pm »

yeah, actually i did not describe it the right way.
thank you, michael. that is functionally what i was
looking for /
 
_C


Re: popup menu for use in p5?
« Reply #6 on: Dec 12th, 2004, 5:00pm »

so, the Actionlistener does not work inside  
p5? is this an AWT thing? tried to implement
it but it did not work...
 
michael05

WWW
Re: popup menu for use in p5?
« Reply #7 on: Dec 12th, 2004, 6:26pm »

i should not write too fast with an us keyboard..
 
that's the right code. it works fine:
 
Code:

import java.awt.*;
import java.awt.event.*;
 
public class mySketch extends BApplet implements ActionListener
{
  public PopupMenu popup;
 
  public void setup()
  {
    size(640, 480);
 
    popup = new PopupMenu("Popup Sample");
     
    MenuItem m = new MenuItem("first entry");
    // set the string to compare when an item is clicked
    m.setActionCommand("first");
    m.addActionListener(this);
    popup.add(m);
     
    MenuItem n = new MenuItem("second entry");
    n.setActionCommand("second");
    n.addActionListener(this);
    popup.add(n);
     
    add(popup);
  }
 
  public void loop()
  {
    background(255);
  }
 
  public void mousePressed()
  {
    //popup.show(this,mouseX,mouseY);
    //or
    popup.show(this,100,100);
  }
 
  public void actionPerformed(ActionEvent event)
  {
    // ask which item has been clicked
    if (event.getActionCommand()=="first") {
  println("first item clicked");
    }
    else if (event.getActionCommand()=="second") {
  println("second item clicked");
    }
  }
}

 
you can build tree menues and other stuff it it, too.
 
good luck and see you tomorrow!
 
michael
 
 
 
 
« Last Edit: Dec 12th, 2004, 6:28pm by michael05 »  

°°°°°°°°°°°°°°°°°°°°
http://www.m05.de
_C


Re: popup menu for use in p5?
« Reply #8 on: Dec 12th, 2004, 6:54pm »

thanks alot! hope to use this in a way.  
see you
 
c
 
Pages: 1 

« Previous topic | Next topic »