Tuesday, April 24, 2012

Constructors and instantiation

"Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)" ( http://bit.ly/I67fRB )

Every class has at least one Constructor. This is a special method that prepares the object for use. It has the same name as the class.


A class can have multiple constructors - this is known as method overloading.

The constructor is always the first method called on an object. Think of it as an 'on-switch'. When we instantiate an object of a class, we call it's constructor using the new keyword:

Syntax:
Type identifier = new Type(parameters, if any);

Example:
Telephone myTelephone = new Telephone();


In UML notation, the constructor is always referred to as new(). This is because UML is language independent and not Java specific. Different programming languages have different rules for naming a constructor.

Importing and Exporting Java Projects in Eclipse

"JIT Tutorial: Importing packages into Eclipse" ( http://bit.ly/Km6D5M )

"Importing and Exporting Java Projects in Eclipse" ( http://bit.ly/JxcNmZ )

Monday, April 23, 2012

JFrame

From Swing, JFrame is a top-level GUI container component.

"How to Make Frames (Main Windows) (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)" ( http://bit.ly/1eWsG71 )

http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html

JOptionPane

From Swing, a JOptionPane is a dialog window.

http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html

The showInputDialog function returns a String:

String thisString = JOptionPane.showInputDialog("Please input a value");

If you need to use the return value as an int, you may use the following function:

int returnValue = Integer.parseInt(thisString);

(But if the string contains anything other than numbers !!! Your program will CRASH)

If the user presses the Cancel button, showInputDialog will return null.

The following snippet checks if the return is (not) equal to null:

if ((thisString != null) {
// Statements....
}

Swing

javax.swing

GUI Components

http://docs.oracle.com/javase/7/docs/api/javax/swing/package-summary.html

often used in conjunction with java.awt UI classes

http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/package-summary.html

Tuesday, April 17, 2012

For-each Loop


"Java: For-each Loop" ( http://bit.ly/HThpAk )


For each Line in the array called myLine.

Friday, April 6, 2012

Updating a .jar file

"Updating a JAR File (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)" ( http://bit.ly/16Ut4zV )

eg.
jar uf /Users/username/Desktop/minecraft.jar /Users/username/Desktop/char.png