Monday, June 27, 2011

Projects

 
Hi friends,
Its glad to say that our Mini Project and Main Project have been made open source and forged in SourceForge.net

Our Mini Project was cybman - Cyber Cafe Management System
Download cybman from here

And our Main Project XooDB - A cross platform object oriented database engine with multi client support using XML and Java.
Download XooDB from here
 

Java - A simple dictionary using applet

 
/*This is a simple dictionary in which you can add words and their meanings and thereafter search for the same.*/

import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/*
 *
 * @author dhanoopbhaskar
 */
public class Main extends javax.swing.JApplet implements java.awt.event.ActionListener {

    JTextField textField = null;
    JTextArea textArea = null;
    JButton addButton = null;
    JButton showButton = null;
    String[] words = null;
    String[] meanings = null;
    int ptr = -1;

    public Main() {
        initComponents();
        setLayout(null);       
        add(textArea);
        add(textField);
        add(addButton);
        add(showButton);
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == addButton) {
            String word = textField.getText();
            String meaning = textArea.getText();

            words[++ptr] = word;
            meanings[ptr] = meaning;

            textArea.setText("");
            textField.setText("");           
        }
        if(e.getSource() == showButton) {
            String word = textField.getText();
            String meaning = "";
            boolean found = false;
            for(int i = 0 ; i <= ptr ; i++) {
                if(word.equalsIgnoreCase(words[i])) {
                    textArea.setText(meanings[i]);
                    found = true;
                }
            }

            if (found == false) {
                textArea.setText("Error: Not found !!!");
            }
        }
    }

    private void initComponents() {
        words = new String[20];
        meanings = new String[20];
        textField = new JTextField(20);
        textArea = new JTextArea();
        addButton = new JButton("Add");
        showButton = new JButton("Show");
        addButton.addActionListener(this);
        showButton.addActionListener(this);
        textField.setBounds(5, 5, 250, 30);
        textArea.setBounds(5, 40, 250, 100);
        addButton.setBounds(5, 150, 70, 20);
        showButton.setBounds(185, 150, 70, 20);
    }

}


Java - Writing to serial port using Java Communication API




import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;

/**
 *
 * @author dhanoopbhaskar
 */
public class SerialPortWriter {

    Enumeration portList;
    CommPortIdentifier portIdentifier;
    String message;
    SerialPort serialPort;
    OutputStream outputStream;
    String portName = "";

    public SerialPortWriter(String portName) {
        this.portName = portName;
        /**
         * gets a list of ports
         */
        portList = CommPortIdentifier.getPortIdentifiers();


        while (portList.hasMoreElements()) {

            portIdentifier = (CommPortIdentifier) portList.nextElement();
            /**
             * check whether the port is serial
             */
            if (portIdentifier.getPortType() == CommPortIdentifier.PORT_SERIAL) {

                /**
                 * check whether the port name is portName (eg.COM1)
                 */
                if (portIdentifier.getName().equals(portName)) {
                    try {
                        /**
                         * String - application name
                         * int - time out value
                         */
                        serialPort = (SerialPort) portIdentifier.open("SerialPortWriter", 2000);
                    } catch (PortInUseException ex) {
                        System.out.println("#1 " + ex);
                    }

                    try {
                        outputStream = serialPort.getOutputStream();
                    } catch (IOException ex) {
                        System.out.println("#2 " + ex);
                    }

                    try {
                        /**
                         * int baudrate
                         * int dataBits
                         * int stopBits
                         * int parity
                         */
                        serialPort.setSerialPortParams(9600,
                                SerialPort.DATABITS_8,
                                SerialPort.STOPBITS_1,
                                SerialPort.PARITY_NONE);

                        serialPort.setDTR(true);
                    } catch (UnsupportedCommOperationException ex) {
                        System.out.println("#3 " + ex);
                    }
                }
            }
        }
    }

    public void sendMessage(String message) {

        try {
            outputStream.write(message.getBytes());
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }

    public void close() {
        serialPort.close();
    }
}






To test the above program you need to download Java Communication API.



After the download has completed extract the archive and you will get the following files, and it is very important to have them installed on your system for a proper operation:
  • comm.jar
  • win32com.dll
  • javax.comm.properties
comm.jar should be placed in:

    %JAVA_HOME%/lib

    %JAVA_HOME%/jre/lib/ext

win32com.dll should be placed in:

    %JAVA_HOME%/bin

    %JAVA_HOME%/jre/bin

    %windir%System32

javax.comm.properties should be placed in:

    %JAVA_HOME%/lib

    %JAVA_HOME%/jre/lib
   

Contact Form

Name

Email *

Message *