tekk
YaBB Newbies
Offline
Posts: 3
Re: Help with file chooser
Reply #2 - Apr 7th , 2009, 3:15pm
Whoops, here's the rest of my code. I tried the loop/noLoop thing, but no dice so far. } class pickAudio { String path; float xpos, ypos, btnX, btnY; boolean clicked; pickAudio() { path = null; btnX = 50; btnY = 20; xpos = width - (btnX + 5); ypos = 5; clicked = false; } pickAudio(float sliderNum, float sliderTot) { path = null; btnX = 50; btnY = 20; xpos = width * (sliderNum / (sliderTot + 1)) - (btnX/2); ypos = height - btnY * 1.5; clicked = false; } void initialize() { JFileChooser chooser = new JFileChooser(); audioFileFilter audioFilter = new audioFileFilter(); chooser.setFileFilter(audioFilter); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); int returnVal = chooser.showOpenDialog(null); //print the path to the console if(returnVal == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().getAbsolutePath(); println("File path: " + path); } } void display() { click(); stroke(0); strokeWeight(2); if(clicked) { fill(200); } else { fill(150); } rect(xpos, ypos, btnX, btnY); fill(0); textSize(15); text("Music", xpos + 3, ypos + btnY * .7); } //called to check if the user is clicking the button boolean click() { if(locked && !clicked) { return false; } if((overRect(xpos, ypos, btnX, btnY) && mousePressed) || clicked == true) { clicked = true; locked = true; return true; } else { return false; } } } //FUNCTION TAKEN FROM THE HANDLES EXAMPLE FROM PROCESSING.ORG boolean overRect(float x, float y, float width, float height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } }