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: