3 Replies - 713 Views - Last Post: 28 February 2012 - 01:50 PM Rate Topic: -----

#1 D0r13n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-February 12

Learn Java on My Own

Posted 27 February 2012 - 03:59 PM

I am currently in the process of teaching myself programming, specifically Java. I have taken an SQL class and have done some work with AutoLISP. That being said, the company I work for wants me to work on some pretty intricate stuff for in house use. So I figure, why not make a prank program to learn the stuff that I need to eventually do. So with the "Java For Dummies" book and google in hand, I have completed my first program that actually works. But like I said, it's a hodge podge of the Dummies book and google searches. So it works, but there is no convention but my own, which will really annoy whoever eventually replaces me someday. Plus, if I ever get into the Java class at school, I don't want to have to reprogram myself proper technique. So what I'm really asking is, what about the below code annoys you, and what would you recommend to look into about actually learning the proper conventions for programming?

package me.playingWithJava.elevatorFitter;

import java.awt.Container;
import java.awt.GridLayout;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class ShowAFrame {
	/**
	 * This program creates a simple window that will display a warning that the
	 * computer is being monitored by Skynet. It also pulls the days date and
	 * prints it at the bottom of the warning.
	 * 
	 * @throws InterruptedException
	 *             Makes program wait so many hours before running. Great for
	 *             messing with Phil.
	 */
	public static void main(String args[]) throws InterruptedException {
		Thread.sleep(1000*60*24);
		Date date = new Date();// Pulls date from computer.
		SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
		// Sets up formating for the date to later be displayed
		String d = sdf.format(date);// Applies the format to the date.
		JFrame.setDefaultLookAndFeelDecorated(true);
		// Makes the window look like a Java window and not a windows window.
		JFrame myFrame = new JFrame();// Creates the window.
		String myTitle = "Skynet System Monitoring";// The window title.
		JLabel mylabel1 = new JLabel(
				"For your convienence, this computer is being monitored by Skynet.");
		// Creates the first Text string for the warning.
		JLabel mylabel2 = new JLabel(
				"All activity will be monitored and reported to you Supervisor.");
		// Creates second text sting for the warning.
		JLabel mylabel3 = new JLabel(
				"Please remember to follow District policy for proper computer use.");
		// Creates the third text sting for the warning.
		JLabel mylabel4 = new JLabel("Thank you for your time." + " " + d);
		// creates the last text string for the warning and includes the current
		// date.
		Container pane = myFrame.getContentPane();
		// Puts a container in the window to hold the Text strings.
		pane.setLayout(new GridLayout(4, 1));
		// Creates 4 rows and one column inside the container.
		pane.add(mylabel1);// Adds the first Label to the container.
		pane.add(mylabel2);// Adds the second Label to the container.
		pane.add(mylabel3);// Adds the third label to the container.
		pane.add(mylabel4);// Adds the fourth label to the container.
		myFrame.setVisible(true);// Makes it so the window is actually visible.
		myFrame.setTitle(myTitle);// Sets the title of the window.
		myFrame.setSize(400, 100);
		// Sets the minimum size of the window, will be larger if the text takes
		// up more space.
		myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		// Makes the program close when the window is closed.

	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Learn Java on My Own

#2 supercorey  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 119
  • View blog
  • Posts: 207
  • Joined: 15-February 09

Re: Learn Java on My Own

Posted 27 February 2012 - 04:19 PM

In my opinion, to learn Java the best, you should use the official Oracle Tutorials. These do a pretty good job of explaining how and why things work, so they should help you in learning why you should do certain things and should allow you to develop your own style. They also teach very good, if not the standard, coding conventions for Java.

Good luck and Cheers!
Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,858
  • Joined: 06-March 08

Re: Learn Java on My Own

Posted 27 February 2012 - 10:30 PM

If you really go into Java, you should think OOP
The main() method is just use to start your application it should only have a few line
It is your class, as an instance object, that handles everything

class ShowAFrame exends JFrame {
    // constructor
    ShowAFrame() {
       super("This is a frame");
       setLayout(new GridLayout(4,1);
       add(new JLabel("Label1");      
       add(new JLabel("Label2");
       add(new JLabel("Label3");
       add(new JLabel("Label4");
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setSize(300,200);
       setVisible(true);
    }

    public static void main(String[] args) {
       new ShowAFrame();      // <--- that's it !!!
    }
}


Was This Post Helpful? 2
  • +
  • -

#4 D0r13n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-February 12

Re: Learn Java on My Own

Posted 28 February 2012 - 01:50 PM

View Postpbl, on 27 February 2012 - 10:30 PM, said:

If you really go into Java, you should think OOP
The main() method is just use to start your application it should only have a few line
It is your class, as an instance object, that handles everything


I was thinking that it was really kind of muddled. I'm still working my way through the Dummies book, so I'm not sure how in depth it will get into that sort of thing. Once I get more of my head wrapped around it, I will take a crack at the java tutorials. I went there first and it was a little much for me.

Thanks to both of you, really gave me an idea of where I'm at and where I need to head.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1