Developing Status bar component in java Swing




Java does not have a built-in StatusBar class in Swing. You need to create your own status bar.The following program is developed for displaying Date and time in Status bar ..This program helps you implement dynamic Status bar related application .

Java Program

// Comment


package up2java.com.code;

/**
 *
 * @author www.up2java.com
 */
   
import java.awt.event.*; 
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;  
public class ClockLabel extends JLabel implements ActionListener {
 String date1;
 StringBuffer css;
  public ClockLabel() { 
       super("" + new SimpleDateFormat("E dd-MMM-yyyy    hh:mm:ss a").format(new Date()));
       Timer t = new Timer(1000,this);
       t.start(); 
         }  
  public void actionPerformed(ActionEvent ae) { 
         setText("" +new SimpleDateFormat("E dd-MMM-yyyy    hh:mm:ss a ").format(new Date()));  
        } 
} 
This program act as a timer to display the date and time with specific time delay .Due to this use will be able to see the date time in the status bar..
// Comment



package up2java.com.code;

/**
 *
 * @author up2java.com
 */
public class StatusBarSample extends javax.swing.JFrame {
ClockLabel clock = new ClockLabel();
    /**
     * Creates new form StatusBarSample
     */
    public StatusBarSample() {
        initComponents();
        jToolBar1.add(clock);
    }

    /**
     * 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")
    // 
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("UP2JAVA.COM");

        jToolBar1.setRollover(true);
        jToolBar1.setName("jt");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 275, Short.MAX_VALUE)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// 

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(StatusBarSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StatusBarSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StatusBarSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StatusBarSample.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new StatusBarSample().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration
}

This java program is responsible for frame which contain jToolBar as a status bar

 ClockLabel clock = new ClockLabel(); 
 Above line creates object clock which contains timer to display date and time.

jToolBar1.add(clock);
Here cloak object has been added to the jtoolbar component by the jToolbar now act as a Status bar.For running this program we have used Net beans..

                                                                            Output

Unknown Web Developer

Java Program to Import data from textfile to mysql Database


Mysql Posses the functionality  to import data from txt,csv files..Following program helps to import sample text data in to table in database.

Sample data need to be imported


temp.txt file 
--------------


"1 string"      100

"2 string"      102
"3 string"      104
"4 string"      106
  

Table Structure



CREATE TABLE testtable

(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

text varchar(45) NOT NULL,
price integer not null);

Java Program

 
// Comment

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class automateImport
{
    public static void main(String[] args) 
    {
        DBase db = new DBase();
        Connection conn = db.connect(
    "jdbc:mysql://localhost:3306/test","root","caspian");
        db.importData(conn,args[0]);
    }

}

class DBase
{
    public DBase()
    {
    }

    public Connection connect(String db_connect_str, 
  String db_userid, String db_password)
    {
        Connection conn;
        try 
        {
            Class.forName(  
    "com.mysql.jdbc.Driver").newInstance();

            conn = DriverManager.getConnection(db_connect_str, 
    db_userid, db_password);
        
        }
        catch(Exception e)
        {
            e.printStackTrace();
            conn = null;
        }

        return conn;    
    }
    
    public void importData(Connection conn,String filename)
    {
        Statement stmt;
        String query;

        try
        {
            stmt = conn.createStatement(
    ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_UPDATABLE);

            query = "LOAD DATA INFILE '"+filename+
    "' INTO TABLE testtable (text,price);";

            stmt.executeUpdate(query);
                
        }
        catch(Exception e)
        {
            e.printStackTrace();
            stmt = null;
        }
    }
}; 


Unknown Web Developer

Java Program to export data from msql database to CSV file


Due to this program its possible to export data from mysql database to cvs file using java code...
// Comment


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class automateExport {
    public static void main(String[] args) {
        DBase db = new DBase();
        Connection conn = db.connect(
                "jdbc:mysql://localhost:3306/test","root","caspian");
        
        if (args.length != 1) {
            System.out.println(
                    "Usage: java automateExport [outputfile path] ");
            return;
        }
        db.exportData(conn,args[0]);
    }
    
}

class DBase {
    public DBase() {
    }
    
    public Connection connect(String db_connect_str, 
            String db_userid, String db_password) {
        Connection conn;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(db_connect_str,
                    db_userid, db_password);
            
        } catch(Exception e) {
            e.printStackTrace();
            conn = null;
        }
        return conn;
    }
    
    public void exportData(Connection conn,String filename) {
        Statement stmt;
        String query;
        try {
            stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_UPDATABLE);
            
            //For comma separated file
            query = "SELECT id,text,price into OUTFILE  '"+filename+
                    "' FIELDS TERMINATED BY ',' FROM testtable t";
            stmt.executeQuery(query);
            
        } catch(Exception e) {
            e.printStackTrace();
            stmt = null;
        }
    }
};


Unknown Web Developer

Java Programming IDE App for Android


 

           
Now a days Android smart phones has been  playing a vital roles in market.. Lot of user thinks of how to compile and execute Java program…. Sand is an integrated development environment(IDE) for Java in Android platform .Due to this user shall be able to compile and execute the java programs.. Sand has a very powerful Java editor inside, keywords highlighting for Java, showing line number, undo/redo feature, automatically close are all supported. Sand has a complete Java compiler, Java projects can be built by Sand. Sand can run Java programs, output and input are both supported by Console of Sand
In a word, Sand turns your Android device into a real development tool.



Features of Java programming Ide in android.

A powerful Java editor. Keywords highlighting, showing line number, undo/redo feature, automatically close, automatically indentation are all supported

A complete Java compiler. Support from Java 1.3 to Java 1.6.(Android doesn't support Java 1.7)

Bluetooth keyboard supported

A Console which is in charge of Input from users and Output from compiler and Java programs

Import external JARs into Java project

Import your Favorite RT.jar


                          
You can download rt.jar(1.6.0_24) from the project web page:
download rt.jar


Cons

The memory Sand can use is limited. When you compile and run some very large Java project, Sand may become a little bit slow. It depends on the hardware of your device. 
 
Unknown Web Developer

Installing software’s in BOSS for government Laptop.




 In order to install your favorite software in BOSS linux which is preloaded in tamilnadu government laptop use  Synaptic Package Manager in boss. The Synaptic Package Manager enables you to install and manage the software on your system. To open Synaptic Package manager Click on System -> Administration -> Synaptic Package Manager

Installing a package/application using Synaptic Package Manager

1. click on search to find a package , a dialog appears on the screen type the package name in it and click on search. If that package is found it will get displayed on the screen.

2. Right click on that package and select mark for installation.

3. You can mark all the packages that you need and finally click on apply button.

The packages that are marked for installation are downloaded and installed from the boss repository onto your system.

Removing a package/application using Synaptic Package Manager

To remove a package right click on it and select "Mark for Removal" and then choose apply.

If you want to remove the package along with the configuration files right click and select "Mark for complete removal" This removes all the unwanted packages.

Installing package/application through shell prompt

First connect to the boss repository.

1. Open the sources.list file (ie) Run the command

                    vi /etc/apt/sources.list

2. Find out whether these lines are there in that file

                    deb http://packages.bosslinux.in/boss savir main contrib non-free

                    deb-src http://packages.bosslinux.in/boss savir main contrib non-free

If these lines are not present then you must include these lines into your file and quit with saving. Comment all the unnecessary lines. Lines that
start with '#' symbol means are commented.

3.Once you have connected to the BOSS repository run this command

                    apt-get update

This command is used to resynchronize the package index files from their sources. The indexes of available packages are fetched from the locations specified in /etc/apt/sources.list.

4. You can search packages by running the command

                    apt-cache search package name

It searches the package names and the descriptions for an occurrence of the regular expression and prints out the package name and the short description, including virtual package names.

5. From the description provided find out the apt package you need and run the command

                    apt-get install package name

Using this command the package , all dependent packages required by the packages specified for installation will be retrieved and installed.The /etc/apt/sources.list file is used to locate the desired packages.

Removing packages from shell prompt

To remove unwanted packages run the command

                    apt-get --purge remove packagename


To remove the package along with dependencies run the command

                    apt-get autoremove

Source  Retrieved from "http://wiki.bosslinux.in/wiki/index.php/Package_Management_System
Unknown Web Developer

Related Posts Plugin for WordPress, Blogger...