Results 1 to 2 of 2
  1. #1
    ninjakreborn is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default Issues getting file text to display in dialog, and overall code review.

    So i'm fairly new to Java. Below is my code.

    Java Code:
     * Author: Joyel Puryear
     * Website:
     * Title: Morrowind Swiss Army Knife
    /***** IMPORTS *****/
    import java.awt.Component;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class MorrowindSwissArmyKnife {
         * @param args the command line arguments
        public static void main(String[] args) {
            /***** CREATE FRAME *****/
            final JFrame frame = new JFrame("Morrowind Swiss Army Knife - Author Joyel Puryear (");
            /***** CREATE MENU BAR *****/
            JMenuBar menubar = new JMenuBar();
            /***** CREATE FILE MENU *****/
            // File menu item.
            JMenu file = new JMenu("File");
            // INI Editor sub menu
            JMenuItem mwinieditor = new JMenuItem("Morrowind INI Editor");
            class mwinieditoraction implements ActionListener {
                private Component aComponent;
                public void actionPerformed (ActionEvent e) {
                    //Create a file chooser
                    final JFileChooser fc = new JFileChooser();                
                    int returnVal = fc.showOpenDialog(null);
                    File file = null;
                    if(returnVal == JFileChooser.APPROVE_OPTION) {
                      file = fc.getSelectedFile();    
                    BufferedReader in = null;
                    try {
                        in = new BufferedReader(new FileReader(file));
                    } catch (FileNotFoundException ex) {
                        Logger.getLogger(MorrowindSwissArmyKnife.class.getName()).log(Level.SEVERE, null, ex);
                    String line = null;
                    try {
                        line = in.readLine();
                    } catch (IOException ex) {
                        Logger.getLogger(MorrowindSwissArmyKnife.class.getName()).log(Level.SEVERE, null, ex);
                    while(line != null){
                        try {
                            line = in.readLine();
                        } catch (IOException ex) {
                            Logger.getLogger(MorrowindSwissArmyKnife.class.getName()).log(Level.SEVERE, null, ex);
                    //default title and icon
                    JOptionPane.showMessageDialog(frame, line);
            mwinieditor.addActionListener(new mwinieditoraction());        
            // Exit sub item within File menu.
            JMenuItem exit = new JMenuItem("Exit");
            class exitaction implements ActionListener {
                public void actionPerformed (ActionEvent e) {
            exit.addActionListener(new exitaction());        
            /***** CREATE HELP MENU *****/
            JMenu help = new JMenu("Help");
            JMenuItem about = new JMenuItem("About");
            class aboutaction implements ActionListener {
                public void actionPerformed (ActionEvent e) {
                    //default title and icon
                            "--APPLICATION DETAILS--\n\n"
                            + "Application Name: Morrowind Swiss Army Knife.\n"
                            + "Application Version: 0.3\n"
                            + "Application Details: Once complete, this application is intended to be a one-stop-shop for all things Morrowind.\n"
                            + "In today's modding world there are hundreds of utilities. The standard player/modder has to switch between 3-6\n"
                            + "different utilities for various purposes. Each utility they use is generally pretty buggy and outdated. Very few\n"
                            + "utilities are actualy maintained and updated anymore.  The purpose of this app is to rebuild a new super utility to\n"
                            + "handle all the functionality of the misc utilities as well as to offer continued development support, and continuing\n"
                            + "to build onto..and improve the app.  To start off with I will be introducing a few features, and then expanding upon\n"
                            + "it as I have time, and have new ideas for utilities to build into it (both big and small).\n\n"
                            + "--DEVELOPER DETAILS--\n\n"
                            + "Developer Name: Joyel Puryear\n"
                            + "Personal Website:\n"
                            + "Business Website:\n");
            about.addActionListener(new aboutaction());
    Two questions.

    1. Any advice on how I can write better code, anything i'm doing wrong, or anything I can do to improve it.

    2. I can't get the "text" from the INI file to display in a dialog. For now. My ultimate goal is to parse the ini file and read the values into a table. Left
    side will be ini variable name, right side will be current value, then beside that is the "new" value you want to replace it with.

    Right now I just want to display it in dialog so I know i'm reading it. Then i'll start learning/implementing the parsing of it and putting it into a table.

    So anyway. Just curious why it's not showing in the dialog, and if there's anything I can do to improve my code, since I am just learning.

    Also I don't understand my editor. I am using Netbeans and I tried to make a simple implementation but it started throwing a lot of errors and wanted me to bunch of try/catch
    stuff in there. Is that the proper way to do all of that. Because when I first wrote it, it was very clean. Now there is a lot of extra code that was recommended by Netbeans.

    Thanks again!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Issues getting file text to display in dialog, and overall code review.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Read text file into array and display it
    By Waflix in forum New To Java
    Replies: 1
    Last Post: 07-10-2012, 09:58 PM
  2. Replies: 0
    Last Post: 12-09-2010, 05:56 PM
  3. Replies: 1
    Last Post: 12-01-2010, 06:35 PM
  4. Replies: 6
    Last Post: 03-12-2010, 04:54 AM
  5. [SOLVED] Display the text.log file in the browser
    By jazz2k8 in forum Advanced Java
    Replies: 2
    Last Post: 06-09-2009, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts