Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Phase one clean up! (windows style file loader/saver WANTED)

  1. #1
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default Phase one clean up! (windows style file loader/saver WANTED)

    Hi everyone! I finally have a nicely working version of my program and I am looking to clean up the file input/output.

    Currently I have used Strings, Files, and URLs, in a blended mess of concatenation, and though it all works perfectly,
    I need to expand in re-usability, and professionalism. My desire is to make your "Standard" file opener, exactly like say Microsoft word.
    The viewer will allow the user to look through the folder visually and select a file to load, as well as when saving see if they are saving
    over a file name already being used.

    If anyone knows of a good library that already has a class that does this, I would be extremely grateful, as putting together the GUI to do it from scratch seems almost as complex as my program itself.

    An example of the code I use currently to achieve these results:
        public CenterGrid(String fileName) {
            JPanel gridHolder = new JPanel();
     
            File file = new File(fileName); //Not responsible for checking for valid fileName. That is up to the loader.
            BufferedReader reader;
     
            // TODO: z CONVERTING URL EXAMPLE: (Project Aid)
            // System.getProperty("user.dir") = C:\Users\Jons\Desktop\TestFile Loading
            // curLineInfo                    = /Images/Terrain/Grass.png
            // URL NEEDS TO LOOK LIKE         = file:/C:/Users/Jons/Desktop/TestFile Loading/Images/Terrain/Grass.png       
            try {
                reader = new BufferedReader(new FileReader(file));
                String curLineInfo;
                myHeight = Integer.parseInt(reader.readLine());// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
                myLength = Integer.parseInt(reader.readLine());// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
                tiles = new Tile[myHeight*myLength]; //creates array long enough for the area of Tile objects.
     
                gridHolder.setLayout(new GridLayout(myHeight,myLength));
     
                int idx = 0;// keeps track of the array index
                while ((curLineInfo = reader.readLine()) != null) {// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
                    Tile tile = new Tile();
                    String terrainStringURL = ("file:/" + System.getProperty("user.dir").replace('\\','/') + curLineInfo); //build curLineInfo into a useable URL
                    Terrain terrainFromFile = new Terrain(new URL(terrainStringURL), tile);
                    tile.addTerrain(terrainFromFile);
                    gridHolder.add(tile);
                    tiles[idx]=(tile);
                    idx++; 
                }
            } catch(FileNotFoundException e){} catch (IOException ex) {}// TODO: x currently ignoring standard error checking. need to make sure everything is covered.
     
            add(gridHolder);
            gridHolder.setVisible(true);
        }

    So I have sections of zoo like appearance I would prefer to clean up before I handle my programs ability to load multiple folders.
    I will write a class to clean up the "on the spot" code look, but before I do, I wanted to see if I could get the golden apple and instead
    get the windows style loader, and just rewrite to use that classes functionality instead.

    Hopefully I am being clear.

    I will post a .zip file that has the .jar and the folders needed to run the program so you can get a feel for what is is capable of.

    Thanks as always,
    Jonathan


  2. #2
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default Re: Phase one clean up! (windows style file loader/saver WANTED)

    imported classes for my .jar program (attempting to ensure a malware free promise)
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import java.awt.event.*;
    import javax.swing.*;

    There are no infinite loops, or memory leaks.
    The program has no hidden agenda other then its very visual functionality.

    I have run it using windows 7 and JDK 7u3-nb-7_1 with netbeans 7.1.1-ml-javase

    it has the ability to make a large amount of JPanels, but I have caped the users input to 100x100, 10,000. the default is 20x30, 600.

    Currently the loader automatically loads test.txt from the Maps folder.
    I have not done any error checking involving a user creating bad data to load, but it will most certainly just result in the program not loading pictures to JPanels.

    If I could get some basic testing on other platforms that would be amazing.
    Thanks,
    Jonathan
    Attached Files Attached Files

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Phase one clean up! (windows style file loader/saver WANTED)

    Perhaps I mis-undertand your requirements, but wouldn't a JFileChooser suffice?
    How to Use File Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

  4. #4
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default Re: Phase one clean up! (windows style file loader/saver WANTED)

    looks very promising, Ill let you know tomorrow when i get it all working.
    Thanks Copeg (as usual) once I get this thing running and hopefully marketed, Ill be sure to send you some meager royalties lol.

Similar Threads

  1. Windows 7 - jar file not opening a window
    By Yaten13 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 10th, 2011, 05:53 PM
  2. Trying to figure out how to make a screen saver.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 59
    Last Post: August 8th, 2011, 07:05 AM
  3. [SOLVED] jar file Built(clean and build) perfectly, but not running as jar
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: July 11th, 2011, 11:41 AM
  4. Please help me clean up my code!
    By Java Neil in forum What's Wrong With My Code?
    Replies: 8
    Last Post: February 25th, 2011, 02:48 PM
  5. My Jar File Crashing Windows 7
    By PrinceSendai in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 19th, 2011, 02:49 PM

Tags for this Thread