Program.in

By Santosh Wadghule

Archive for August 2007

Number Conversion

without comments

nc

Enter decimal number in the text field. When Calculate button clicked, It will display binary, octal and hexadecimal equivalents.

// By Santosh Wadghule.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NumberConversion extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4,n1,n2;
JTextField tf1,tf2,tf3,tf4;
JButton b1,b2;
JPanel p1,p2;
JFrame frame;

NumberConversion () //constuctor
{
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

n1 = new JLabel("Created BY :",JLabel.CENTER);
n2 = new JLabel("Santosh Wadghule",JLabel.CENTER);
l1 = new JLabel("Decimal Number",JLabel.CENTER);
l2 = new JLabel("Binary Number",JLabel.CENTER);
l3 = new JLabel("Octal Number",JLabel.CENTER);
l4 = new JLabel("Hexadecimal Number",JLabel.CENTER);
tf1 = new JTextField();
tf2 = new JTextField();
tf3 = new JTextField();
tf4 = new JTextField();
b1 = new JButton("Calculate");
b2 = new JButton("Clear");

frame.setTitle("Number Conversion");
frame.setLayout(new GridLayout(6,2));
frame.setSize(300,300);
frame.add(n1);
frame.add(n2);
frame.add(l1);
frame.add(tf1);
frame.add(l2);
frame.add(tf2);
frame.add(l3);
frame.add(tf3);
frame.add(l4);
frame.add(tf4);
frame.add(b1);
frame.add(b2);
frame.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
} // end designing part

public static String toBinary(int n)
{
StringBuffer s = new StringBuffer(16);

while(n!=0)
{
s.append(n%2);
n=n/2;
}
return s.reverse().toString();
}

public static String toOctal(int n)
{
StringBuffer s = new StringBuffer(16);

while(n!=0)
{
s.append(n%8);
n=n/8;
}
return s.reverse().toString();
}

public static String toHex(int n)
{
StringBuffer s = new StringBuffer(16);

while(n!=0)
{
if(n%16>=10)
s.append((char)(55+n%16));//conversion for character
else
s.append(n%16);
n=n/16;

}
return s.reverse().toString();
}

public void actionPerformed(ActionEvent ae)

{ JButton b = (JButton)ae.getSource();
if(b==b1)
{
int n = Integer.parseInt(tf1.getText());
tf2.setText(toBinary(n));
tf3.setText(toOctal(n));
tf4.setText(toHex(n));
}
if(b==b2)
{
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf1.requestFocus();
}

}
public static void main(String args[])
{
new NumberConversion();
}
}

Written by Santosh Wadghule

August 20, 2007 at 4:39 pm

Posted in Java, Uncategorized

To-do list Source code on PSC

without comments

Today, I have uploded source code of ToDoList on Planet-Source-Code sites for beginners. This is very simple code for understand so everyone can imlpement this code. You can download it from by this link
Download

Written by Santosh Wadghule

August 20, 2007 at 10:00 am

Posted in Java, Uncategorized

To-Do List

without comments

To-Do List
This is simple To-do List java program. To-do List java program is just like to add item through textfield to the list. This program is created using swing.You can add and remove item from the list.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ToDoList extends JFrame implements ActionListener
{
JLabel l1,l2,l3;
JTextField tf;
JButton b1,b2;
JPanel p1,p2,p3,p4;
JFrame frame;
List lst;

ToDoList ()//constuctor
{
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

l1 = new JLabel("TO DO LIST",JLabel.CENTER);
l2 = new JLabel("",JLabel.CENTER);
l3 = new JLabel("Enter Here",JLabel.LEFT);

lst = new List();
tf = new JTextField();
b1 = new JButton("Add");
b2 = new JButton("Remove");

p1 = new JPanel();
p1.setLayout(new GridLayout(2,1));
p1.add(l1);
p1.add(lst);

p2= new JPanel();
p2.setLayout(new GridLayout(3,1));
p2.add(l2);
p2.add(l3);
p2.add(tf);

p3= new JPanel();
p3.setLayout(new GridLayout(1,2));
p3.add(b1);
p3.add(b2);

frame.setTitle("Santosh Wadghule");
frame.setSize(300,300);
frame.setLayout(new BorderLayout());
frame.add(p1,"North");
frame.add(p2,"Center");
frame.add(p3,"South");
frame.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}// end designing part

public void actionPerformed(ActionEvent ae)
{
JButton b = (JButton)ae.getSource();
if(b==b1)
{
String element = tf.getText();
lst.add(element);
tf.setText("");
}

if(b==b2)
{
int i = lst.getSelectedIndex();
lst.remove(i);
lst.select(i);
}
}

public static void main(String args[])
{ new ToDoList();
}
}

Written by Santosh Wadghule

August 18, 2007 at 5:18 pm

Posted in Java, Uncategorized

Simple Function call program

without comments

This java program is very simple to understand that how one function calls to another function.
here, main function calls the santosh and anil function.

public class FunctCall
public static void santosh () {
System.out.println ("Inside the santosh fuction");
}
public static void main (String[] args) {
int val;
System.out.println ("Inside main");
santosh();
System.out.println ("About to call anil function");
val = anil(4);
System.out.println ("anil returned a value of " + val);
System.out.println ("About to call anil again");
val = anil(-2);
System.out.println ("anil returned a value of " + val);
}
public static int anil (int param) {
System.out.println ("Inside anil with param " + param);
return param * 2;
}
}

Written by Santosh Wadghule

August 13, 2007 at 5:23 pm

Posted in Java, Uncategorized

HelloDate

without comments

This java program is to show the date of month.

import java.util.*;
public class HelloDate {
public static void main (String[] args) {
System.out.println ("Hello, it's: ");
System.out.println(new Date());
}
}

Written by Santosh Wadghule

August 13, 2007 at 4:43 pm

Posted in Java, Uncategorized

Simple Java Program

without comments

public class MyFirstApp
{
public static void main ( String[] args)
{
System.out.println("Hello World");
} // main method
} // MyFirstApp class

1] public is for that everyone can access it.
2] MyFirstApp is the name of class.
3] String[] for arguments to the method. This method must be given an array of Strings,and the array will be called ‘args’.

Written by Santosh Wadghule

August 9, 2007 at 5:57 pm

Posted in Java, Uncategorized

Hello world!

without comments

Hello Friends,
I am Santosh Wadghule from T.Y.Bsc(Comp Sci) in India.
I like to compose code & to explore technology.

Written by Santosh Wadghule

August 9, 2007 at 3:23 pm

Posted in Uncategorized