twittertimeline.MainFrame.java Source code

Java tutorial

Introduction

Here is the source code for twittertimeline.MainFrame.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package twittertimeline;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import twitter4j.Paging;
import twitter4j.Status;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

/**
 *
 * @author hackp
 */
public class MainFrame extends javax.swing.JFrame {

    TwitterFactory tw;
    twitter4j.Twitter twt;
    int pageCounter = 1, twCounter = 1;
    List<Status> status1, status2;
    Paging pg;

    //After the rt,fw buttons, we need to keep this tweets as a rt or fw. So we will use this list.
    //If program would restart, this info will be refresh. This lists for the before the restart. 
    //Shortly, for offline proccess.
    List<Long> rtList, fwList;

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        Tweet = new javax.swing.JButton();
        SizeOfTweet = new javax.swing.JLabel();
        photoPanel = new javax.swing.JPanel();
        photo = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TweetArea = new javax.swing.JTextArea();
        refresh = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tweet1 = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        tweet2 = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        tweet3 = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        tweet4 = new javax.swing.JTextArea();
        jScrollPane6 = new javax.swing.JScrollPane();
        tweet5 = new javax.swing.JTextArea();
        next = new javax.swing.JButton();
        previous = new javax.swing.JButton();
        userPhoto1 = new javax.swing.JPanel();
        user1 = new javax.swing.JLabel();
        username2 = new javax.swing.JLabel();
        userPhoto2 = new javax.swing.JPanel();
        user2 = new javax.swing.JLabel();
        username3 = new javax.swing.JLabel();
        userPhoto3 = new javax.swing.JPanel();
        user3 = new javax.swing.JLabel();
        username4 = new javax.swing.JLabel();
        userPhoto4 = new javax.swing.JPanel();
        user4 = new javax.swing.JLabel();
        username5 = new javax.swing.JLabel();
        userPhoto5 = new javax.swing.JPanel();
        user5 = new javax.swing.JLabel();
        username6 = new javax.swing.JLabel();
        retweet1 = new javax.swing.JButton();
        favorite1 = new javax.swing.JButton();
        retweet2 = new javax.swing.JButton();
        retweet3 = new javax.swing.JButton();
        retweet4 = new javax.swing.JButton();
        retweet5 = new javax.swing.JButton();
        favorite2 = new javax.swing.JButton();
        favorite3 = new javax.swing.JButton();
        favorite4 = new javax.swing.JButton();
        favorite5 = new javax.swing.JButton();
        tate1 = new javax.swing.JLabel();
        tate2 = new javax.swing.JLabel();
        tate3 = new javax.swing.JLabel();
        tate4 = new javax.swing.JLabel();
        tate5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Twikstop");
        setBackground(new java.awt.Color(0, 102, 153));
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(153, 204, 255));

        Tweet.setText("Tweet");
        Tweet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TweetActionPerformed(evt);
            }
        });

        SizeOfTweet.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        SizeOfTweet.setAutoscrolls(true);
        SizeOfTweet.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);

        photoPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        javax.swing.GroupLayout photoPanelLayout = new javax.swing.GroupLayout(photoPanel);
        photoPanel.setLayout(photoPanelLayout);
        photoPanelLayout.setHorizontalGroup(
                photoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(photo,
                        javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE));
        photoPanelLayout.setVerticalGroup(
                photoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(photo,
                        javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE));

        TweetArea.setColumns(20);
        TweetArea.setRows(5);
        TweetArea.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        TweetArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TweetAreaKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(TweetArea);

        refresh.setBackground(new java.awt.Color(0, 0, 204));
        refresh.setFont(new java.awt.Font("Dialog", 1, 8)); // NOI18N
        refresh.setForeground(new java.awt.Color(102, 255, 255));
        refresh.setText("Refresh");
        refresh.setBorder(null);
        refresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                .addComponent(photoPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(31, 31, 31))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(35, 35, 35)
                                .addComponent(refresh, javax.swing.GroupLayout.PREFERRED_SIZE, 53,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(SizeOfTweet, javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(141, 141, 141).addComponent(Tweet))
                                .addComponent(jScrollPane1))
                        .addGap(23, 23, 23)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 126,
                                        Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(Tweet, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(SizeOfTweet, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addContainerGap())
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(photoPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28).addComponent(refresh, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))));

        jScrollPane2.setBorder(null);

        tweet1.setEditable(false);
        tweet1.setBackground(new java.awt.Color(153, 204, 255));
        tweet1.setColumns(20);
        tweet1.setLineWrap(true);
        tweet1.setRows(5);
        tweet1.setWrapStyleWord(true);
        tweet1.setBorder(null);
        jScrollPane2.setViewportView(tweet1);

        jScrollPane3.setBorder(null);

        tweet2.setEditable(false);
        tweet2.setBackground(new java.awt.Color(153, 204, 255));
        tweet2.setColumns(20);
        tweet2.setLineWrap(true);
        tweet2.setRows(5);
        tweet2.setWrapStyleWord(true);
        tweet2.setBorder(null);
        jScrollPane3.setViewportView(tweet2);

        jScrollPane4.setBorder(null);

        tweet3.setEditable(false);
        tweet3.setBackground(new java.awt.Color(153, 204, 255));
        tweet3.setColumns(20);
        tweet3.setLineWrap(true);
        tweet3.setRows(5);
        tweet3.setWrapStyleWord(true);
        tweet3.setBorder(null);
        jScrollPane4.setViewportView(tweet3);

        jScrollPane5.setBorder(null);

        tweet4.setEditable(false);
        tweet4.setBackground(new java.awt.Color(153, 204, 255));
        tweet4.setColumns(20);
        tweet4.setLineWrap(true);
        tweet4.setRows(5);
        tweet4.setWrapStyleWord(true);
        tweet4.setBorder(null);
        jScrollPane5.setViewportView(tweet4);

        jScrollPane6.setBorder(null);

        tweet5.setEditable(false);
        tweet5.setBackground(new java.awt.Color(153, 204, 255));
        tweet5.setColumns(20);
        tweet5.setLineWrap(true);
        tweet5.setRows(5);
        tweet5.setWrapStyleWord(true);
        tweet5.setBorder(null);
        jScrollPane6.setViewportView(tweet5);

        next.setBackground(new java.awt.Color(153, 204, 255));
        next.setText("NEXT >>");
        next.setBorder(null);
        next.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextActionPerformed(evt);
            }
        });

        previous.setBackground(new java.awt.Color(153, 204, 255));
        previous.setText("<< PREVIOUS");
        previous.setBorder(null);
        previous.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previousActionPerformed(evt);
            }
        });

        username2.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        username2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        username2.setText("jLabel1");
        username2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout userPhoto1Layout = new javax.swing.GroupLayout(userPhoto1);
        userPhoto1.setLayout(userPhoto1Layout);
        userPhoto1Layout
                .setHorizontalGroup(userPhoto1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(userPhoto1Layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(user1, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())
                        .addComponent(username2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        userPhoto1Layout.setVerticalGroup(userPhoto1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(userPhoto1Layout.createSequentialGroup()
                        .addComponent(user1, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(username2)));

        username3.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        username3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        username3.setText("jLabel1");
        username3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout userPhoto2Layout = new javax.swing.GroupLayout(userPhoto2);
        userPhoto2.setLayout(userPhoto2Layout);
        userPhoto2Layout
                .setHorizontalGroup(userPhoto2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(userPhoto2Layout.createSequentialGroup().addContainerGap()
                                .addComponent(user2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
                        .addGroup(userPhoto2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(username3, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)));
        userPhoto2Layout.setVerticalGroup(userPhoto2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(userPhoto2Layout.createSequentialGroup()
                        .addComponent(user2, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(userPhoto2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, userPhoto2Layout
                                .createSequentialGroup().addGap(0, 60, Short.MAX_VALUE).addComponent(username3))));

        username4.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        username4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        username4.setText("jLabel1");

        javax.swing.GroupLayout userPhoto3Layout = new javax.swing.GroupLayout(userPhoto3);
        userPhoto3.setLayout(userPhoto3Layout);
        userPhoto3Layout
                .setHorizontalGroup(userPhoto3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(userPhoto3Layout.createSequentialGroup().addContainerGap()
                                .addComponent(user3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
                        .addGroup(userPhoto3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(username4, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)));
        userPhoto3Layout.setVerticalGroup(userPhoto3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(userPhoto3Layout.createSequentialGroup()
                        .addComponent(user3, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(userPhoto3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, userPhoto3Layout
                                .createSequentialGroup().addGap(0, 60, Short.MAX_VALUE).addComponent(username4))));

        username5.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        username5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        username5.setText("jLabel1");

        javax.swing.GroupLayout userPhoto4Layout = new javax.swing.GroupLayout(userPhoto4);
        userPhoto4.setLayout(userPhoto4Layout);
        userPhoto4Layout.setHorizontalGroup(userPhoto4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(userPhoto4Layout.createSequentialGroup().addContainerGap()
                        .addComponent(user4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                .addGroup(userPhoto4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(username5, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)));
        userPhoto4Layout.setVerticalGroup(userPhoto4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(userPhoto4Layout.createSequentialGroup()
                        .addComponent(user4, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(userPhoto4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, userPhoto4Layout
                                .createSequentialGroup().addGap(0, 60, Short.MAX_VALUE).addComponent(username5))));

        username6.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        username6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        username6.setText("jLabel1");

        javax.swing.GroupLayout userPhoto5Layout = new javax.swing.GroupLayout(userPhoto5);
        userPhoto5.setLayout(userPhoto5Layout);
        userPhoto5Layout.setHorizontalGroup(userPhoto5Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(userPhoto5Layout.createSequentialGroup().addContainerGap()
                        .addComponent(user5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                .addGroup(userPhoto5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(username6, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)));
        userPhoto5Layout.setVerticalGroup(userPhoto5Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(userPhoto5Layout.createSequentialGroup()
                        .addComponent(user5, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(userPhoto5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, userPhoto5Layout
                                .createSequentialGroup().addGap(0, 60, Short.MAX_VALUE).addComponent(username6))));

        retweet1.setBackground(new java.awt.Color(51, 153, 255));
        retweet1.setForeground(new java.awt.Color(255, 255, 255));
        retweet1.setText("RT");
        retweet1.setBorder(null);
        retweet1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                retweet1ActionPerformed(evt);
            }
        });

        favorite1.setBackground(new java.awt.Color(255, 204, 0));
        favorite1.setForeground(new java.awt.Color(51, 0, 204));
        favorite1.setText("FW");
        favorite1.setBorder(null);
        favorite1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                favorite1ActionPerformed(evt);
            }
        });

        retweet2.setBackground(new java.awt.Color(51, 153, 255));
        retweet2.setForeground(new java.awt.Color(255, 255, 255));
        retweet2.setText("RT");
        retweet2.setBorder(null);
        retweet2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                retweet2ActionPerformed(evt);
            }
        });

        retweet3.setBackground(new java.awt.Color(51, 153, 255));
        retweet3.setForeground(new java.awt.Color(255, 255, 255));
        retweet3.setText("RT");
        retweet3.setBorder(null);
        retweet3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                retweet3ActionPerformed(evt);
            }
        });

        retweet4.setBackground(new java.awt.Color(51, 153, 255));
        retweet4.setForeground(new java.awt.Color(255, 255, 255));
        retweet4.setText("RT");
        retweet4.setBorder(null);
        retweet4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                retweet4ActionPerformed(evt);
            }
        });

        retweet5.setBackground(new java.awt.Color(51, 153, 255));
        retweet5.setForeground(new java.awt.Color(255, 255, 255));
        retweet5.setText("RT");
        retweet5.setBorder(null);
        retweet5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                retweet5ActionPerformed(evt);
            }
        });

        favorite2.setBackground(new java.awt.Color(255, 204, 0));
        favorite2.setForeground(new java.awt.Color(51, 0, 204));
        favorite2.setText("FW");
        favorite2.setBorder(null);
        favorite2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                favorite2ActionPerformed(evt);
            }
        });

        favorite3.setBackground(new java.awt.Color(255, 204, 0));
        favorite3.setForeground(new java.awt.Color(51, 0, 204));
        favorite3.setText("FW");
        favorite3.setBorder(null);
        favorite3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                favorite3ActionPerformed(evt);
            }
        });

        favorite4.setBackground(new java.awt.Color(255, 204, 0));
        favorite4.setForeground(new java.awt.Color(51, 0, 204));
        favorite4.setText("FW");
        favorite4.setBorder(null);
        favorite4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                favorite4ActionPerformed(evt);
            }
        });

        favorite5.setBackground(new java.awt.Color(255, 204, 0));
        favorite5.setForeground(new java.awt.Color(51, 0, 204));
        favorite5.setText("FW");
        favorite5.setBorder(null);
        favorite5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                favorite5ActionPerformed(evt);
            }
        });

        tate1.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        tate1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tate1.setText("jLabel1");
        tate1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        tate2.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        tate2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tate2.setText("jLabel1");
        tate2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        tate3.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        tate3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tate3.setText("jLabel1");
        tate3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        tate4.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        tate4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tate4.setText("jLabel1");
        tate4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        tate5.setFont(new java.awt.Font("Dialog", 0, 7)); // NOI18N
        tate5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tate5.setText("jLabel1");
        tate5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 11, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                layout.createSequentialGroup().addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(userPhoto1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(userPhoto2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(userPhoto3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(userPhoto4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(userPhoto5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(favorite1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(favorite2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(favorite3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(favorite4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(favorite5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(retweet5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(retweet4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(retweet3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(retweet2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(
                                                        retweet1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(12, 12, 12)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        layout.createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                                .addComponent(jScrollPane6,
                                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 310,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(jScrollPane2)
                                                                .addComponent(jScrollPane3)
                                                                .addComponent(jScrollPane4)
                                                                .addComponent(jScrollPane5))
                                                .addGroup(layout.createSequentialGroup().addGap(4, 4, 4)
                                                        .addComponent(previous,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 109,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(next, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                110, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(tate1, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 198,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(tate2, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 198,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(tate3, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 198,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(tate4, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 198,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(tate5, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 185,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(retweet1, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(favorite1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(userPhoto1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jScrollPane2))
                        .addGap(4, 4, 4).addComponent(tate1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(userPhoto2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jScrollPane3)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(retweet2, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12).addComponent(favorite2,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(tate2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(userPhoto3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jScrollPane4)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(retweet3, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12).addComponent(favorite3,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(tate3).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(userPhoto4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jScrollPane5)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(retweet4, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12).addComponent(favorite4,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(tate4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(retweet5, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12).addComponent(favorite5,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(userPhoto5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jScrollPane6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(tate5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(previous, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                                .addComponent(next, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TweetAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TweetAreaKeyTyped
        // TODO add your handling code here:

        //Check the size of tweet while writing. 
        int size = TweetArea.getText().length() + 1;
        SizeOfTweet.setText(size + "");
        if (size > 140)
            Tweet.setEnabled(false);
        else
            Tweet.setEnabled(true);

        TweetArea.setLineWrap(true);
    }//GEN-LAST:event_TweetAreaKeyTyped

    private void TweetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TweetActionPerformed
        // TODO add your handling code here:

        //Status updating 
        try {
            Status status = twt.updateStatus(TweetArea.getText());
            photo.setText("Status updated");
        } catch (Exception e) {
            photo.setText("ERROR");
        }
    }//GEN-LAST:event_TweetActionPerformed

    private void nextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextActionPerformed
        // TODO add your handling code here:

        //To change next page. We need to get tweets for timeline. 
        twCounter += 5;
        if (twCounter > status1.size())
            try {
                getTweets();
            } catch (TwitterException ex) {
                twCounter -= 5;
                return;
            }
        showTweets();
    }//GEN-LAST:event_nextActionPerformed

    private void previousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousActionPerformed
        // TODO add your handling code here:
        //To change previous page. 
        if (twCounter > 5) {
            twCounter -= 5;
            showTweets();
        } else
            return;
    }//GEN-LAST:event_previousActionPerformed

    private void retweet1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retweet1ActionPerformed

        //Retweet action for 1st tweet. Retweet and set enabled as a false for the button.
        //And we need to add this tweet id to list. 

        try {
            // TODO add your handling code here:
            twt.retweetStatus(status1.get(twCounter).getId());
            retweet1.setBackground(Color.RED);
            retweet1.setEnabled(false);
            rtList.add(status1.get(twCounter).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_retweet1ActionPerformed

    private void retweet2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retweet2ActionPerformed
        //Retweet action for 2nd tweet. Retweet and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.retweetStatus(status1.get(twCounter + 1).getId());
            retweet1.setBackground(Color.RED);
            retweet1.setEnabled(false);
            rtList.add(status1.get(twCounter + 1).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_retweet2ActionPerformed

    private void retweet3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retweet3ActionPerformed
        //Retweet action for 3rd tweet. Retweet and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.retweetStatus(status1.get(twCounter + 2).getId());
            retweet2.setBackground(Color.RED);
            retweet2.setEnabled(false);
            rtList.add(status1.get(twCounter + 2).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_retweet3ActionPerformed

    private void retweet4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retweet4ActionPerformed
        //Retweet action for 4th tweet. Retweet and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.retweetStatus(status1.get(twCounter + 3).getId());
            retweet3.setBackground(Color.RED);
            retweet3.setEnabled(false);
            rtList.add(status1.get(twCounter + 3).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_retweet4ActionPerformed

    private void retweet5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retweet5ActionPerformed
        //Retweet action for 5th tweet. Retweet and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.retweetStatus(status1.get(twCounter + 4).getId());
            retweet5.setBackground(Color.RED);
            retweet5.setEnabled(false);
            rtList.add(status1.get(twCounter + 4).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_retweet5ActionPerformed

    private void favorite1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_favorite1ActionPerformed
        //Favourite action for 1st tweet. Favourited and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.createFavorite(status1.get(twCounter).getId());
            favorite1.setBackground(Color.RED);
            favorite1.setEnabled(false);
            fwList.add(status1.get(twCounter).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_favorite1ActionPerformed

    private void favorite2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_favorite2ActionPerformed
        //Favourite action for 2nd tweet. Favourited and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.createFavorite(status1.get(twCounter + 1).getId());
            favorite2.setBackground(Color.RED);
            favorite2.setEnabled(false);
            fwList.add(status1.get(twCounter + 1).getId());

        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_favorite2ActionPerformed

    private void favorite3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_favorite3ActionPerformed
        //Favourite action for 3rd tweet. Favourited and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.createFavorite(status1.get(twCounter + 2).getId());
            favorite3.setBackground(Color.RED);
            favorite3.setEnabled(false);
            fwList.add(status1.get(twCounter + 2).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_favorite3ActionPerformed

    private void favorite4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_favorite4ActionPerformed
        //Favourite action for 4th tweet. Favourited and set enabled as a false for the button.
        //And we need to add this tweet id to list. 
        try {
            // TODO add your handling code here:
            twt.createFavorite(status1.get(twCounter + 3).getId());
            favorite4.setBackground(Color.RED);
            favorite4.setEnabled(false);
            fwList.add(status1.get(twCounter + 3).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_favorite4ActionPerformed

    private void favorite5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_favorite5ActionPerformed
        //Favourite action for 5th tweet. Favourited and set enabled as a false for the button.
        //And we need to add this tweet id to list.  
        try {
            // TODO add your handling code here:
            twt.createFavorite(status1.get(twCounter + 4).getId());
            favorite5.setBackground(Color.RED);
            favorite5.setEnabled(false);
            fwList.add(status1.get(twCounter + 4).getId());
        } catch (TwitterException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_favorite5ActionPerformed

    private void refreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshActionPerformed
        // TODO add your handling code here:

        //We download timeline again. And values sets to 1.
        //Tweets are refreshed. So, we can clean our rt and fw lists too. 
        try {
            pageCounter = 1;
            twCounter = 1;

            pg = new Paging(pageCounter);
            pageCounter++;
            status1 = twt.getHomeTimeline(pg);

            rtList = new ArrayList<Long>();
            fwList = new ArrayList<Long>();
            getTweets();
            showTweets();
        } catch (Exception e) {
        }
    }//GEN-LAST:event_refreshActionPerformed

    public void SetTwitter() throws TwitterException {
        //Keys
        ConfigurationBuilder cf = new ConfigurationBuilder();
        cf.setDebugEnabled(true).setOAuthConsumerKey("").setOAuthConsumerSecret("").setOAuthAccessToken("")
                .setOAuthAccessTokenSecret("");

        //Create twitter object
        tw = new TwitterFactory(cf.build());
        twt = tw.getInstance();

        //Setting the photo of login user 
        BufferedImage img = null;
        try {
            img = ImageIO.read(new URL(twt.showUser("username").getOriginalProfileImageURL()));
            photo.setIcon(
                    new ImageIcon(img.getScaledInstance(photo.getWidth(), photo.getHeight(), img.SCALE_DEFAULT)));

        } catch (Exception e) {
            photo.setText("Photo Error");
        }

        pg = new Paging(pageCounter);
        pageCounter++;

        //Get first page of timeline        
        status1 = twt.getHomeTimeline(pg);

        rtList = new ArrayList<Long>();
        fwList = new ArrayList<Long>();
        getTweets();
        showTweets();

    }

    //Setting the user images of tweets. We pull photo with user id and put it to label. 
    void stImage(JLabel lb, long user) {
        BufferedImage img = null;
        try {
            img = ImageIO.read(new URL(twt.showUser(user).getBiggerProfileImageURL()));
            lb.setIcon(new ImageIcon(img.getScaledInstance(lb.getWidth(), lb.getHeight(), img.SCALE_DEFAULT)));

        } catch (Exception e) {
        }
    }

    //Getting tweets text, username and fav count. And put them to suitable place.   
    void showTweets() {

        tweet1.setText(status1.get(twCounter).getText());
        username2.setText(status1.get(twCounter).getUser().getScreenName());
        tate1.setText(status1.get(twCounter).getFavoriteCount() + " FAV");
        stImage(user1, status1.get(twCounter).getUser().getId());

        tweet2.setText(status1.get(twCounter + 1).getText());
        username3.setText(status1.get(twCounter + 1).getUser().getScreenName());
        tate2.setText(status1.get(twCounter + 1).getFavoriteCount() + " FAV");
        stImage(user2, status1.get(twCounter + 1).getUser().getId());

        tweet3.setText(status1.get(twCounter + 2).getText());
        username4.setText(status1.get(twCounter + 2).getUser().getScreenName());
        tate3.setText(status1.get(twCounter + 2).getFavoriteCount() + " FAV");
        stImage(user3, status1.get(twCounter + 2).getUser().getId());

        tweet4.setText(status1.get(twCounter + 3).getText());
        username5.setText(status1.get(twCounter + 3).getUser().getScreenName());
        tate4.setText(status1.get(twCounter + 3).getFavoriteCount() + " FAV");
        stImage(user4, status1.get(twCounter + 3).getUser().getId());

        tweet5.setText(status1.get(twCounter + 4).getText());
        username6.setText(status1.get(twCounter + 4).getUser().getScreenName());
        tate5.setText(status1.get(twCounter + 4).getFavoriteCount() + " FAV");
        stImage(user5, status1.get(twCounter + 4).getUser().getId());

        checkTweets();

    }

    //Checking the tweets and set their RT/FW buttons.
    void checkTweets() {
        if ((status1.get(twCounter).isRetweetedByMe()) || rtList.contains(status1.get(twCounter).getId()))
            doPassiveRt(retweet1);
        else
            doActiveRt(retweet1);

        if ((status1.get(twCounter + 1).isRetweetedByMe()) || rtList.contains(status1.get(twCounter + 1).getId()))
            doPassiveRt(retweet2);
        else
            doActiveRt(retweet2);

        if ((status1.get(twCounter + 2).isRetweetedByMe()) || rtList.contains(status1.get(twCounter + 2).getId()))
            doPassiveRt(retweet3);
        else
            doActiveRt(retweet3);

        if ((status1.get(twCounter + 3).isRetweetedByMe()) || rtList.contains(status1.get(twCounter + 3).getId()))
            doPassiveRt(retweet4);
        else
            doActiveRt(retweet4);

        if ((status1.get(twCounter + 4).isRetweetedByMe()) || rtList.contains(status1.get(twCounter + 4).getId()))
            doPassiveRt(retweet5);
        else
            doActiveRt(retweet5);

        if ((status1.get(twCounter).isFavorited()) || fwList.contains(status1.get(twCounter).getId()))
            doPassiveFw(favorite1);
        else
            doActiveFw(favorite1);

        if ((status1.get(twCounter + 1).isFavorited()) || fwList.contains(status1.get(twCounter + 1).getId()))
            doPassiveFw(favorite2);
        else
            doActiveFw(favorite2);

        if ((status1.get(twCounter + 2).isFavorited()) || fwList.contains(status1.get(twCounter + 2).getId()))
            doPassiveFw(favorite3);
        else
            doActiveFw(favorite3);

        if ((status1.get(twCounter + 3).isFavorited()) || fwList.contains(status1.get(twCounter + 3).getId()))
            doPassiveFw(favorite4);
        else
            doActiveFw(favorite4);

        if ((status1.get(twCounter + 4).isFavorited()) || fwList.contains(status1.get(twCounter + 4).getId()))
            doPassiveFw(favorite5);
        else
            doActiveFw(favorite5);

    }

    //Setting the button states
    void doActiveRt(JButton button) {
        button.setBackground(new Color(51, 153, 255));
        button.setEnabled(true);
    }

    //Setting the button states    
    void doPassiveRt(JButton button) {
        button.setBackground(Color.red);
        button.setEnabled(false);
    }

    //Setting the button states    
    void doActiveFw(JButton button) {
        button.setBackground(new Color(255, 204, 0));
        button.setEnabled(true);
    }

    //Setting the button states    
    void doPassiveFw(JButton button) {
        button.setBackground(Color.red);
        button.setEnabled(false);
    }

    //Getting new 5 timeline pages  
    void getTweets() throws TwitterException {
        int start = pageCounter;
        pageCounter += 5;
        for (int counter = start; counter <= pageCounter; counter++) {
            pg = new Paging(counter);
            status2 = twt.getHomeTimeline(pg);
            if (status2.isEmpty())
                break;
            for (Status s : status2) {
                status1.add(s);
            }
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel SizeOfTweet;
    private javax.swing.JButton Tweet;
    private javax.swing.JTextArea TweetArea;
    private javax.swing.JButton favorite1;
    private javax.swing.JButton favorite2;
    private javax.swing.JButton favorite3;
    private javax.swing.JButton favorite4;
    private javax.swing.JButton favorite5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JButton next;
    private javax.swing.JLabel photo;
    private javax.swing.JPanel photoPanel;
    private javax.swing.JButton previous;
    private javax.swing.JButton refresh;
    private javax.swing.JButton retweet1;
    private javax.swing.JButton retweet2;
    private javax.swing.JButton retweet3;
    private javax.swing.JButton retweet4;
    private javax.swing.JButton retweet5;
    private javax.swing.JLabel tate1;
    private javax.swing.JLabel tate2;
    private javax.swing.JLabel tate3;
    private javax.swing.JLabel tate4;
    private javax.swing.JLabel tate5;
    private javax.swing.JTextArea tweet1;
    private javax.swing.JTextArea tweet2;
    private javax.swing.JTextArea tweet3;
    private javax.swing.JTextArea tweet4;
    private javax.swing.JTextArea tweet5;
    private javax.swing.JLabel user1;
    private javax.swing.JLabel user2;
    private javax.swing.JLabel user3;
    private javax.swing.JLabel user4;
    private javax.swing.JLabel user5;
    private javax.swing.JPanel userPhoto1;
    private javax.swing.JPanel userPhoto2;
    private javax.swing.JPanel userPhoto3;
    private javax.swing.JPanel userPhoto4;
    private javax.swing.JPanel userPhoto5;
    private javax.swing.JLabel username2;
    private javax.swing.JLabel username3;
    private javax.swing.JLabel username4;
    private javax.swing.JLabel username5;
    private javax.swing.JLabel username6;
    // End of variables declaration//GEN-END:variables
}