Results 1 to 2 of 2
- 11-21-2012, 05:32 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 4
- Rep Power
- 0
Issues getting file text to display in dialog, and overall code review.
So i'm fairly new to Java. Below is my code.
Two questions.Java Code:/**** * Author: Joyel Puryear * Website: http://www.joyelpuryear.com * Title: Morrowind Swiss Army Knife ****/ package morrowind.swiss.army.knife; /***** IMPORTS *****/ import java.awt.Component; import javax.swing.*; import java.awt.event.*; import java.io.*; 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 (http://www.joyelpuryear.com)"); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /***** CREATE MENU BAR *****/ JMenuBar menubar = new JMenuBar(); /***** CREATE FILE MENU *****/ // File menu item. JMenu file = new JMenu("File"); menubar.add(file); // INI Editor sub menu JMenuItem mwinieditor = new JMenuItem("Morrowind INI Editor"); file.add(mwinieditor); class mwinieditoraction implements ActionListener { private Component aComponent; @Override 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"); file.add(exit); class exitaction implements ActionListener { @Override public void actionPerformed (ActionEvent e) { System.exit(0); } } exit.addActionListener(new exitaction()); /***** CREATE HELP MENU *****/ JMenu help = new JMenu("Help"); menubar.add(help); JMenuItem about = new JMenuItem("About"); help.add(about); class aboutaction implements ActionListener { @Override public void actionPerformed (ActionEvent e) { //default title and icon JOptionPane.showMessageDialog(frame, "--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: http://www.joyelpuryear.com\n" + "Business Website: http://www.infotechnologist.biz\n"); } } about.addActionListener(new aboutaction()); frame.setJMenuBar(menubar); frame.setVisible(true); } }
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!
- 11-21-2012, 06:40 PM #2
Re: Issues getting file text to display in dialog, and overall code review.
Not a cross post, but related:
Wanting advice from other modders/utility makers. • Great House Fliggerty
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Read text file into array and display it
By Waflix in forum New To JavaReplies: 1Last Post: 07-10-2012, 09:58 PM -
Applet program to open a text file and display the content in text area
By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM -
Display only certain contents of text file and edit display
By blkshrk81 in forum New To JavaReplies: 1Last Post: 12-01-2010, 06:35 PM -
How can I get the file contents to display as readable text?
By xtiano77 in forum New To JavaReplies: 6Last Post: 03-12-2010, 04:54 AM -
[SOLVED] Display the text.log file in the browser
By jazz2k8 in forum Advanced JavaReplies: 2Last Post: 06-09-2009, 02:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks