Friday, October 24, 2008

Bermain MouseEvent di JAVA

Kita akan memanfaatkan MouseEvent di Java untuk membuat mouseEntered dan mouseExited pada TextField. mouseEntered ketika mouse berada diatas posisi TextField and mouseExited ketika mouse keluar dari area TextField .

Coba kita buat program yang diberi nama "MyMouseEvent1.java". program ini berisi Label Command, Name, Age and Description. Jika mouse berada di atas posisi TextField Name maka label command akan tertulis "Please type your name" dan jika mouse berada diatas posisi TextField Age maka label command akan tertulis "Please type your Age". Saat mouse keluar dari name jika name diisi data maka data yang ada di name dan age akan ditampilkan description.Saat mouse keluar dari Age jika name diisi data yang ada di name dan age maka data akan ditampilkan description.


Download source :
esnips.com/doc/6f73d79d-9a06-4707-9a8d-d4b42ed52188/MyMouseEvent1

==========================================================
package test1;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;


import javax.swing.JFrame;

public class MyMouseEvent1 extends JFrame{

/**
* @param args
*/
private Label lblCommand = null;
private Label lblName = null;
private TextField txfName = null;
private Label lblAge = null;
private TextField txfAge = null;
private Label lblDescription = null;
private TextArea txaDescription = null;

public MyMouseEvent1() {
super("My Title");
initialize();
}

public void initialize(){

int y = 0;
GridBagConstraints gbcLblCommand = new GridBagConstraints();
gbcLblCommand.gridx = 1;
gbcLblCommand.gridy = y;
gbcLblCommand.anchor = GridBagConstraints.WEST;
gbcLblCommand.fill = GridBagConstraints.HORIZONTAL;
gbcLblCommand.insets = new Insets(5,10,0,10);
lblCommand = new Label();
lblCommand.setText("");

y++;
GridBagConstraints gbcLblName = new GridBagConstraints();
gbcLblName.gridx = 0;
gbcLblName.gridy = y;
gbcLblName.anchor = GridBagConstraints.WEST;
gbcLblName.fill = GridBagConstraints.HORIZONTAL;
lblName = new Label();
lblName.setText("Name");
GridBagConstraints gbcTxfName = new GridBagConstraints();
gbcTxfName.gridx = 1;
gbcTxfName.gridy = y;
gbcTxfName.anchor = GridBagConstraints.WEST;
gbcTxfName.insets = new Insets(5,10,0,10);

y++;
GridBagConstraints gbcLblAge = new GridBagConstraints();
gbcLblAge.gridx = 0;
gbcLblAge.gridy = y;
gbcLblAge.anchor = GridBagConstraints.WEST;
gbcLblAge.fill = GridBagConstraints.HORIZONTAL;
lblAge = new Label();
lblAge.setText("Age");
GridBagConstraints gbcTxfAge = new GridBagConstraints();
gbcTxfAge.gridx = 1;
gbcTxfAge.gridy = y;
gbcTxfAge.anchor = GridBagConstraints.WEST;
gbcTxfAge.insets = new Insets(5,10,0,10);

y++;
GridBagConstraints gbcLblDescription = new GridBagConstraints();
gbcLblDescription.gridx = 0;
gbcLblDescription.gridy = y;
gbcLblDescription.anchor = GridBagConstraints.WEST;
gbcLblDescription.fill = GridBagConstraints.HORIZONTAL;
lblDescription = new Label();
lblDescription.setText("description");
GridBagConstraints gbcTxaDescription = new GridBagConstraints();
gbcTxaDescription.gridx = 1;
gbcTxaDescription.gridy = y;
gbcTxaDescription.anchor = GridBagConstraints.WEST;
gbcTxaDescription.insets = new Insets(5,10,0,10);

this.setLayout(new GridBagLayout());
this.setSize(new Dimension(695, 498));
this.add(lblCommand, gbcLblCommand);
this.add(lblName, gbcLblName);
this.add(getTxfName(), gbcTxfName);
this.add(lblAge, gbcLblAge);
this.add(getTxtAge(), gbcTxfAge);
this.add(lblDescription, gbcLblDescription);
this.add(getTxaDescription(), gbcTxaDescription);


}

private TextField getTxfName() {
if (txfName == null) {
txfName = new TextField();
txfName.setColumns(30);
txfName.setName("name");
txfName.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {

}
public void mouseEntered(MouseEvent e) {
lblCommand.setText("Please type your name");
}
public void mousePressed(MouseEvent e) {

}
public void mouseReleased(MouseEvent e) {

}
public void mouseExited(MouseEvent e) {
if ((!txfName.getText().equals("")) && (!txfAge.getText().equals("")) ){
txaDescription.setText("Name : "+txfName.getText()+" ; "+"Age : "+txfAge.getText());
}
else if (!txfName.getText().equals("")){
txaDescription.setText("Name : "+txfName.getText());
}
else if (!txfAge.getText().equals("")){
txaDescription.setText("Age : "+txfAge.getText());
}
}

}

);


}
return txfName;
}

private TextField getTxtAge() {
if (txfAge == null) {
txfAge = new TextField();
txfAge.setColumns(10);
txfAge.setName("age");
txfAge.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {

}
public void mouseEntered(MouseEvent e) {
lblCommand.setText("Please type your Age");
}
public void mousePressed(MouseEvent e) {

}
public void mouseReleased(MouseEvent e) {

}
public void mouseExited(MouseEvent e) {
if ((!txfName.getText().equals("")) && (!txfAge.getText().equals("")) ){
txaDescription.setText("Name : "+txfName.getText()+" ; "+"Age : "+txfAge.getText());
}
else if (!txfName.getText().equals("")){
txaDescription.setText("Name : "+txfName.getText());
}
else if (!txfAge.getText().equals("")){
txaDescription.setText("Age : "+txfAge.getText());
}
}

}
);
}
return txfAge;
}

private TextArea getTxaDescription() {
if (txaDescription == null) {
txaDescription = new TextArea();
txaDescription.setName("addRemark");
txaDescription .setRows(4);
txaDescription.setColumns(40);
txaDescription.setEditable(false);
}
return txaDescription;
}

}


==========================================================

Thursday, October 23, 2008

Apa beda SQL Inner Join, Left Outer Join, Right Outer Join?

Mungkin kedengarannya lucu ya pertanyaan diatas(Hari gene masih binun ttg SQL Join)? tp mmg kalo ga sering pake kita bisa lupa prinsip tentang SQL join koq.Wajar...manusiawi:))
Selagi belum ada kerjaan yg di assign ke aq, sambil nunggu JIRA-nya diisi ama mas paddy bisa belajar n review2 hehehe
Sekarang mari kita coba mengingat-ingat lagi pelajaran SQl ini :
disini qta buat dulu 2 tabel yaitu
- tabel area, dengan 3 buah field : area_id, nama_area, luas_area
- tabel penduduk, dengan field 3 buah field : penduduk_id, nama_penduduk, area_id

kedua tabel diatas diilustrasikan dengan beberapa data sebagai berikut :

TABEL AREA
=====================================================
Area_ID || Nama_Area || Luas_Area
=====================================================
ARS01 Surabaya 1000
ARJ01 Jakarta 2000
ARY09 Yogya 4000
ARS02 Solo 3000
ARK01 Kediri null



TABEL PENDUDUK
=====================================================
Penduduk_ID || Nama_Penduduk || Area_ID
=====================================================
PDS01 Susanna ARS01
PDJ01 Jocki Hendry null
PDA01 Asrina Febyanti ARJ01
PDA02 Abi Anwari ARY01


I. Inner Join / Join :
Operasi Join tipe ini akan hanya menampilkan tabel sisi kiri yang datanya sama dengan data di pasangan joinnya yg disisi kanan.

dengan script sql berikut :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from area d
inner join penduduk p on (d.area_id=p.area_id);

script diatas ekivalen dengan script dibawah ini :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from penduduk p
inner join area d on (d.area_id=p.area_id);

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti

2 rows selected


II. Left Outer Join / Left Join :
Operasi Join tipe ini akan menampilkan semua isi tabel sisi kiri, walaupun data di pasangan joinnya yg disisi kanan nilainya tidak sama ataupun bernilai null.


dengan script sql berikut (Note => tabel sisi kiri : area; tabel sisi kanan : penduduk) :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from area d
left outer join penduduk p on (d.area_id=p.area_id);

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti
ARY09 Yogya 4000
ARS02 Solo 3000
ARK01 Kediri

5 rows selected

dengan script sql berikut (Note => tabel sisi kiri : penduduk; tabel sisi kanan : area) :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from penduduk p
left outer join area d on (d.area_id=p.area_id);

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
PDJ01 Jocki Henry
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti
PDA02 Abi Anwari

4 rows selected


III. Right Outer Join / Right Join :
Operasi Join tipe ini akan menampilkan semua isi tabel sisi Kanan, walaupun data di pasangan joinnya yg disisi kiri nilainya tidak sama ataupun bernilai null.

dengan script sql berikut (Note => tabel sisi kiri : area; tabel sisi kanan : penduduk) :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from area d
Right outer join penduduk p on (d.area_id=p.area_id);

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
PDJ01 Jocki Henry
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti
PDA02 Abi Anwari

4 rows selected


dengan script sql berikut (Note => tabel sisi kiri : penduduk; tabel sisi kanan : area) :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from penduduk p
Right outer join area d on (d.area_id=p.area_id);

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti
ARY09 Yogya 4000
ARS02 Solo 3000
ARK01 Kediri

5 rows selected


IV. Cross Join :
Operasi Join tipe ini akan menampilkan semua isi tabel sisi Kiri akan memiliki pasangan semua data disisi kanan.
Banyaknya Record Cross Join = jumlah record tabel pertama x jumlah record tabel kedua

dengan script sql berikut :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from area d
cross JOIN penduduk p

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
ARJ01 Jakarta 2000 PDS01 Susanna
ARS02 Solo 3000 PDS01 Susanna
ARY09 Yogya 4000 PDS01 Susanna
ARK01 Kediri PDS01 Susanna
ARS01 Surabaya 1000 PDJ01 Jocki Henry
ARJ01 Jakarta 2000 PDJ01 Jocki Henry
ARS02 Solo 3000 PDJ01 Jocki Henry
ARY09 Yogya 4000 PDJ01 Jocki Henry
ARK01 Kediri PDJ01 Jocki Henry
ARS01 Surabaya 1000 PDA01 Asrina Febyanti
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti
ARS02 Solo 3000 PDA01 Asrina Febyanti
ARY09 Yogya 4000 PDA01 Asrina Febyanti
ARK01 Kediri PDA01 Asrina Febyanti
ARS01 Surabaya 1000 PDA02 Abi Anwari
ARJ01 Jakarta 2000 PDA02 Abi Anwari
ARS02 Solo 3000 PDA02 Abi Anwari
ARY09 Yogya 4000 PDA02 Abi Anwari
ARK01 Kediri PDA02 Abi Anwari

20 rows selected


script diatas ekivalen dengan script dibawah ini :

select * from area d, penduduk p;


V. Full Outer Join / Full Join :
Operasi Join tipe ini akan menampilkan semua isi tabel sisi kiri, walaupun data di pasangan joinnya yg disisi kanan nilainya null.dan sebaliknya.

dengan script sql berikut :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from area d
full join penduduk p on (d.area_id=p.area_id);

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti
ARY09 Yogya 4000
ARS02 Solo 3000
ARK01 Kediri
PDJ01 Jocki Henry
PDA02 Abi Anwari

7 rows selected

dengan script sql berikut :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from penduduk p
full join area d on (d.area_id=p.area_id);

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
PDJ01 Jocki Henry
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti
PDA02 Abi Anwari
ARY09 Yogya 4000
ARS02 Solo 3000
ARK01 Kediri

7 rows selected



VI. Lain-lain
Kadang ada yang terbiasa/lebih suka dengan menggunakan left outer join untuk menghasilkan data seperti yang dihasilkan perintah di inner join. bisa juga sich. caranya filter data sisi kanan yang bernilai null.

dengan script sql berikut :

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from area d
left outer join penduduk p on (d.area_id=p.area_id)
where p.area_id is not null;

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti

2 rows selected

atau ada yang suka pake right outer join juga bisa lho.

scriptnya sebagai berikut

select d.Area_id, d.nama_area, d.luas_area, p.penduduk_id, p.nama_penduduk from area d
Right outer join penduduk p on (d.area_id=p.area_id)
where d.area_id is not null;

akan menghasilkan :

AREA_ID NAMA_AREA LUAS_AREA PENDUDUK_ID NAMA_PENDUDUK
------- -------------------- ---------------------- ----------- --------------------
ARS01 Surabaya 1000 PDS01 Susanna
ARJ01 Jakarta 2000 PDA01 Asrina Febyanti

2 rows selected

Tuesday, October 21, 2008

Bermain FocusEvent di Java

Kita akan memanfaatkan FocusEvent di Java untuk membuat focusGained dan FocusLost pada TextField. FocusGained seperti onKeyDown and FocusLost seperti OnExit di Delphi kali y:).

Coba kita buat program yang diberi nama "MyFocusLostFocusGain1.java". program ini berisi Label Command, Name, Age and Description. Jika onKeydown di Name maka label command akan tertulis "Please type your name" dan jika onKeydown di Age maka label command akan tertulis "Please type your Age". Saat mouse keluar dari name jika name diisi data maka data yang ada di name dan age akan ditampilkan description.Saat mouse keluar dari Age jika name diisi data yang ada di name dan age maka data akan ditampilkan description.


Download source :
www.esnips.com/doc/f6d77178-b25f-4a2f-808d-8aaf71b87910/MyFocusLostFocusGain1
=============================================================================
package test1;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;


import javax.swing.JFrame;

public class MyFocusLostFocusGain1 extends JFrame{

/**
* @param args
*/
private Label lblCommand = null;
private Label lblName = null;
private TextField txfName = null;
private Label lblAge = null;
private TextField txfAge = null;
private Label lblDescription = null;
private TextArea txaDescription = null;

public MyFocusLostFocusGain1() {
super("My Title");
initialize();
}

public void initialize(){

int y = 0;
GridBagConstraints gbcLblCommand = new GridBagConstraints();
gbcLblCommand.gridx = 1;
gbcLblCommand.gridy = y;
gbcLblCommand.anchor = GridBagConstraints.WEST;
gbcLblCommand.fill = GridBagConstraints.HORIZONTAL;
gbcLblCommand.insets = new Insets(5,10,0,10);
lblCommand = new Label();
lblCommand.setText("");

y++;
GridBagConstraints gbcLblName = new GridBagConstraints();
gbcLblName.gridx = 0;
gbcLblName.gridy = y;
gbcLblName.anchor = GridBagConstraints.WEST;
gbcLblName.fill = GridBagConstraints.HORIZONTAL;
lblName = new Label();
lblName.setText("Name");
GridBagConstraints gbcTxfName = new GridBagConstraints();
gbcTxfName.gridx = 1;
gbcTxfName.gridy = y;
gbcTxfName.anchor = GridBagConstraints.WEST;
gbcTxfName.insets = new Insets(5,10,0,10);

y++;
GridBagConstraints gbcLblAge = new GridBagConstraints();
gbcLblAge.gridx = 0;
gbcLblAge.gridy = y;
gbcLblAge.anchor = GridBagConstraints.WEST;
gbcLblAge.fill = GridBagConstraints.HORIZONTAL;
lblAge = new Label();
lblAge.setText("Age");
GridBagConstraints gbcTxfAge = new GridBagConstraints();
gbcTxfAge.gridx = 1;
gbcTxfAge.gridy = y;
gbcTxfAge.anchor = GridBagConstraints.WEST;
gbcTxfAge.insets = new Insets(5,10,0,10);

y++;
GridBagConstraints gbcLblDescription = new GridBagConstraints();
gbcLblDescription.gridx = 0;
gbcLblDescription.gridy = y;
gbcLblDescription.anchor = GridBagConstraints.WEST;
gbcLblDescription.fill = GridBagConstraints.HORIZONTAL;
lblDescription = new Label();
lblDescription.setText("description");
GridBagConstraints gbcTxaDescription = new GridBagConstraints();
gbcTxaDescription.gridx = 1;
gbcTxaDescription.gridy = y;
gbcTxaDescription.anchor = GridBagConstraints.WEST;
gbcTxaDescription.insets = new Insets(5,10,0,10);

this.setLayout(new GridBagLayout());
this.setSize(new Dimension(695, 498));
this.add(lblCommand, gbcLblCommand);
this.add(lblName, gbcLblName);
this.add(getTxfName(), gbcTxfName);
this.add(lblAge, gbcLblAge);
this.add(getTxtAge(), gbcTxfAge);
this.add(lblDescription, gbcLblDescription);
this.add(getTxaDescription(), gbcTxaDescription);


}

private TextField getTxfName() {
if (txfName == null) {
txfName = new TextField();
txfName.setColumns(30);
txfName.setName("name");
txfName.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent feLost) {
lblCommand.setText("Please type your name");

}

public void focusLost(FocusEvent feGain){
if ((!txfName.getText().equals("")) && (!txfAge.getText().equals("")) ){
txaDescription.setText("Name : "+txfName.getText()+" ; "+"Age : "+txfAge.getText());
}
else if (!txfName.getText().equals("")){
txaDescription.setText("Name : "+txfName.getText());
}
else if (!txfAge.getText().equals("")){
txaDescription.setText("Age : "+txfAge.getText());
}
}
}
);

}
return txfName;
}

private TextField getTxtAge() {
if (txfAge == null) {
txfAge = new TextField();
txfAge.setColumns(10);
txfAge.setName("age");
txfAge.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent feLost) {
lblCommand.setText("Please type your Age");

}

public void focusLost(FocusEvent feGain){
if ((!txfName.getText().equals("")) && (!txfAge.getText().equals("")) ){
txaDescription.setText("Name : "+txfName.getText()+" ; "+"Age : "+txfAge.getText());
}
else if (!txfName.getText().equals("")){
txaDescription.setText("Name : "+txfName.getText());
}
else if (!txfAge.getText().equals("")){
txaDescription.setText("Age : "+txfAge.getText());
}
}
}
);

}
return txfAge;
}

private TextArea getTxaDescription() {
if (txaDescription == null) {
txaDescription = new TextArea();
txaDescription.setName("addRemark");
txaDescription .setRows(4);
txaDescription.setColumns(40);
txaDescription.setEditable(false);
}
return txaDescription;
}



}

=============================================================================

atau

http://www.esnips.com/doc/3e5e58c6-d1c6-44e6-ab97-b7bf09db5955/MyFocusLostFocusGain2
=============================================================================

package test1;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;


import javax.swing.JFrame;

public class MyFocusLostFocusGain2 extends JFrame implements FocusListener{

/**
* @param args
*/
private Label lblCommand = null;
private Label lblName = null;
private TextField txfName = null;
private Label lblAge = null;
private TextField txfAge = null;
private Label lblDescription = null;
private TextArea txaDescription = null;

public MyFocusLostFocusGain2() {
super("My Title");
initialize();
}

public void initialize(){

int y = 0;
GridBagConstraints gbcLblCommand = new GridBagConstraints();
gbcLblCommand.gridx = 1;
gbcLblCommand.gridy = y;
gbcLblCommand.anchor = GridBagConstraints.WEST;
gbcLblCommand.fill = GridBagConstraints.HORIZONTAL;
gbcLblCommand.insets = new Insets(5,10,0,10);
lblCommand = new Label();
lblCommand.setText("");

y++;
GridBagConstraints gbcLblName = new GridBagConstraints();
gbcLblName.gridx = 0;
gbcLblName.gridy = y;
gbcLblName.anchor = GridBagConstraints.WEST;
gbcLblName.fill = GridBagConstraints.HORIZONTAL;
lblName = new Label();
lblName.setText("Name");
GridBagConstraints gbcTxfName = new GridBagConstraints();
gbcTxfName.gridx = 1;
gbcTxfName.gridy = y;
gbcTxfName.anchor = GridBagConstraints.WEST;
gbcTxfName.insets = new Insets(5,10,0,10);

y++;
GridBagConstraints gbcLblAge = new GridBagConstraints();
gbcLblAge.gridx = 0;
gbcLblAge.gridy = y;
gbcLblAge.anchor = GridBagConstraints.WEST;
gbcLblAge.fill = GridBagConstraints.HORIZONTAL;
lblAge = new Label();
lblAge.setText("Age");
GridBagConstraints gbcTxfAge = new GridBagConstraints();
gbcTxfAge.gridx = 1;
gbcTxfAge.gridy = y;
gbcTxfAge.anchor = GridBagConstraints.WEST;
gbcTxfAge.insets = new Insets(5,10,0,10);

y++;
GridBagConstraints gbcLblDescription = new GridBagConstraints();
gbcLblDescription.gridx = 0;
gbcLblDescription.gridy = y;
gbcLblDescription.anchor = GridBagConstraints.WEST;
gbcLblDescription.fill = GridBagConstraints.HORIZONTAL;
lblDescription = new Label();
lblDescription.setText("description");
GridBagConstraints gbcTxaDescription = new GridBagConstraints();
gbcTxaDescription.gridx = 1;
gbcTxaDescription.gridy = y;
gbcTxaDescription.anchor = GridBagConstraints.WEST;
gbcTxaDescription.insets = new Insets(5,10,0,10);

this.setLayout(new GridBagLayout());
this.setSize(new Dimension(695, 498));
this.add(lblCommand, gbcLblCommand);
this.add(lblName, gbcLblName);
this.add(getTxfName(), gbcTxfName);
this.add(lblAge, gbcLblAge);
this.add(getTxtAge(), gbcTxfAge);
this.add(lblDescription, gbcLblDescription);
this.add(getTxaDescription(), gbcTxaDescription);


}

private TextField getTxfName() {
if (txfName == null) {
txfName = new TextField();
txfName.setColumns(30);
txfName.setName("name");
txfName.addFocusListener(this);

}
return txfName;
}

private TextField getTxtAge() {
if (txfAge == null) {
txfAge = new TextField();
txfAge.setColumns(10);
txfAge.setName("age");
txfAge.addFocusListener(this);

}
return txfAge;
}

private TextArea getTxaDescription() {
if (txaDescription == null) {
txaDescription = new TextArea();
txaDescription.setName("addRemark");
txaDescription .setRows(4);
txaDescription.setColumns(40);
txaDescription.setEditable(false);
}
return txaDescription;
}


public void focusGained(FocusEvent feLost) {
if (feLost.getSource() == txfName) {
lblCommand.setText("Please type your name");
}
else if (feLost.getSource() == txfAge){
lblCommand.setText("Please type your Age");
}

}

public void focusLost(FocusEvent feGain){

if ((feGain.getSource() == txfName ) ||(feGain.getSource() == txfAge)) {
if ((!txfName.getText().equals("")) && (!txfAge.getText().equals("")) ){
txaDescription.setText("Name : "+txfName.getText()+" ; "+"Age : "+txfAge.getText());
}
else if (!txfName.getText().equals("")){
txaDescription.setText("Name : "+txfName.getText());
}
else if (!txfAge.getText().equals("")){
txaDescription.setText("Age : "+txfAge.getText());
}

}

}


}

Bermain dengan Gridbagconstraint di java

Property yang ada di class Gridbagconstraint antara lain :
- gridx -> digunakan untuk menentukan posisi x dr komponen
- gridy -> digunakan untuk menentukan posisi y dr komponen
- anchor -> digunakan jika komponen lebih kecil dari display area
- insets -> digunakan untuk menentukan external padding dari komponen, minimum space antara komponen dan ujung dari display area
- gridheight -> digunakan untuk menentukan jumlah sel di suatu kolom untuk display area komponen
- gridwidth -> digunakan untuk menentukan jumlah sel di baris untuk display area komponen

class Gridbagconstraint ini kita coba untuk di test di program yang kita beri nama "MyGridBagConstraints1.java" sbb :

Download Source :
esnips.com/doc/d4d4254d-46a8-4e8e-9f50-8ee70c7e8b17/MyGridBagConstraints1
=================================================================================================
package test1;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Insets;


import javax.swing.JFrame;

public class MyGridBagConstraints1 extends JFrame{

/**
* @param args
*/
private Label lblName = null;
private TextField txfName = null;
private Label lblAddress = null;
private TextField txfAddress = null;
private Label lblAge = null;
private TextField txfAge = null;
private Label lblWeight = null;
private TextField txfWeight = null;
private Label lblDescription = null;
private TextArea txaDescription = null;
private Panel pnlWeightAge = null;

public MyGridBagConstraints1() {
super("My Title");
initialize();
}

public void initialize(){

GridBagConstraints gbcLblName = new GridBagConstraints();
gbcLblName.gridx = 0;
gbcLblName.gridy = 1;
gbcLblName.anchor = GridBagConstraints.WEST;
gbcLblName.weighty = 0.1;
lblName = new Label();
lblName.setText("Name");
GridBagConstraints gbcTxfName = new GridBagConstraints();
gbcTxfName.gridx = 1;
gbcTxfName.gridy = 1;
gbcTxfName.anchor = GridBagConstraints.WEST;
gbcTxfName.insets = new Insets(0,10,0,5);
gbcTxfName.weightx = 0.1;

GridBagConstraints gbcLblAddress = new GridBagConstraints();
gbcLblAddress.gridx = 0;
gbcLblAddress.gridy = 2;
gbcLblAddress.anchor = GridBagConstraints.WEST;
gbcLblAddress.weighty = 0.1;
lblAddress = new Label();
lblAddress.setText("Address");
GridBagConstraints gbcTxfAddress = new GridBagConstraints();
gbcTxfAddress.gridx = 1;
gbcTxfAddress.gridy = 2;
gbcTxfAddress.anchor = GridBagConstraints.WEST;
gbcTxfAddress.insets = new Insets(0,10,0,5);
gbcTxfAddress.weightx = 0.1;

GridBagConstraints gbcLblAge = new GridBagConstraints();
gbcLblAge.gridx = 0;
gbcLblAge.gridy = 3;
gbcLblAge.anchor = GridBagConstraints.WEST;
gbcLblAge.weighty = 0.1;
lblAge = new Label();
lblAge.setText("Age");
GridBagConstraints gbcPnlWeightAge = new GridBagConstraints();
gbcPnlWeightAge.gridx = 1;
gbcPnlWeightAge.gridy = 3;
gbcPnlWeightAge.anchor = GridBagConstraints.WEST;
gbcPnlWeightAge.insets = new Insets(0,10,0,5);
gbcPnlWeightAge.weighty = 0.1;

GridBagConstraints gbcLblDescription = new GridBagConstraints();
gbcLblDescription.gridx = 0;
gbcLblDescription.gridy = 4;
gbcLblDescription.anchor = GridBagConstraints.WEST;
gbcLblDescription.weighty = 0.1;
lblDescription = new Label();
lblDescription.setText("description");
GridBagConstraints gbcTxaDescription = new GridBagConstraints();
gbcTxaDescription.gridx = 1;
gbcTxaDescription.gridy = 4;
gbcTxaDescription.anchor = GridBagConstraints.WEST;
gbcTxaDescription.insets = new Insets(0,10,0,5);
gbcTxaDescription.weightx = 0.1;

this.setLayout(new GridBagLayout());
this.setSize(new Dimension(695, 300));
this.add(lblName, gbcLblName);
this.add(getTxfName(), gbcTxfName);
this.add(lblAddress, gbcLblAddress);
this.add(getTxtAddress(), gbcTxfAddress);
this.add(lblAge, gbcLblAge);
this.add(getPnlWeightAge() , gbcPnlWeightAge);
this.add(lblDescription, gbcLblDescription);
this.add(getTxaDescription(), gbcTxaDescription);

}
private Panel getPnlWeightAge() {
if (pnlWeightAge == null) {
lblWeight = new Label();
lblWeight.setText("Weight");
pnlWeightAge = new Panel();
pnlWeightAge.add(getTxtAge(), null);
pnlWeightAge.add(lblWeight, null);
pnlWeightAge.add(getTxtWeight(), null);
}
return pnlWeightAge;
}

private TextField getTxfName() {
if (txfName == null) {
txfName = new TextField();
txfName.setColumns(30);
txfName.setName("name");
}
return txfName;
}

private TextField getTxtAddress() {
if (txfAddress == null) {
txfAddress = new TextField();
txfAddress.setColumns(40);
txfAddress.setName("address");
}
return txfAddress;
}

private TextField getTxtAge() {
if (txfAge == null) {
txfAge = new TextField();
txfAge.setColumns(10);
txfAge.setName("age");
}
return txfAge;
}

private TextField getTxtWeight() {
if (txfWeight == null) {
txfWeight = new TextField();
txfWeight.setColumns(10);
txfWeight .setName("weight");
}
return txfWeight;
}

private TextArea getTxaDescription() {
if (txaDescription == null) {
txaDescription = new TextArea();
txaDescription.setName("addRemark");
txaDescription .setRows(4);
txaDescription.setColumns(40);
}
return txaDescription;
}
}


=================================================================================================

Monday, October 20, 2008

Create dan Compile Program Assembler di Linux

- bikin program Assembler di linux bs gunakan editor "kwrite" or editor gedit misal : file dikasih nama hello.S
- untuk meng-compile program hello.S agar menghasilkan file object "hello.o" di linux dg perintah "as" yang merupakan compiler default pada linux yang menggunakan GNU Assembler compiler. seperti dibawah ini di console :

as -o hello.o hello.S

- untuk menghasilkan executable file nya digunakan perintah "ld".seperti dibawah ini

ld -s -o hello hello.o

- untuk menjalankan program yang dihasilkan tersebut dg perintah dibawah ini di console:

./hello