Wednesday, April 30, 2008

Create java Classes Dynamically and Run It

This program needs a com.sun.tools.javac.Main.compile for that u need to add the tools.jar file to your class path..


RunIt.java


/** *

* @author SJoshi

*/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

import java.lang.reflect.*;


public class RunIt extends JFrame {

JPanel contentPane;

JScrollPane jScrollPane1 = new JScrollPane();

JTextArea source = new JTextArea();

JPanel jPanel1 = new JPanel();

JLabel classNameLabel = new JLabel("Class Name");

GridLayout gridLayout1 = new GridLayout(2,1);

JTextField className = new JTextField();

JButton compile = new JButton("Go");

Font boldFont = new java.awt.Font("SansSerif", 1, 11);


public RunIt() {

super("Editor");

setDefaultCloseOperation(EXIT_ON_CLOSE);

contentPane = (JPanel) this.getContentPane();

this.setSize(400, 300);

classNameLabel.setFont(boldFont);

jPanel1.setLayout(gridLayout1);

compile.setFont(boldFont);

compile.setForeground(Color.black);

compile.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try {

doCompile();

} catch (Exception ex) {

System.err.println(

"Error during save/compile: " + ex);

ex.printStackTrace();

}

}

});

contentPane.add(jScrollPane1, BorderLayout.CENTER);

contentPane.add(jPanel1, BorderLayout.NORTH);

jPanel1.add(classNameLabel);

jPanel1.add(className);

jScrollPane1.getViewport().add(source);

contentPane.add(compile, BorderLayout.SOUTH);

}

public static void main(String[] args) {

Frame frame = new RunIt();

// Center screen

Dimension screenSize =

Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = frame.getSize();

if (frameSize.height > screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width > screenSize.width) {

frameSize.width = screenSize.width;

}

frame.setLocation(

(screenSize.width - frameSize.width) / 2,

(screenSize.height - frameSize.height) / 2);

frame.show();

}

private void doCompile() throws Exception {

// write source to file

String sourceFile = className.getText() + ".java";


FileWriter fw = new FileWriter(sourceFile);

fw.write(source.getText());

fw.close();

// compile it

int compileReturnCode =

com.sun.tools.javac.Main.compile(

new String[] {sourceFile});

if (compileReturnCode == 0) {

// run it

Object objectParameters[] = {new String[]{}};

Class classParameters[] =

{objectParameters[0].getClass()};

Class aClass =

Class.forName(className.getText());

Object instance = aClass.newInstance();

Method theMethod = aClass.getDeclaredMethod(

"main", classParameters);

theMethod.invoke(instance, objectParameters);

}

}

}


Sample Code for :

public class Sample {

public static void main(String args[]) {

System.out.println(new java.util.Date());

}

}

Output Window :




Reference Link :


Thanks & Regards

Joshi Shirin

Monday, April 28, 2008

File Searching with JAVA

FileSearch.java


 

package com.joshi;


 

import java.awt.Container;

import java.awt.Dimension;

import java.awt.Insets;

import java.awt.Point;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.io.File;

import javax.swing.ImageIcon;

import javax.swing.JApplet;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JScrollPane;

import javax.swing.JTextField;

import javax.swing.ListSelectionModel;


 

/** *

* @author SJoshi

*/

public class FileSearch extends JApplet implements ActionListener {

SearchThread sc;

@Override

public void init() {

FileSearch fs = new FileSearch();

}

public FileSearch() {

initComponents();

lblProcess.setVisible(false);

this.setSize(450, 350);

this.setVisible(true);

// this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

initListener();

btnStop.setEnabled(false);


 

}

private void initComponents() {

// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents

// Generated using JFormDesigner Evaluation license - Shirin Joshi

txtSearch = new JTextField();

btnSearch = new JButton();

lblEnterSearch = new JLabel();

spFileList = new JScrollPane();

lstFileList = new CustomJList();

lblSearch = new JLabel();

lblProcess = new JLabel();

btnStop = new JButton();

lblCurrentScan = new JLabel();

lblScan = new JLabel();


 

//======== this ========

// setTitle("Search");

Container contentPane = getContentPane();

contentPane.setLayout(null);

contentPane.add(txtSearch);

txtSearch.setBounds(115, 30, 190, txtSearch.getPreferredSize().height);


 

//---- btnSearch ----

btnSearch.setText("Search");

contentPane.add(btnSearch);

btnSearch.setBounds(310, 30, btnSearch.getPreferredSize().width, 20);


 

//---- lblEnterSearch ----

lblEnterSearch.setText("Enter File Name:");

contentPane.add(lblEnterSearch);

lblEnterSearch.setBounds(15, 30, lblEnterSearch.getPreferredSize().width, 20);


 

//======== spFileList ========

{


 

//---- lstFileList ----

lstFileList.setVisibleRowCount(10);

lstFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

spFileList.setViewportView(lstFileList);

}

contentPane.add(spFileList);

spFileList.setBounds(15, 100, 350, spFileList.getPreferredSize().height);


 

//---- lblSearch ----

lblSearch.setText("Search Result :");

contentPane.add(lblSearch);

lblSearch.setBounds(new Rectangle(new Point(15, 70), lblSearch.getPreferredSize()));


 

//---- lblProcess ----

lblProcess.setIcon(new ImageIcon(getClass().getResource("resource/ajax-loader.gif")));

contentPane.add(lblProcess);

lblProcess.setBounds(320, 65, 32, 32);


 

//---- btnStop ----

btnStop.setText("Stop");

contentPane.add(btnStop);

btnStop.setBounds(new Rectangle(new Point(240, 70), btnStop.getPreferredSize()));


 

//---- lblScan ----

lblScan.setText("Scan: ");

contentPane.add(lblScan);

lblScan.setBounds(10, 275, 80, 20);


 

contentPane.add(lblCurrentScan);

lblCurrentScan.setBounds(60, 275, 305, 20);


 

{ // compute preferred size

Dimension preferredSize = new Dimension();

for (int i = 0; i < contentPane.getComponentCount(); i++) {

Rectangle bounds = contentPane.getComponent(i).getBounds();

preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);

preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);

}

Insets insets = contentPane.getInsets();

preferredSize.width += insets.right;

preferredSize.height += insets.bottom;

contentPane.setMinimumSize(preferredSize);

contentPane.setPreferredSize(preferredSize);

}

// pack();

// setLocationRelativeTo(getOwner());

// JFormDesigner - End of component initialization //GEN-END:initComponents

}


 

// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables

// Generated using JFormDesigner Evaluation license - Shirin Joshi

public JTextField txtSearch;

private JButton btnSearch;

private JLabel lblEnterSearch;

private JScrollPane spFileList;

public CustomJList lstFileList;

private JLabel lblSearch;

public JLabel lblProcess;

private JButton btnStop;

public JLabel lblCurrentScan;

private JLabel lblScan;

public boolean isStopSearch = false;


 

private void initListener() {

btnSearch.setActionCommand("Search");

btnSearch.addActionListener(this);

btnStop.setActionCommand("Stop");

btnStop.addActionListener(this);


 

lstFileList.addMouseListener(new MouseAdapter() {


 

@Override

public void mouseClicked(MouseEvent e) {

if(e.getButton()==MouseEvent.BUTTON1 && e.getClickCount()==2) {

showFileInformation();

}

}

});

}

private void showFileInformation() {

String file = lstFileList.getSelectedValue().toString();


 

File clickFile = new File(file);

StringBuffer sbFileInfo = new StringBuffer();

sbFileInfo.append("\nFile Name : ").append(clickFile.getName());

sbFileInfo.append("\nRead Only : ").append(!clickFile.canRead());

JOptionPane.showMessageDialog(this,sbFileInfo.toString());

}


 

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equalsIgnoreCase("Search")) {

if (txtSearch.getText().trim().length() != 0) {

btnSearch.setEnabled(false);

lblProcess.setVisible(true);

isStopSearch = false;

lstFileList.getListModel().removeAllElements();

lblCurrentScan.setText("");

sc = new SearchThread(this);

sc.start();

btnStop.setEnabled(true);

} else {

JOptionPane.showMessageDialog(this, "Please Provide Search File Name", "File Name Error..", JOptionPane.ERROR_MESSAGE);

}

} else if (e.getActionCommand().equalsIgnoreCase("Stop")) {

sc.stop();

lblProcess.setVisible(false);

lblCurrentScan.setText("");

isStopSearch = true;

btnSearch.setEnabled(true);

btnStop.setEnabled(true);

}

}

}


 

SearchThread.java


 

package com.joshi

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import javax.swing.JOptionPane;


 

/**

*

* @author SJoshi

*/

public class SearchThread extends Thread {


 

File[] roots = File.listRoots();

FileSearch fs;


 

public SearchThread(FileSearch p_fs) {

fs = p_fs;

}//SearchThread

@Override

public void run() {

List list = new ArrayList();

for (int i = 0; i < roots.length; i++) {

try {

if (fs.isStopSearch) {

break;

}//if

try {

scan(roots[i], list);

fs.lblProcess.setVisible(false);

fs.lblCurrentScan.setText("");

} //try

catch (IOException ex) {

JOptionPane.showMessageDialog(fs, ex, "Searching Error..", JOptionPane.ERROR_MESSAGE);

}//catch

sleep(100);

} //try

catch (InterruptedException ex) {

JOptionPane.showMessageDialog(fs, ex, "Searching Error..", JOptionPane.ERROR_MESSAGE);

}//catch

}//for

}//run

public void scan(File path,

List list) throws IOException {

// Get filtered files in the current path

File[] files = path.listFiles();

//path.listFiles(filter);

// Process each filtered entry

for (int i = 0; i < files.length; i++) {

// recurse if the entry is a directory

try {

fs.lblCurrentScan.setText(files[i].getPath());

if (files[i].isDirectory()) {

scan(files[i], list);//, filter);

} else {

// add the filtered file to the list

if (files[i].getName().equalsIgnoreCase(fs.txtSearch.getText())) {

fs.lstFileList.addElement(files[i].getCanonicalPath());

list.add(files[i]);

}

}

} catch (NullPointerException ne) {

System.out.println("Null Pointer.." + files[i]);

continue;

}

} // for

} // scan

}

Tuesday, April 22, 2008

TIC TAC TOE Version 1 – Standalone Java

import com.sun.awt.AWTUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import org.jvnet.substance.painter.GlassGradientPainter;
import org.jvnet.substance.skin.SubstanceBusinessBlueSteelLookAndFeel;

/**
 * @author Shirin Joshi
 */
public class TicTacToe extends JFrame implements ActionListener {

    int turn = 0;
    int count = 0;

    public TicTacToe() {

        initComponents();
        initListner();

    }

    public static void main(String a[]) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);

        try {
            SubstanceBusinessBlueSteelLookAndFeel.setCurrentGradientPainter(new GlassGradientPainter());
            UIManager.setLookAndFeel(new SubstanceBusinessBlueSteelLookAndFeel());
        } catch (Exception exception) {
            System.out.println("L&amp;F not set" + exception);
        }
        TicTacToe objTicTacToe = new TicTacToe();
        objTicTacToe.setDefaultCloseOperation(EXIT_ON_CLOSE);
        objTicTacToe.setSize(170, 180);
        objTicTacToe.setResizable(false);
        objTicTacToe.setVisible(true);

    // AWTUtilities.setWindowOpacity(objTicTacToe, 0.3F);
    // AWTUtilities.setWindowOpacity(JOptionPane.getRootFrame(),0.3F);
    }

    private void checkWiningCondition() {
        // Check is Pressed the Button or not

        // Check First Line Horizontal Line
        if (!btn_0.isEnabled() &amp;&amp; !btn_1.isEnabled() &amp;&amp; !btn_2.isEnabled()) {
            if (btn_0.getText().equalsIgnoreCase(btn_1.getText()) &amp;&amp;
                    btn_1.getText().equalsIgnoreCase(btn_2.getText())) {
                setEnableAll(false);
                JOptionPane.showMessageDialog(this, "Winner Is 1 : " + btn_0.getText());
                setWinnerBold(btn_0, btn_1, btn_2);
                return;
            }
        }

        // Check 2nd Line Horizontal Line
        if (!btn_3.isEnabled() &amp;&amp; !btn_4.isEnabled() &amp;&amp; !btn_5.isEnabled()) {
            if (btn_3.getText().equalsIgnoreCase(btn_4.getText()) &amp;&amp;
                    btn_4.getText().equalsIgnoreCase(btn_5.getText())) {
                setEnableAll(false);
                JOptionPane.showMessageDialog(this, "Winner Is  2 : " + btn_3.getText());
                setWinnerBold(btn_3, btn_4, btn_5);
                return;
            }
        }

        // Check 3nd Line Horizontal Line
        if (!btn_6.isEnabled() &amp;&amp; !btn_7.isEnabled() &amp;&amp; !btn_8.isEnabled()) {
            if (btn_6.getText().equalsIgnoreCase(btn_7.getText()) &amp;&amp;
                    btn_7.getText().equalsIgnoreCase(btn_8.getText())) {
                setEnableAll(false);
                JOptionPane.showMessageDialog(this, "Winner Is 3 : " + btn_6.getText());
                setWinnerBold(btn_6, btn_7, btn_8);
                return;

            }
        }

        // Check First Line Verticle Line
        if (!btn_0.isEnabled() &amp;&amp; !btn_3.isEnabled() &amp;&amp; !btn_6.isEnabled()) {
            if (btn_0.getText().equalsIgnoreCase(btn_3.getText()) &amp;&amp;
                    btn_3.getText().equalsIgnoreCase(btn_6.getText())) {
                setEnableAll(false);
                JOptionPane.showMessageDialog(this, "Winner Is 4 : " + btn_0.getText());
                setWinnerBold(btn_0, btn_3, btn_6);
                return;
            }
        }
        // Check 2nd Line Verticle Line
        if (!btn_1.isEnabled() &amp;&amp; !btn_4.isEnabled() &amp;&amp; !btn_7.isEnabled()) {
            if (btn_2.getText().equalsIgnoreCase(btn_4.getText()) &amp;&amp;
                    btn_4.getText().equalsIgnoreCase(btn_7.getText())) {
                setEnableAll(false);
                JOptionPane.showMessageDialog(this, "Winner Is 5 : " + btn_1.getText());
                setWinnerBold(btn_1, btn_4, btn_7);
                return;
            }
        }

        // Check 3nd Line Verticle Line
        if (!btn_2.isEnabled() &amp;&amp; !btn_5.isEnabled() &amp;&amp; !btn_8.isEnabled()) {
            if (btn_2.getText().equalsIgnoreCase(btn_5.getText()) &amp;&amp;
                    btn_5.getText().equalsIgnoreCase(btn_8.getText())) {
                setEnableAll(false);
                JOptionPane.showMessageDialog(this, "Winner Is 6 : " + btn_2.getText());
                setWinnerBold(btn_2, btn_5, btn_8);
                return;
            }
        }

        // Check Diagnol \
        if (!btn_0.isEnabled() &amp;&amp; !btn_4.isEnabled() &amp;&amp; !btn_8.isEnabled()) {
            if (btn_0.getText().equalsIgnoreCase(btn_4.getText()) &amp;&amp;
                    btn_4.getText().equalsIgnoreCase(btn_8.getText())) {
                setEnableAll(false);
                JOptionPane.showMessageDialog(this, "Winner Is 7 : " + btn_0.getText());
                setWinnerBold(btn_0, btn_4, btn_8);
                return;

            }
        }

        // Check Diagnol /
        if (!btn_2.isEnabled() &amp;&amp; !btn_4.isEnabled() &amp;&amp; !btn_6.isEnabled()) {
            if (btn_2.getText().equalsIgnoreCase(btn_4.getText()) &amp;&amp;
                    btn_4.getText().equalsIgnoreCase(btn_6.getText())) {
                JOptionPane.showMessageDialog(this, "Winner Is 8 : " + btn_2.getText());
                setEnableAll(false);
                setWinnerBold(btn_2, btn_4, btn_6);
                return;
            }
        }

        if (count == 9) {
            if (!btnReset.isEnabled()) {
                JOptionPane.showMessageDialog(this, "Draw Match...");
                btnReset.setEnabled(true);
                return;
            }
        }
    }

    private void clearAll() {
        btn_0.setText("");
        btn_1.setText("");
        btn_2.setText("");
        btn_3.setText("");
        btn_4.setText("");
        btn_5.setText("");
        btn_6.setText("");
        btn_7.setText("");
        btn_8.setText("");
        turn = 0;
        count = 0;
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - Shirin Joshi
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        btn_0 = new JButton();
        btn_1 = new JButton();
        btn_2 = new JButton();
        btn_3 = new JButton();
        btn_4 = new JButton();
        btn_5 = new JButton();
        btn_6 = new JButton();
        btn_7 = new JButton();
        btn_8 = new JButton();
        buttonBar = new JPanel();
        btnReset = new JButton();
        cancelButton = new JButton();

        //======== this ========
        setTitle("TicTacToe");
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));

            dialogPane.setLayout(new BorderLayout());

            //======== contentPanel ========
            {
                contentPanel.setLayout(new GridLayout(3, 3));
                contentPanel.add(btn_0);
                contentPanel.add(btn_1);
                contentPanel.add(btn_2);
                contentPanel.add(btn_3);
                contentPanel.add(btn_4);
                contentPanel.add(btn_5);
                contentPanel.add(btn_6);
                contentPanel.add(btn_7);
                contentPanel.add(btn_8);
            }
            dialogPane.add(contentPanel, BorderLayout.CENTER);

            //======== buttonBar ========
            {
                buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
                buttonBar.setLayout(new GridBagLayout());
                ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[]{53, 46, 40};
                ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[]{1.0, 0.0, 0.0};

                //---- btnReset ----
                btnReset.setText("Reset");
                btnReset.setEnabled(false);
                buttonBar.add(btnReset, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 3), 0, 0));

                //---- cancelButton ----
                cancelButton.setText("Cancel");
                buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));
            }
            dialogPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        //pack();
        setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - Shirin Joshi
    private JPanel dialogPane;
    private JPanel contentPanel;
    private JButton btn_0;
    private JButton btn_1;
    private JButton btn_2;
    private JButton btn_3;
    private JButton btn_4;
    private JButton btn_5;
    private JButton btn_6;
    private JButton btn_7;
    private JButton btn_8;
    private JPanel buttonBar;
    private JButton btnReset;
    private JButton cancelButton;

    public void actionPerformed(ActionEvent e) {

        if (e.getActionCommand().equalsIgnoreCase("K")) {
            setEnableAll(true);
            clearAll();
        } else {
            JButton Clicked = (JButton) e.getSource();
            if (Clicked.getText().trim().length() == 0) {
                Clicked.setEnabled(false);

                Clicked.setText(turn == 0 ? "0" : "X");

                turn = turn == 0 ? 1 : 0;
                count++;

                // Check Condition always occured after 4th Click..
                if (count &gt; 3) {
                    checkWiningCondition();
                }

            }
        }
    }

    private void initListner() {
        btn_0.addActionListener(this);
        btn_1.addActionListener(this);
        btn_2.addActionListener(this);
        btn_3.addActionListener(this);
        btn_4.addActionListener(this);
        btn_5.addActionListener(this);
        btn_6.addActionListener(this);
        btn_7.addActionListener(this);
        btn_8.addActionListener(this);

        btnReset.setActionCommand("K");
        btnReset.addActionListener(this);
    }

    private void setEnableAll(boolean p_isEnable) {
        btn_0.setEnabled(p_isEnable);
        btn_1.setEnabled(p_isEnable);
        btn_2.setEnabled(p_isEnable);
        btn_3.setEnabled(p_isEnable);
        btn_4.setEnabled(p_isEnable);
        btn_5.setEnabled(p_isEnable);
        btn_6.setEnabled(p_isEnable);
        btn_7.setEnabled(p_isEnable);
        btn_8.setEnabled(p_isEnable);



        if (p_isEnable) {
            btn_0.setForeground(btnReset.getForeground());
            btn_1.setForeground(btnReset.getForeground());
            btn_2.setForeground(btnReset.getForeground());
            btn_3.setForeground(btnReset.getForeground());
            
            btn_4.setForeground(btnReset.getForeground());
            btn_5.setForeground(btnReset.getForeground());
            btn_6.setForeground(btnReset.getForeground());
            btn_7.setForeground(btnReset.getForeground());
            btn_8.setForeground(btnReset.getForeground());
        }

        btnReset.setEnabled(!p_isEnable);
    }

    private void setWinnerBold(JButton btn_0, JButton btn_1, JButton btn_2) {
        btn_0.setForeground(Color.blue);
        btn_1.setForeground(Color.blue);
        btn_2.setForeground(Color.blue);
    }
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}

Friday, April 18, 2008

Google Type Paging :

Need to change as per requirement and Use the loop at your JSP page with starting from startPage to endPage and if pageIndex will be your current Page


 

import java.util.List;

import javax.persistence.Query;


 

public class Page {

    private int startPage;

    private int endPage;

    private double count;

    private static int vellySize = 10;

    private List<?> results;

private int pageIndex;

    private int pageSize;

    private int lastPageIndex;


 

    public Page() {

    }


 

    public Page(Query selectQuery, Query countQuery, int index, int size) {

        if (index <= 0)

            index = 1;

        // If page index is not zero based

        pageIndex = index;

        // Make sure that the page size is within its limits

        pageSize = size;

        // Get the total number of items in the database.

        // If count was of type Long you would lose the precision when

        // calling Math.ceil() --> count is declared as double

        count = (Long) countQuery.getSingleResult();

        if (count <= 0) {

            // You need to handle this situation. One option is to throw an

            // exception or display an error message using FacesMessages.

            return;

        }


 

        // calculate the number of pages and set last page index

        lastPageIndex = (int) Math.ceil(count / pageSize);


 

        // make sure that the page index in not out of scope

        if (pageIndex > lastPageIndex)

            pageIndex = 1;

        results = selectQuery.setMaxResults(pageSize).setFirstResult(

                pageSize * (pageIndex - 1)).getResultList();

        setEndPage();

        setStartPage();

    }


 

    public int getStartPage() {

        return startPage;

    }

    public int getEndPage() {

        return endPage;

    }

    public void setStartPage() {

        int fst = (vellySize / 2);


 

        if (pageIndex - fst <= 0)

            this.startPage = 1;

        else

            startPage = pageIndex - fst;

    }

    public void setEndPage() {

        int lst = (vellySize / 2);


 

        if (pageIndex + lst > (int) Math.ceil(count / pageSize))

            endPage = (int) Math.ceil(count / pageSize);

        else

            endPage = pageIndex + lst;

    }


 

    public List getResults() {

        return results;

    }


 

    public int getPageIndex() {

        return pageIndex;

    }


 

    public int getLastPageIndex() {

        return lastPageIndex;

    }


 

    public int getPageSize() {

        return pageSize;

    }


 

    /**

     * This method used to set the page index after the delete operation. If the

     * current page having only single record than after the delete operation

     * the user will forwarded to previous page.

     *

     * i.e. if currentPage Index is 2 than user will forwarded to 1 page if and

     * only if the page having no records after delete operation. If pageIndex

     * less than 0 it will set to 1 by default.

     *

     */

public void setPageAfterDelete() {

        // Set the page Index by checking the result size. If it is Zero means

        // user deleted the last record than this will set to previous page.

        if (getResults().size() == 0)

            pageIndex--;

        // If pageIndex < 0 than need to set it to 1st page.

        if (pageIndex < 0)

            pageIndex = 1;

    }

}

Tuesday, April 15, 2008

EAR deployment for Seam + JSF using Ant File

Need to change the projectName.ear file.

And create new folder at your root with Extralib having jsf-api.jar file.


<project
name="PROJECTNAME"
default="dist"
basedir=".">

<description>

PROJECTNAME Build Script


</description>

<!-- Please Change this property As per your JBOSS_HOME -->

<property
name="jboss.home "
location="C:\Program Files\Java\Jboss4.2.2"
/>

<!-- set global properties for this build -->

<property
name="src"
location="src"
/>

<property
name="project.ear"
location="../projectName.ear"
/>

<property
name="project.ejb"
location="../projectName-ejb"
/>

<property
name="project.web"
location="../projectName-web"
/>

<!-- Starting Cleaning and Folder Generation -->

<target
name="init"
depends="clean">

<!-- Create the time stamp -->

<tstamp
/>

<!-- Create the project.ear directory structure used by compile -->

<mkdir
dir="${project.ear}"
/>

<mkdir
dir="${project.ear}/projectName-ejb.jar"
/>

<mkdir
dir="${project.ear}/projectName-web.war"
/>

<mkdir
dir="${project.ejb}/classes"
/>

<mkdir
dir="${project.web}/WebRoot/WEB-INF/classes"
/>

</target>

<target
name="clean"
description="clean up">

<!-- Delete the ${project.ear} and ${project.ejb}/classes and ${project.web}/WebRoot/WEB-INF/classes directory trees -->

<delete
dir="${project.ear}"
/>

<delete
dir="${project.ejb}/classes"
/>

<delete
dir="${project.web}/WebRoot/WEB-INF/classes"
/>

</target>

<!-- CLASS Library for PROJECT -->

<path
id="project.class.path">

<fileset
dir="${jboss.home }/server/default/lib">

<include
name="*.jar"
/>

</fileset>

<fileset
dir="${basedir}/lib">

<include
name="*.jar"
/>

</fileset>

<fileset
dir="../Extralib">

<include
name="*.jar"
/>

</fileset>

</path>

<!-- EJB Project Compilation and moving to EAR -->

<target
name="ejb"
description="compile the EJB ">

<!-- Compile the java code from ${src} -->

<javac
srcdir="${project.ejb}/src"
destdir="${project.ejb}/classes">

<classpath
refid="project.class.path"
/>

</javac>

<copy
todir="${project.ear}/projectName-ejb.jar">

<fileset
dir="${project.ejb}/classes"
/>

<fileset
dir="${project.ejb}/src">

<exclude
name="**/*.java"
/>

<exclude
name="**/*.svn"
/>

</fileset>

</copy>

</target>

<!-- WEB Project Compilation and moving to EAR -->

<target
name="web"
description="compile the WEB ">

<!-- Compile the java code from ${src}} -->

<javac
srcdir="${project.web}/src"
destdir="${project.web}/WebRoot/WEB-INF/classes">

<classpath
refid="project.class.path"
/>

</javac>

<copy
todir="${project.web}/WebRoot/WEB-INF/classes">

<fileset
dir="${project.web}/src">

<exclude
name="**/*.svn"
/>

<exclude
name="**/*.java"
/>

<include
name="**/*.properties"
/>

</fileset>

</copy>

<copy
todir="${project.ear}/projectName-web.war">

<fileset
dir="${project.web}/WebRoot">

<exclude
name="**/*.svn"
/>

</fileset>

</copy>

</target>

<target
name="copy"
description="copy the files">

<copy
todir="${project.ear}/lib">

<fileset
dir="${basedir}/lib"
excludes="**/*.svn , **/jsf*.jar , **/jstl*.jar, **/javaee.jar"
/>

</copy>

<copy
todir="${project.ear}/META-INF">

<fileset
dir="${basedir}/META-INF"
excludes="**/*.svn"
/>

</copy>

</target>

<target
name="dist"
depends="init,ejb,web,copy"
description="generate the distribution">

<!-- Copy Everything and deploy the project to jboss.home -->

<copy
todir="${jboss.home }\server\default\deploy\projectName.ear"
overwrite="true">

<fileset
dir="${project.ear}"
/>

</copy>

<echo>==================PROJECT Deployment Task Completed..=========================</echo>

</target>

</project>

Friday, April 11, 2008

Splash Screen with JAR using NetBeans or Eclipse IDE

How to set Splash screen for JAR file ?. After JDK 1.5.0 the problem of Splash Screen solved bye introducing two ways to display Splash Screen. You can find more about Splash Screen on SUN JAVA SITE.

But here a little guidance.

When you create a JAR file you need to add following line in your Manifest File.
 SplashScreen-Image: filename.gif

In NetBeans or Eclipse you can find Manifest file easily and add above line.

Also need to add filename.gif to your src folder

SRC
filename.gif (at root of source folder)
com (package)
joshi (package in side com)


So, when u jar the Application the gif image will be added as:

JAR
filename.gif (at root of source folder)
com (package)
joshi (package in side com)

Now just run the JAR file and you will get splash Screen.

Thanks & Regards,






Tuesday, April 8, 2008

Serial Key, Activation Key,

Hi,

***************************************************

Macro media Fireworks Serial Key :
***************************************************
WPD700-55705-37394-92115 - This will work..
WPD700-55509-39094-59108
WPD700-53903-19494-46683


***************************************************
My Eclipse 6.0.1
***************************************************

=========================================
Subscriber: administrator
Subscription Code: nLR7ZL-655342-54657656405281154
=========================================

: After registration:
Subscriber: administrator
Product ID: E2MY (MyEclipse Standard Subscription)
License version: 1.0
Full Maintenance Included
Subscription expiration date (YYYYMMDD): 20091021
Number of licenses: 897

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


: Below the 6.0 GA / GA M1 and 5.5 versions of the "registration" and "registration key," "break" to everyone:
Subscriber:
Subscriber Code: jLR8ZC-655355-5450765457039125
Subscriber: Or Subscriber:
Subscriber Code: jLR7ZL-655355-5450755330522962

: Apply to the early 5.5 version of the M2:
Subscriber:
Subscriber Code: jLR8ZC-956-55-5467865833584547

: Apply to the early 5.1.1 GA and 5.5 versions of the M1:
Subscriber:
Subscriber Code: jLR8ZC-444-55-4467865481680090

: After the success of the registration will be found:
Subscriber:
Product ID: E3MP (MyEclipse Professional Subscription)
License version: xx
Full Maintenance Included
Subscription expiration date (YYYYMMDD): 20090520
Number of licenses: 800

***************************************************
MyEclipse 5.5 subscription Id
***************************************************

ID : brd[bond no.]
Key : oLR7ZL-752556-545373-6179839171

ID : myeclipse5.5
Key : zLR8ZC-850444-5453675708725833

***************************************************
Tuneup Utilities 2008
***************************************************

Serial desined by http://topdownloads.ucoz.ru/:
Name: HotSoft.Net.Ru
Company: HotSoft.Net.Ru
Key: AQ21M-XRS43-9FRX3-QS8AM-DX1YY-EPASQ

this registration works pecfect
Name: pupu
Org: ventura
serial:M65XP43YP1EEP63PLAPD4KN8P6HAVU


Name : Kai
Company : Sweet
Serial : UN3W7-EC52F-7XRTC-4XXK2-Q7FAD-UHAX2

Name : Kai
Company : Sweet
Serial : UN3W7-EC52F-7XRTC-4XXK2-Q7FAD-UHAX2

http://www.torrentz.com/28c1e315b2d929f5e147b75b87f29540cba14a0b
http://www.leechers.info/tuneup-utilities-2008-707992

***************************************************
***************************************************

Contributors