- import org.jdesktop.application.Action; Marks a method that will be used to define a Swing Action object's actionPerformed method. It also identifies the resources that will be used to initialize the Action's properties. Additional @Action parameters can be used to specify the name of the bound properties (from the same class) that indicate if the Action is to be enabled/selected, and if the GUI should be blocked while the Action's background Task is running.
- import org.jdesktop.application.ResourceMap; A read-only encapsulation of one or more ResourceBundles that adds automatic string conversion, support for field and Swing component property injection, string resource variable substitution, and chaining.
- import org.jdesktop.application.SingleFrameApplication;
- import org.jdesktop.application.FrameView; A View encapsulates a top-level Application GUI component, like a JFrame or an Applet, and its main GUI elements: a menu bar, tool bar, component, and a status bar. All of the elements are optional (although a View without a main component would be unusual). Views have a JRootPane, which is the root component for all of the Swing Window types as well as JApplet. Setting a View property, like menuBar or toolBar, just adds a component to the rootPane in a way that's defined by the View subclass.
- import org.jdesktop.application.TaskMonitor; This class is intended to serve as the model for GUI components, like status bars, that display the state of an application's background tasks. TaskMonitor provides an overview of all the ApplicationContext's Tasks, as well as the state of a single foreground Task.
- import org.jdesktop.application.Task; A type of SwingWorker that represents an application background task. Tasks add descriptive properties that can be shown to the user, a new set of methods for customizing task completion, support for blocking input to the GUI while the Task is executing, and a TaskListener that enables one to monitor the three key SwingWorker methods: doInBackground, process and done.
- import java.awt.event.ActionEvent; A semantic event which indicates that a component-defined action occurred. This high-level event is generated by a component (such as a Button) when the component-specific action occurs (such as being pressed). The event is passed to every every ActionListener object that registered to receive such events using the component's addActionListener method.
- import java.awt.event.ActionListener; The listener interface for receiving action events. The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component's addActionListener method. When the action event occurs, that object's actionPerformed method is invoked.
- import java.util.ArrayList;
- import java.util.List;
- import javax.persistence.RollbackException; Thrown by the persistence provider when the EntityTransaction.commit() fails.
- import javax.swing.Timer;
- import javax.swing.Icon;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.event.ListSelectionEvent;
- import javax.swing.event.ListSelectionListener;
- import org.jdesktop.beansbinding.AbstractBindingListener; An abstract subclass of BindingListener that simplifies writing BindingListeners by allowing you to extend this class and re-implement only the methods you care about.
- import org.jdesktop.beansbinding.Binding; A factory class for creating instances of the concrete Binding implementations provided by this package.
- import org.jdesktop.beansbinding.PropertyStateEvent; An event characterizing a change in a Property's state for a particular source object.
Showing posts with label Java Programming. Show all posts
Showing posts with label Java Programming. Show all posts
Wednesday, April 22, 2009
5 - Import statements generated by netbeans inside "*View.java"
These are the list of import statements generated by netbeans when we build desktop database application. These statements are placed inside *View.java (which is a user interface class) :
Labels:
Java Programming
Friday, March 6, 2009
4 - Variable and Constant
Variable Declaration
The syntax for attribute declaration is exactly the same with what we have done when we declare methods. The syntax is like this :
[modifiers] type name_of_variable or [modifiers] type name_of_variable = [value].
In terms of its visibility a variable can be local if it is declared inside a method, it can only be seen inside the method where it is declared. But there is a slight difference if we compare that with the rules listed above. The syntax for declaring such variable is very short :
int intStudentNumber;
char charGrade;
int intMarbleCount = 20;
char charStudentGrade = 'A';
boolean boolIStillAlive = true;
A variable can only store one value at a time, but we can change it. We can change what is stored inside a variable by assigning a legal value to it. There are 4 ways to assign a value to a variable :
charGrade = charStudentGrade;
float floatKgOrdered = 210.01F;
float floatTotalPrice = (floatUnitPrice * floatKgOrdered);
Do we have another type of “variable” ? Yes it is called constant. A constant represents a value in a memory area that can not be changed at all. A constant is named with capital letters. Here is an example of a constant declaration :
final char TOP_GRADE = 'A';
A constant's value can not be changed forever and ever. Its value stays happily ever after.
Heap Memory and Stack Memory
Variables that are declared inside a method, known as local variables, are stored inside stack memory area, while attributes reside inside heap memory area. Heap memory stores any information about objects while they are needed by a program, while stack memory stores memory that are suitable for a short period of time.
The syntax for attribute declaration is exactly the same with what we have done when we declare methods. The syntax is like this :
[modifiers] type name_of_variable or [modifiers] type name_of_variable = [value].
- This form : [modifiers] type name_of_variable is only for declaring a variable without giving the the initial value of the variable.
- The other form is : [modifiers] type name_of_variable = [value] is for declaring a variable and GIVING it the initial value.
- [] (square bracket means anything inside this bracket is optional). Modifiers can be any java keywords. The most common are private, public, and static that we have encounter before.
In terms of its visibility a variable can be local if it is declared inside a method, it can only be seen inside the method where it is declared. But there is a slight difference if we compare that with the rules listed above. The syntax for declaring such variable is very short :
- type name_of_variable if you only want to declare a variable without initializing a value for it.
- type name_of_variable = valueif you need to declare an initial value.
In fact WE ARE NOT ALLOWED to place a modifier (such as public, private, etc) when declaring a local variable.
- byte : the range of value is from -128 to 127 (8 bits long)
- short : the range of value is from -32,768 to 32,767 (16 bits long)
- int : the range of value is -2,147,483,648 to 2,147,483,647 (32 bits long)
- long : the range of value is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (64 bits long).
- float : 32 bits floating point or real number point number.
- double : 64 bits floating point or real number point number.
- char : 8 bits long it holds a character value. At one point of time it store one only character.
- boolean : a variable of type boolean can only store a logical value true or false.
- Examples for declaration of several variables without initialization :
int intStudentNumber;
char charGrade;
- Examples for declaration of several variables WITH initialization :float
int intMarbleCount = 20;
char charStudentGrade = 'A';
boolean boolIStillAlive = true;
A variable can only store one value at a time, but we can change it. We can change what is stored inside a variable by assigning a legal value to it. There are 4 ways to assign a value to a variable :
- Assigning a value directly to a variable. Suppose a Grade of a student is F (fails he never studies) : charGrade = 'F';
- The other way is by giving a value of another variable to one variable
charGrade = charStudentGrade;
- We can also assign the result of an arithmetic operation to a variable :
float floatKgOrdered = 210.01F;
float floatTotalPrice = (floatUnitPrice * floatKgOrdered);
- We can assign the result of a function execution to a variable. WE DO NOT HAVE ANY EXAMPLE FOR THIS YET.
Do we have another type of “variable” ? Yes it is called constant. A constant represents a value in a memory area that can not be changed at all. A constant is named with capital letters. Here is an example of a constant declaration :
final char TOP_GRADE = 'A';
A constant's value can not be changed forever and ever. Its value stays happily ever after.
Heap Memory and Stack Memory
Variables that are declared inside a method, known as local variables, are stored inside stack memory area, while attributes reside inside heap memory area. Heap memory stores any information about objects while they are needed by a program, while stack memory stores memory that are suitable for a short period of time.
Labels:
Java Programming
Saturday, February 28, 2009
3 - Class Structure
Lets begin our discussion by refreshing our memory with hello world application. A simple one class program :
public class HelloJava // The class declaration
{
public static void main(String args[]) //The main method declaration
{
System.out.println("Hello Java : a cup of arabica and robusta blend");
}
}
Inside the program we have :
1.class declaration.
2.method declaration
3.Some comments
Every class inside our application must be declared. A Declaration is like telling the world that this class exists. By convention, class names begin with a capital letter, and usually I use uppercase letter for every word that is part of a class name. Lets disect our HelloJava class :
1.syntax for class declaration is [access_modifier] class class_identifier
2.access_modifier determines the accessibility of other classes to this class. Our access modifier is public so that this class is visible and accessible to other class
3.class identifier or better known as class name is HelloJava. Our class name is HelloJava.
4.Every java program must have one main() method. Our method is declared inside HelloJava class. Our main method comprises only one statement : System.out.println("Hello Java : a cup of arabica and robusta blend"). This statement will be executed during runtime.
5.In HelloJava we haven't got any variables yet.
Comments is good for documenting our logic of programming. Comments inside a java program takes the form of :
1.//. This type of comment may spans only one line of comments
2.Traditional comment just like in c language : begin with /* end with */. This type of comments may span several lines of comments.
Until now we haven't got any variable declaration. Now lets have a look at another examples : Triangle. We have two variables, which are public. base and height are public. It means they can be accessed and manipulated by another class.
public class Triangle
{
public float base = 0;
public float height = 0;
public void showTriangle()
{
System.out.println("Base : " + base);
System.out.println("Height : " + height);
System.out.println("Area : " + base*height/2);
}
}
Another interesting declaration is the method : showTriangle. It is public but it has a key word void. It means ON COMPLETION IT DOES NOT RETURN ANY VALUE. It has 3 statements that will be executed during run time.
public class HelloJava // The class declaration
{
public static void main(String args[]) //The main method declaration
{
System.out.println("Hello Java : a cup of arabica and robusta blend");
}
}
Inside the program we have :
1.class declaration.
2.method declaration
3.Some comments
Every class inside our application must be declared. A Declaration is like telling the world that this class exists. By convention, class names begin with a capital letter, and usually I use uppercase letter for every word that is part of a class name. Lets disect our HelloJava class :
1.syntax for class declaration is [access_modifier] class class_identifier
2.access_modifier determines the accessibility of other classes to this class. Our access modifier is public so that this class is visible and accessible to other class
3.class identifier or better known as class name is HelloJava. Our class name is HelloJava.
4.Every java program must have one main() method. Our method is declared inside HelloJava class. Our main method comprises only one statement : System.out.println("Hello Java : a cup of arabica and robusta blend"). This statement will be executed during runtime.
5.In HelloJava we haven't got any variables yet.
Comments is good for documenting our logic of programming. Comments inside a java program takes the form of :
1.//. This type of comment may spans only one line of comments
2.Traditional comment just like in c language : begin with /* end with */. This type of comments may span several lines of comments.
Until now we haven't got any variable declaration. Now lets have a look at another examples : Triangle. We have two variables, which are public. base and height are public. It means they can be accessed and manipulated by another class.
public class Triangle
{
public float base = 0;
public float height = 0;
public void showTriangle()
{
System.out.println("Base : " + base);
System.out.println("Height : " + height);
System.out.println("Area : " + base*height/2);
}
}
Another interesting declaration is the method : showTriangle. It is public but it has a key word void. It means ON COMPLETION IT DOES NOT RETURN ANY VALUE. It has 3 statements that will be executed during run time.
Labels:
Java Programming
2 - Multiclass Java Program
Now it is time for us to write application (simple one) with more than one class. The specification for our application is that we have a class that create an instance of another class. Our main class is called TriangleCreator, and the other class is called Triangle. TriangleCreator will create an instance of a Triangle.
The scenario for building such program is that we need to have a class that will be used by another class. The first class we need to write is Triangle class, the class that creates another class is called TriangleCreator. Now we have class Triangle that is depicted bellow :
public class Triangle
{
public float base = 0;
public float height = 0;
public void showTriangle()
{
System.out.println("Base : " + base);
System.out.println("Height : " + height);
System.out.println("Area : " + base*height/2);
}
}
what you have to do is the same with the other exercises we have done before :
1.Copy the source code.
2.Paste it into your text editor.
3.Save the program as Triangle.java IN YOUR WORKING DIRECTORY.
Next we need to have TriangleCreator class.
public class TriangleCreator
{
public static void main(String args[])
{
Triangle oTriangle;
oTriangle = new Triangle();
oTriangle.base = 10;
oTriangle.height = 10;
oTriangle.showTriangle();
}
}
Here is a list of action you need to do :
1.Copy the source code.
2.Paste it into your text editor.
3.Save the program as TriangleCreator.java IN YOUR WORKING DIRECTORY.
4.Compile the program using this command :javac TriangleCreator.java
5.After completing compilation process, a bytecode is produced : TriangleCreator.class
6.You run your program by executing this command : java TriangleCreator
In the next section we are going to discuss what we have done, discussing the syntax of making class.
The scenario for building such program is that we need to have a class that will be used by another class. The first class we need to write is Triangle class, the class that creates another class is called TriangleCreator. Now we have class Triangle that is depicted bellow :
public class Triangle
{
public float base = 0;
public float height = 0;
public void showTriangle()
{
System.out.println("Base : " + base);
System.out.println("Height : " + height);
System.out.println("Area : " + base*height/2);
}
}
what you have to do is the same with the other exercises we have done before :
1.Copy the source code.
2.Paste it into your text editor.
3.Save the program as Triangle.java IN YOUR WORKING DIRECTORY.
Next we need to have TriangleCreator class.
public class TriangleCreator
{
public static void main(String args[])
{
Triangle oTriangle;
oTriangle = new Triangle();
oTriangle.base = 10;
oTriangle.height = 10;
oTriangle.showTriangle();
}
}
Here is a list of action you need to do :
1.Copy the source code.
2.Paste it into your text editor.
3.Save the program as TriangleCreator.java IN YOUR WORKING DIRECTORY.
4.Compile the program using this command :javac TriangleCreator.java
5.After completing compilation process, a bytecode is produced : TriangleCreator.class
6.You run your program by executing this command : java TriangleCreator
In the next section we are going to discuss what we have done, discussing the syntax of making class.
Labels:
Java Programming
Tuesday, February 24, 2009
1 - Introduction to Java Programming
Java is Object Oriented Programming Language. You can find many explanation of java environment and architecture somewhere else. This page is focusing on the programming example. If you see the examples in this page you will notice that a java program at least consist of a class declaration, method declaration, comments (if required/optional), and variable declaration (usually a class has several variables).
Our first program is hello java. The source code is presented below. All you have to do is copying and pasting it into your text editor, compile, and run the program :
public class HelloJava // The class declaration
{
public static void main(String args[]) //The main method declaration
{
System.out.println("Hello Java : a cup of arabica and robusta blend");
}
}
1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloJava.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloJava.java
5. After completing compilation process, a bytecode is produced : HelloJava.class
6. You run your program by executing this command : java HelloJava
We have more programming work to do. We are going to have another program that will print multiple lines of output. The source code is presented below. In case you are wondering what kopi luwak is Kopi luwak is coffe beans fermented inside the digestion system of a weasel like animal called luwak.
public class HelloKopiLuwak
{
public static void main(String args[])
{
System.out.println("Kopi Luwak : Exquisite Coffe produced by digestive system of ");
System.out.println("Paradoxurus hermaphroditusa, raccon-like animal." );
System.out.println("Perhaps it costs 300 or 400 dollars per kilo ");
}
}
1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloKopiLuwak.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloKopiLuwak.java
5. After completing compilation process, a bytecode is produced : HelloJavaKopiLuwak.class
6. You run the program by executing this command : java HelloKopiLuwak
We can also modify the program so that instead of having 3 println statements. We only need one.
public class HelloKopiLuwakModified
{
public static void main(String args[])
{
System.out.println("Kopi Luwak : Exquisite Coffe produced by digestive system of\nParadoxurus hermaphroditusa, raccon-like animal\nPerhaps it costs 300 or 400 dollars per kilo ");
}
}
Then what you have to do is :
1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloKopiLuwakModified.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloKopiLuwakModified.java
5. After completing compilation process, a bytecode is produced : HelloKopiLuwakModified.class
6. You run the program by executing this command : java HelloKopiLuwakModified
Until now, we only have one class. A one class program is fine inside classroom. But in actual world you need to have several classes. How to make such construct will be discussed on the next section of Java Programming.
Our first program is hello java. The source code is presented below. All you have to do is copying and pasting it into your text editor, compile, and run the program :
public class HelloJava // The class declaration
{
public static void main(String args[]) //The main method declaration
{
System.out.println("Hello Java : a cup of arabica and robusta blend");
}
}
1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloJava.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloJava.java
5. After completing compilation process, a bytecode is produced : HelloJava.class
6. You run your program by executing this command : java HelloJava
We have more programming work to do. We are going to have another program that will print multiple lines of output. The source code is presented below. In case you are wondering what kopi luwak is Kopi luwak is coffe beans fermented inside the digestion system of a weasel like animal called luwak.
public class HelloKopiLuwak
{
public static void main(String args[])
{
System.out.println("Kopi Luwak : Exquisite Coffe produced by digestive system of ");
System.out.println("Paradoxurus hermaphroditusa, raccon-like animal." );
System.out.println("Perhaps it costs 300 or 400 dollars per kilo ");
}
}
1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloKopiLuwak.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloKopiLuwak.java
5. After completing compilation process, a bytecode is produced : HelloJavaKopiLuwak.class
6. You run the program by executing this command : java HelloKopiLuwak
We can also modify the program so that instead of having 3 println statements. We only need one.
public class HelloKopiLuwakModified
{
public static void main(String args[])
{
System.out.println("Kopi Luwak : Exquisite Coffe produced by digestive system of\nParadoxurus hermaphroditusa, raccon-like animal\nPerhaps it costs 300 or 400 dollars per kilo ");
}
}
Then what you have to do is :
1. Copy the source code.
2. Paste it into your text editor.
3. Save the program as HelloKopiLuwakModified.java IN YOUR WORKING DIRECTORY.
4. Compile the program using this command :javac HelloKopiLuwakModified.java
5. After completing compilation process, a bytecode is produced : HelloKopiLuwakModified.class
6. You run the program by executing this command : java HelloKopiLuwakModified
Until now, we only have one class. A one class program is fine inside classroom. But in actual world you need to have several classes. How to make such construct will be discussed on the next section of Java Programming.
Labels:
Java Programming
Subscribe to:
Posts (Atom)
