Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Java (or J2ME) question

  • 19-11-2008 08:16PM
    #1
    Closed Accounts Posts: 2,349 ✭✭✭


    For a J2ME project I have this problem:

    I have a class that is basically a File Browser for the phone. The class is instantiated in the main java file i.e.
    public void startApp() {
            FileBrowser browser = new FileBrowser(Display.getDisplay(this), true);
    ........
    }
    

    The user selects a file and I want the main class to wait until this happens. How can I do it?

    I know I can do it with a callback function but my code just starts to get overcomplicated, can I make the main class wait until an event has occured in the FileBrowser class?


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 10,093 Mod ✭✭✭✭marco_polo


    grasshopa wrote: »
    For a J2ME project I have this problem:

    I have a class that is basically a File Browser for the phone. The class is instantiated in the main java file i.e.
    public void startApp() {
            FileBrowser browser = new FileBrowser(Display.getDisplay(this), true);
    ........
    }
    

    The user selects a file and I want the main class to wait until this happens. How can I do it?

    I know I can do it with a callback function but my code just starts to get overcomplicated, can I make the main class wait until an event has occured in the FileBrowser class?

    Not sure how well it is supported in J2ME but I would use a seperate thread for the file browser if possible, you can then wait for an answer in the main thread. The browser thread should notify the main thread when a file is selected by the user.


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    Thanks, I'll try that. Only done threads in C so I'm eager to find another way! If anyone has a simpler way do chime in :)

    Edit: Turns out it's very easy and I can use "wait()" and "notify()" - see http://www.crazysquirrel.com/computing/java/concurrency/wait-and-notify.jspx for anyone having trouble


  • Registered Users, Registered Users 2 Posts: 21,611 ✭✭✭✭Sam Vimes


    i know in J2SE you can call a method called int returnVal = fc.showOpenDialog(.....)

    and it opens the chooser box and the program waits until you choose a file. I'd assume it's something similar in J2ME


Advertisement