can someone help me with my java assignment please?

Discussion in 'Mac Programming' started by apattee, Oct 25, 2007.

  1. macrumors regular

    Joined:
    Oct 19, 2006
    #1
    i'm really lost. i'm supposed to write a program that gets input from dialog boxes and then produces the output to a file. suppose the input was asking for your name. can someone help me please? the homework is more complex then that but that will help me figure it out after that. thanks.
     
  2. macrumors 6502

    hankolerd

    Joined:
    Sep 19, 2007
    Location:
    Seattle, WA
    #2
    i've never worked with dialog boxes in java, just command line or from a file. But i assume that the spaces in a dialog box are assigned to variables, so when you enter a name, it is stored in a variable, or maybe a variable array. though I may be very wrong.
    Once you find out how to get the input, writing to a file is pretty easy.
    First you will need to use the FileWriter class. Depending on what version of java you are using, this sight is very helpful http://java.sun.com/j2se/1.5.0/docs/api/
    anyway...
    for writing to a file, do something like this.
    PrintWriter fout = new PrintWriter(new FileWriter("filename"));
    fout.println("Whatever you want " + your_data + " you get the idea");
    fout.close()
    DONT FORGET THAT LAST LINE! If you don't close the file, it will be empty when you try to open it, and it is frustrating to figure out what's wrong, until you finally realize you never close it. I hope that helps some

    Do you know what class you are using for the dialog box?? is it JOptionPane? or something different?:apple:
     
  3. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #3
    Are you looking for standalone application like think or webpage like.
    If you are going for standalone application looking for help in AWT or Swings.
    For Webpage, servelets and JSP are there.
    Pick the proper one as per ur requirements.
     

Share This Page