Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-02-2006, 10:08 PM   #1 (permalink)
jessewclark
Recruit
 
Join Date: Aug 2006
Posts: 6
jessewclark is on a distinguished road
Newbie's Simple Code

Hi, everybody.

I'm just starting and I think this may be too simple of a thing to get response on , but I guess I wanted to get feedback from the ground up. I made a simple little class called JaVonNuemann, whose purpose is to basically duplicate itself. It takes a text file with all its own code, and copies it to a new file.

I also had it pop up as a GUI. Right now all the GUI does is allow you to click a button to make the copying happen.

If anybody has any advice as to a better way to do any of this, I'd appreciate hearing it. It's probably too simple a thing to ask about, but I thought I'd see just in case I did some small thing wrong.
Code:
public class JaVonNuemann implements ActionListener {
	
	public JaVonNuemann () {
		//Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JFrame frame = new JFrame("JaVonNuemann");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Make a nice JPanel to hold our components.
        JPanel main = new JPanel ();
        frame.setContentPane(main);
        
        //Add the label.
        JLabel label = new JLabel("Make that thing!");
        main.add(label);
        
        //Make a Button
        JButton button = new JButton ("Make it good!");
        button.setActionCommand("Make It!");
        button.addActionListener(this);
        main.add(button);
        
        //Display the window.
        frame.pack();
        frame.setVisible(true);
	}
		
	    private static void createAndShowGUI() {
	        new JaVonNuemann ();
	    }

	    public static void main(String[] args) {
	        //Schedule a job for the event-dispatching thread:
	        //creating and showing this application's GUI.
	        javax.swing.SwingUtilities.invokeLater(new Runnable() {
	            public void run() {
	                createAndShowGUI();
	            }
	        });
	    }

	    public void copy() throws IOException {
	    	File inputFile = new File("JaVonNuemann.txt");
	    	File outputFile = new File("JaVonNuemann1.java");
	    	
	    	FileReader in = new FileReader(inputFile);
	        FileWriter out = new FileWriter(outputFile);
	        int c;

	        while ((c = in.read()) != -1)
	           out.write(c);

	        in.close();
	        out.close();
		}
	    
		public void actionPerformed(ActionEvent e) {
			try {
				copy();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}

}

Last edited by redhead; 10-03-2006 at 07:14 AM.
jessewclark is offline   Reply With Quote
Old 10-03-2006, 01:26 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,174
Belisarius is on a distinguished road
Unfortunantly, in Java there's no real easy way to copy a file. You seemed to do it in the correct fashion - I haven't worked with files in Java in a while, so I'm a little rusty. The only thing I'd suggest would be to clean up your code so it's a little easier to read. The sticky in this section has a link to Java Coding Conventions that will tell you how to present your code so it's easier to read.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 10-04-2006, 06:04 PM   #3 (permalink)
jessewclark
Recruit
 
Join Date: Aug 2006
Posts: 6
jessewclark is on a distinguished road
Bellisarius,

Thanks for your reply! I've downloaded the code conventions, and I'll read it. It's pretty long, though, and I wonder if there's one big thing that stands out right now?
jessewclark is offline   Reply With Quote
Old 10-05-2006, 02:06 AM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,174
Belisarius is on a distinguished road
Right now, I'd say make sure your indentations are uniform. That's the biggest hinderance towards making it easy to read.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 10-11-2006, 10:18 PM   #5 (permalink)
jessewclark
Recruit
 
Join Date: Aug 2006
Posts: 6
jessewclark is on a distinguished road
Thanks for pointing that out. I didn't notice that. It wasn't a choice, just a mistake. Thanks again.
jessewclark is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how the servlet will integrate the LDAP code j.gohel Java 19 04-16-2005 01:55 AM
Help with a simple program C++noob Standard C, C++ 1 03-24-2005 04:31 PM
Simple PHP MySQL code: confused. easilyi Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 10-24-2004 08:53 PM
Cisco Code breaking sde Code Newbie News 0 05-21-2004 08:10 AM


All times are GMT -8. The time now is 01:57 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting