Saturday, May 2, 2009

Installing java platform

To install java platform you need either java installer or internet connection enable to download java platform through the internet.

To download java SE 6 Edition you can search the site: www.java.sun.com
just follow all necessary actions to do to download all java files needed to execute a program. All the files are automatically saved to its default directory:
C:\Program Files\Java\...............

Monday, April 27, 2009

Broughting headache on my head

Ive been dissapointed of myself for not accomplishing my assignment in programming. i thought it was just easy to do it, but Ive been closing my eyes and say "oh! God help me!". Our instructor require us to write a GUIprogram that will add and view a Person name and age using ArrayList class .The ArrayList is class we are going to use as a database for our program. I have already spend two days for this but unfortunately its not yet finish. The only problem was, all the info that I inputted to the textfield will not appear to the display table in the view form. How many times I try but nothing happen. When I go home I felt the dissapoinment to myself, and the headache that brought by this problem will broke my head.
here is the output of my program:

Monday, April 20, 2009

Sample JToolbar application in java

/**
* @(#)JtoolbarDemo.java
*
*
* @author
* @version 1.00 2009/4/21
*/



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JToolBar;

public class JtoolbarDemo extends JFrame implements ActionListener{
String dir = System.getProperty("user.dir");
int x = 500;
JToolBar toolBar = new JToolBar();
JButton item1 = new JButton(new ImageIcon(dir+ "\\images\\Save24.gif"));
JButton item2 = new JButton(new ImageIcon(dir+ "\\images\\Delete24.gif"));
JButton item3 = new JButton(new ImageIcon(dir+ "\\images\\About24.gif"));
JLabel message = new JLabel("You clicked:");
public JtoolbarDemo(){
setLayout(null);

item1.addActionListener(this);
item2.addActionListener(this);
item3.addActionListener(this);

toolBar.add(item1);
toolBar.add(item2);
toolBar.add(item3);

toolBar.setFloatable(false);
toolBar.setBounds(0,0,x,40);

message.setBounds(0,40,200,20);

add(toolBar);
add(message);
setTitle("Toolbar example By: HappyFace - www.engineeringserver.com");
setSize(x,200);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args){
new JtoolbarDemo();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == item1){
message.setText("You clicked: save as..");
}
if(e.getSource() == item2){
message.setText("You clicked: delete");
}

if(e.getSource() == item3){
message.setText("You clicked: about us");
}
}
}


sample output below:

Monday, March 16, 2009

Swing Objects

The JFrame class

JFrame class was a object class imported from javax.swing package.Its also represents a framed window and considered as a parent container.

JFrame class hierarchy:

Frame, Window, Container, Component, and finally Object).



Container
In instantiating the container you will just type the Container class

and a getContentPane() method.See the code below



Container pane=getContentPane();


pane was the object variable of the container class an d it will inherit the Container class. The Container class will carry all the components that you add to your window through using the

add() method. The container should be layout through the layout manager by using the setLayout()method. to know more about container click here.

Important methods of the JFrame:

setSize(int,int) this method will set the size of your frame on your desired size.
setTitle(String) this method will set the title of your window
setVisible(boolean) this method will set your window to be visible if the boolean is true.


Here are some code for making a frame or Window




//*****************

import java.awt.*;
import javax.swing.*;


public class SampleFrame extends JFrame{


public SampleFrame (){

}

public static void main (String args[]){
SampleFrame frame=new SampleFrame ();
frame.setSize(300,400);
frame.setTitle("View Test(shown 1times)");
frame.setVisible(true);
}

}



sample output below: