Archive for September, 2005

How to turn your “home PC” into a “revenue generator”? (Part 1)

Wednesday, September 28th, 2005

How to turn your "home PC" into a "revenue generator"? (Part 1)

I’ve been asking myself all the while: "Is there anyway of making smart-money rather than hard-money?" … Yes, there’s a way to do it, and certainly affiliate marketing is the best way!

(Question) Why should you read on?
- Well this is a free tips from me to share out rather you take it or leave it!
- I’m making small money daily (in USD, yes it is stronger than MYR), and I’m gonna tell you exactly how to do it.
- After all you got something to gain but nothing to lose (all my tactics were free)!

The concept is simple, you help merchant to acheive sells and they will reward you accordingly.

(Question) What you need to get start?
- A computer with access to internet.
- A bank account to deposit your commissions
               OR
  A permenant address for receiving commission cheques.
- A few hours of time.

Firstly, get a famous Affiliate Program Providers (APPs) account from LinkShare, ClickBank, Commission Junction, Befree and others.

Then find a advertiser like eBay, Amazon … and register as their affiliate (reseller).

Go on and find a free hosting and put those ads on the side  to start working, there’s all it needs … so simple! TIPs: Don’t build a site for advertise only, like eBay (provide a brief description or review on products 1st, then only ask ppl to click on links). Normally it works better for simple static page, don’t waste your time designing cool sites which don’t serve the purpose. User will go away in 5 seconds if they don’t see what they are looking for.

I had provided the links for each example, go on and try to register first, for more details let me explain on the following blog.

Note:
- More real life example on the next episode, including how to setup all accounts.
- Don’t rush on starting it now, do more work on researching which advertiser is more profitable andwhich the product you are familiar in.

Regards,
Avatar Ng

Writing a XMPP compatible chat client(Google Talk)

Tuesday, September 20th, 2005

I think I just start off to the topic, firstly u need a 3rd-party library "smack.jar"+"smackx.jar" which extracted from "smack-2.0.0.zip". Get the file from here !

I’m using "javax.swing" classes to build the UI, below is a brief design layout:
+———————————————–+
|  Login : __________                            | <—- login name (e.g.: yourmail.google.com)
| Password: ________ | Login|               | <—- password (e.g.: google mail password)
+———————————————–+
|  +——————————+  | Send | |
|  |                                      |               |
|  |                                      |               |
|  +——————————+  | quit  | |
|  _____________________________ V   |   <— friend’s list
|  _______________________________  |   <—- chat message here
+———————————————–+

Now u get what u needed, put the libraries in a the classpath so that your Java compiler can find it.
Here’s the code and I’ll explains line by line in comments (codes are meant to be small to save up space, simply cut and paste to a textpad for the aid of reading):
____________________________________________________________________________

ChatClient.java
____________________________________________________________________________

package com.avatar.chat;

// import swing classes
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

// import smack classes
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.filter.*;

// packet listener will required you to implement a method
// called
 "processPacket(Packet packet)" which lets you
// go lower level to handle the in/out packets better

public class ChatClient extends JFrame implements ActionListener, PacketListener{
    private JButton btnLogin, btnSend, btnQuit;
    private JTextArea taChatArea;
    private JTextField tfChatMessage, tfLoginName;
    private JComboBox cbOpponent;
    private JPasswordField pfLoginPassword;

// GoogleTalkConnection is one of the class by Smack
    private GoogleTalkConnection con = null;

// GroupChat will allowed you to listen to more than 1 opponent
    private GroupChat chat = null;
    private String login_name = "";
    private String login_password = "";
    private String opponent = "";
    private boolean isLogin = false;

// require class — PacketFilter and PacketCollector, explain below
    private PacketFilter filter = null;
    private PacketCollector myCollector = null;

// Message is a class to hold all data which  extracted from the packet,
// e.g. sender, receiver, timestamp, message … etc

    private Message msg = null;
   
    public ChatClient(){
        super("Chat Client");
       
        setSize(400,300);
        setResizable(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BorderLayout(0,0));
        initComponents();

        setVisible(true);
    }
   
    public void initComponents(){
        btnLogin = new JButton("Login");
        btnLogin.addActionListener(this);   
        btnSend = new JButton("Send");
        btnSend.setMnemonic(KeyEvent.VK_ENTER);
        btnSend.addActionListener(this);
        btnQuit = new JButton("Quit");
        btnQuit.addActionListener(this);
        taChatArea = new JTextArea(10,40);
        taChatArea.setEditable(false);
        JScrollPane chatScroller = new JScrollPane(taChatArea);
        chatScroller.setPreferredSize(new Dimension(300, 200));
        chatScroller.setMinimumSize(new Dimension(300, 200));
        chatScroller.setAlignmentX(Component.LEFT_ALIGNMENT);
        tfChatMessage = new JTextField(40);
        tfLoginName = new JTextField(10);
        cbOpponent = new JComboBox();
        cbOpponent.setEditable(true);
        pfLoginPassword = new JPasswordField(10);
       
        JPanel pnlButton = new JPanel(new GridLayout(2,1,0,0));
        JPanel pnlLogin = new JPanel(new GridLayout(3,2,0,0));
        JPanel pnlMessage = new JPanel(new GridLayout(2,1,0,0));
       
        pnlLogin.add(new JLabel("User Name:"));
        pnlLogin.add(tfLoginName);
        pnlLogin.add(new JLabel("Password:"));
        pnlLogin.add(pfLoginPassword);
        pnlLogin.add(new JLabel("press here to login ->"));
        pnlLogin.add(btnLogin);
        pnlButton.add(btnSend);
        pnlButton.add(btnQuit);
        pnlMessage.add(cbOpponent);
        pnlMessage.add(tfChatMessage);
       
        setChat(false);
       
        add(pnlLogin, BorderLayout.NORTH);
        add(pnlButton, BorderLayout.EAST);
        add(chatScroller, BorderLayout.CENTER);
        add(pnlMessage, BorderLayout.SOUTH);
    }
   
// disable  sending meassage when  variable ‘mark’ is false (offline), and vice-versa
    public void setChat(boolean mark){
        tfChatMessage.setEnabled(mark);
        cbOpponent.setEnabled(mark);
        btnSend.setEnabled(mark);
    }
   

// clean up jobs appoint exit
    public void logout(){
        if(con!=null){
            con.close();
        }
        cbOpponent.removeAllItems();
    }
   

// when user logged in, set the flag to true (online)
    public boolean login(String login_name,String login_password){

        // get textfield’s username
        this.login_name = login_name;

        // get passwordfield’s password
        this.login_password = login_password;
        boolean flag = false;
       
        try{
            con = new GoogleTalkConnection();
            con.login(login_name, login_password);
            

        // filter the XML packet into a PacketCollector (much like a queue),
       // so that you can get them back later

            filter = new AndFilter(
                       new PacketTypeFilter(Message.class),
                       new FromContainsFilter(opponent));
            myCollector = con.createPacketCollector(filter);
            

        // initialise your chatgroup
            chat = con.createGroupChat(login_name+"’s Chat");

        // initialise your message
            msg = new Message();
            

        // get all user from your friends list
            Roster roster = con.getRoster();
            for (Iterator i=roster.getEntries(); i.hasNext(); ) {
                RosterEntry re = (RosterEntry)i.next();
                cbOpponent.addItem(re.getUser());

                // Register the listener.   
            }
            
            con.addPacketListener(this, filter);
            
            setChat(true);
            flag = true;
        }catch(Exception ex){
            ex.printStackTrace();

        // any thing during  login, disable user to send message
            setChat(false);
            flag = false;
        }finally{
            return flag;
        }
    }
   
    public void windowClosing(WindowEvent we){
       logout();
    }

    // implementing processPacket for PacketListener interface
    public void processPacket(Packet packet) {
       
// Put the incoming message on the chat history or chat board.
        Message msg = (Message)packet;
        taChatArea.append(msg.getFrom()+
                          ": "+msg.getBody()+"\n");
    }
   
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==btnLogin){
            String test = btnLogin.getLabel();
            if(test.equals("Login")){
                isLogin = login(tfLoginName.getText().toString().trim(),
                                pfLoginPassword.getText().toString().trim());
                btnLogin.setLabel("Logout");
            }else if(test.equals("Logout")){
                logout();
                setChat(false);
                isLogin = false;
                btnLogin.setLabel("Login");
            }   
        }else if(e.getSource()==btnSend){
            opponent = cbOpponent.getSelectedItem().toString();
            String content = tfChatMessage.getText().toString();
            if(isLogin){
                try{
                    msg.setTo(opponent);
                    msg.setBody(content);            
                    chat.sendMessage(msg);

                        // append your sent message to chat board
                    taChatArea.append(login_name+": "+tfChatMessage.getText()+"\n");
                }catch(Exception ex){
                    ex.printStackTrace();
                }
            }
        }
        else if(e.getSource()==btnQuit){
            logout();
            System.exit(0);
        }
    }
   
    public static void main(String[] args){
        ChatClient c = new ChatClient();
    }
}

___________________________________________________________
End of
"ChatClient.java"
___________________________________________________________
Thanks to Smack by JiveSoftware, online messager never got easier to write!

The final output should looks like this, still depends on platform and versioning of JDK.

Other resoures:

[NOTE: Smack is a trademark of Jive Software, Google Talk is a trademark of Google.]