Hello programmers,
I got a problem, I want to open a file on my Computer with Greenfoot. But how?
I try it with this code but it didn´t work:
public class Bibliothek extends Actor
{
/**
* Act - do whatever the Bibliothek wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (Greenfoot.mouseClicked( this))
{
if (mouse != null)
{
if (mouse.getClickCount() == 1)
{
if (mouse.getButton() == 1)
{
Open();
}
}
}
}
}
private void Open(){
Desktop desktop = null;
if (!Desktop.isDesktopSupported()) {
return;
}
desktop = Desktop.getDesktop();
String path = "Desktop/School ";
try {
File fPath=new File(path);
if(!fPath.exists()){
return;
}
if(!fPath.isDirectory()){
return;
}
desktop.open(new File(path));
} catch (IOException e) {
e.printStackTrace();
return;
}
}
}

