4/24/09

Swing example

LINK

You can see this document to understand how to code step by step to make a form by swing on Java Language.

Next step:
http://www.thainetbeans.com/sample/logindemo.htm

MessageDialog to shows the error message.

Here is the code of NextPage.java

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

class NextPage extends JFrame
{
NextPage()
{
setDefaultCloseOperation(javax.swing.
WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Welcome");
setSize(400, 200);
}
}

Here is the code of LoginDemo.java

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

class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
label1 = new JLabel();
label1.setText("Username:");
text1 = new JTextField(15);

label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);

SUBMIT=new JButton("SUBMIT");

panel=new JPanel(new GridLayout(3,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae)
{
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("roseindia") && value2.equals("roseindia")) {
NextPage page=new NextPage();
page.setVisible(true);
JLabel label = new JLabel("Welcome:"+value1);
page.getContentPane().add(label);
}
else{
System.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Incorrect login or password",
"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
class LoginDemo
{
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(300,100);
frame.setVisible(true);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}

Output will be displayed as:

Download Source Code

4/21/09

Cài đặt memcache, memcache PHP extension (Linux)

Bước 1
Download libevent , cài đặt :
#tar -xvf libevent-1.3b.tar.gz
#cd libevent-1.3b
#./configure
#make
#make install;

Bước 2
Download memcache, cài đặt :
#gunzip memcached-1.2.1.tar.gz
#tar -xvf memcached-1.2.1.tar
#cd memcached-1.2.1
#./configure
#make
#make install;

Bước 3
Tạo liên kết cho memcache :
#ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1
memcached -d -u nobody -m 512 127.0.0.1 -p 11211

Bước 4
Cài đặt gói pecl cho PHP (memcache PHP extension):
#wget http://pecl.php.net/get/memcache-2.1.2.tgz
#gzip -df memcache-2.1.2.tgz
#tar -xvf memcache-2.1.2.tar
#cd memcache-2.1.2
#phpize (Chú ý)
#./configure
#make
#make install

Chú ý : khi gõ lệnh #phpize có thể sẽ gặp lỗi như sau :
“Cannot find autoconf. Please check your autoconf installation”
Lỗi này là do bạn chưa install autoconf trên hệ thống. Bạn cần cài đặt autoconf và m4 cho hệ thống
Cách làm như sau:

# cd /usr/src
# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure
# make
# make install
# cd ../
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure
# make
# make install
Sau đó bạn có thể configure và install memcache PHP extension bình thường.

Bước 5
Tìm file php.ini, memcache.so bằng lệnh :
#whereis php.ini
và
#whereis memcache.so
Nó sẽ chỉ đường dẫn vào cả 2 file. Mở file php.ini.
Vào thư mục chứa file, gõ lệnh :
#nano php.ini
thêm câu lệnh sau vào file php.ini :
extension = /path/memcache.so
path là đường dẫn trực tiếp vào file memcache.so.

Trên đây là tất cả các bước cần thiết để cài đặt memcache cho hệ thống.
Chúc mọi người thành công !

4/16/09

Eclipse Thủ thuật

Ctr + Shift + R : open form to select file resource by keyword
sysout + Ctrl_SpaceBar ==> System.out.println("");

...













Encode to UTF-8
show in the below image:

4/11/09

Ngọc Lan

Mới phát hiện là bạn có thể xem được đám tang của Ngọc Lan trên youtube, 5 phần, lần lượt là
http://www.youtube.com/watch?v=GHTCNvVL2yQ
http://www.youtube.com/watch?v=G3eJ7YrQXhY
http://www.youtube.com/watch?v=UpH_yq6Q864
http://www.youtube.com/watch?v=6VpuSZWIz1A
http://www.youtube.com/watch?v=Yh4Rwd6WF3I

Coi xong nghẹn ngào quá mọi người ơi...... Dù là con trai nhưng tôi không thể nào kiềm nước mắt, một thần tượng âm nhạc với nét đẹp toàn diện từ tiếng hát, đến nhân dáng và nhân cách sống đã mãi mãi rời xa chúng ta rồi!

4/7/09

Đừng bắt ép ai phải suy nghĩ hay hành động giống với cách nghĩ và cách làm của mình

S2Dao

S2Dao: 2-Way SQL

S2Dao can assemble dynamic query using SQL comment. For example:

@Sql("SELECT * FROM emp WHERE empno = /*empno*/7788")
@Arguments("empno")
public Emp selectEmpByEmpNo(int empNo);

/*empno*/ replaces the given argument and 7788 is removed by S2Dao at runtime. We can execute this SQL without no modification with the database client software such as psql. This solutuion is called "2-Way SQL" in S2Dao.

We can also use IF..ELSE statement as SQL comment.

/*IF hoge != null*/hoge = /*hoge*/'abc'/*END*/

And see the following example. If all conditions are false, S2Dao ignores /*BEGIN*/ ... /*END*/ block. So WHERE phrase is removed when it's not needed.

/*BEGIN*/WHERE
/*IF job != null*/job = /*job*/'CLERK'/*END*/
/*IF deptno != null*/AND deptno = /*deptno*/20/*END*/
/*END*/

Again, these SQL can be executed with database client software with no modifications. 2-Way SQL makes possible to test SQL easily.