...::: Recent Updates :::...

Sunday, September 18, 2011

Mod Convertor Java Applets

------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
JAVA APPLET PROGRAM
( Mod Converter )
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
2. Create applet for Mod Convertor which converts from different bases to base 10.
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------ 
NAME : SAHIN NISAR RAJ
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
 ------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package session9;

//Create applet for Mod Convertor which converts from different bases to base 10.

import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;

public class S9Q3 extends Applet implements ActionListener,KeyListener
{
    Button Convert;
    Label lb_Num;
    Label lb_Base;
    Label devl;
    Button Clear;
    TextField Num,Base;
    TextArea Res;

    int i=0;

    @Override
    public void init()
    {
        setSize(210,300);
        setBackground(Color.LIGHT_GRAY);

        Convert = new Button("Convert");
        Clear = new Button("Clear");
        lb_Num = new Label("Number");
        lb_Base = new Label("Base");
        devl = new Label("Developed By : RAJ SAHIN N.");
        Num = new TextField(20);
        Base = new TextField(20);
        Res  = new TextArea(3,25);
       
        add(lb_Num);
        add(Num);
        add(lb_Base);
        add(Base);
        add(Convert);
        add(Clear);
        add(Res);     
        add(devl);

        Convert.setBackground(Color.white);
        Clear.setBackground(Color.white);
        Convert.addActionListener(this);
        Clear.addActionListener(this);
        devl.setForeground(Color.red);

    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource() == Convert)
        {

            try
            {
                int oprand,div= 0;
                StringBuffer res;
                oprand = Integer.parseInt(Num.getText());
                div = Integer.parseInt(Base.getText());
                res = Calculation(oprand,div);
                Res.setText("00"+res.reverse().toString());

            } catch (Exception ex)
            {
                 JOptionPane.showMessageDialog(this,"Please Enter Valid Input Values");

            }
           
        }
        if(e.getSource() == Clear)
        {
            Num.setText("");
            Base.setText("");
            Res.setText("");
        }
    }

    public StringBuffer Calculation(int operand,int div)
    {
           StringBuffer trans = new StringBuffer();
                do
        {
            trans.append(operand % div);
            operand = operand / div;
            this.i++;

        }while(operand != 0);

            return trans;
    }
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment