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
   Syntax
(Moderators: fry, REAS)
   Open Dialog (Frame?)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Open Dialog (Frame?)  (Read 411 times)
skloopy

WWW
Open Dialog (Frame?)
« on: May 6th, 2004, 11:00pm »

Hi I saw how Moovl has an Open and Save dialog, and i wanted to use them with my own stuff. I know it's pretty hard to get that to work with applets, so I only really want it to work inside P5 for now.
 
I found this code that's supposed to do it
 
Code:
FileDialog = new FileDialog(Frame parent, String title, int mode);

It asks for a Frame as one of the parameters..
 
What is a Frame, and if P5 has one, how can I access it?
 
Oh BTW I found that code here http://jan.netcomp.monash.edu.au/java/swingtut/tut1a.html#dialogs
« Last Edit: May 6th, 2004, 11:01pm by skloopy »  
mKoser

WWW Email
Re: Open Dialog (Frame?)
« Reply #1 on: May 7th, 2004, 12:18am »

skimmed through the examples given in your link, and found a simple example ... and made this little sketch:
 
Code:

Hello a;
 
void setup(){
  a = new Hello();
}
 
void loop(){
}
 
class Hello extends Frame {
  /*
  public static void main(String argv[]) {
      new Hello();
  }
  */
 
  Hello() {
    Label hello = new Label("Hello World");
    add(hello, "Center");
    setSize(200, 200);
    setVisible(true);
  }
}

 
hehe, there's no listener set up for closing the Frame (window) - so you have to kill processing to kill the window!
 
+ mikkel
« Last Edit: May 7th, 2004, 12:19am by mKoser »  

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
skloopy

WWW
Re: Open Dialog (Frame?)
« Reply #2 on: May 7th, 2004, 12:51am »

Oh okay thanks Mikkel
 
I guess all i needed to do is make a new Frame as the parameter
 
Code:
void setup() {
  FileDialog fd = new FileDialog(new Frame(), "Yo");
  fd.setVisible(true);
  System.out.println("Selected: " + fd.getDirectory() + fd.getFile());
}

That'll give you the path to load a file. Weird.. I wonder what it needs the Frame for then?
 
Update: Oh I think this will only work on files inside P5's data folder.. I'm loading the files into a Sonia sample but i think that all of the file loading functions assume that everything is in that folder..
« Last Edit: May 7th, 2004, 12:59am by skloopy »  
TomC

WWW
Re: Open Dialog (Frame?)
« Reply #3 on: May 7th, 2004, 1:03am »

I think you pass it a parent reference so that it knows to not pass on mouse clicks to the parent.
 
e.g. in Internet Explorer 6, if I click File... Open... then whilst the dialog is open I can't click on the webpage or buttons.  That's fairly standard in Windows type software - so doubtless Apple did it first, or Xerox, whatever...
 
fry


WWW
Re: Open Dialog (Frame?)
« Reply #4 on: May 7th, 2004, 6:02am »

on May 7th, 2004, 12:51am, scloopy wrote:
Update: Oh I think this will only work on files inside P5's data folder.. I'm loading the files into a Sonia sample but i think that all of the file loading functions assume that everything is in that folder..

sorta but not really.. you can use:
 
Code:
try {  // since we're in java-land now
  FileInputStream stream = new FileInputStream(new File(directory, filename));
  // and then:
  String stuff[] = loadStrings(stream);
  // or:
  String bytes[] = loadBytes(stream);
} catch (Exception e) {
  e.printStackTrace();
}
 
fry


WWW
Re: Open Dialog (Frame?)
« Reply #5 on: May 7th, 2004, 6:04am »

on May 7th, 2004, 1:03am, TomC wrote:
I think you pass it a parent reference so that it knows to not pass on mouse clicks to the parent.

right, i believe it's to do with some windowing systems using a parent/child model for all windows, in addition to modal dialogs (where you're locking out key presses). using just "new Frame()" works fine in most circumstances.  
 
mKoser

WWW Email
Re: Open Dialog (Frame?)
« Reply #6 on: May 7th, 2004, 11:53am »

hmm, sorry scloppy, being a bit tired, and trying to be clever on these boards isn't always a good thing... hehe, i didn't really read your initial post well enough!
 
FileDialog ... nice! (and now, i'll shut up!)
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
Pages: 1 

« Previous topic | Next topic »