Join Us on Facebook Follow us on Twitter Add to Circles
Showing posts with label Java Programs. Show all posts
Showing posts with label Java Programs. Show all posts

26 April 2013

Java Program for Biodata Screen




Program:

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

public class biodata extends JFrame {

JFrame f;
JLabel l,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,td;
JTextArea ta1,ta2;
JComboBox c1;
JButton b1,b2;
JRadioButton rb1,rb2;
ButtonGroup bg1;
JCheckBox ch1,ch2,ch3;
JTable tb1;
TableColumn sc,tc;
DefaultTableModel model,dtm;

public biodata() {
f=new JFrame("BIODATA");
l=new JLabel("BioData");
l.setFont(new Font("Algerian",Font.BOLD,40));
l1=new JLabel("Name                         :-");
l2=new JLabel("Address                       :-");
l3=new JLabel("Contact Number         :-");
l4=new JLabel("E-Mail Address           :-");
l5=new JLabel("Date OF Birth               :-");
l6=new JLabel("Marital Status             :-");
l7=new JLabel("Gender                          :-");
l8=new JLabel("Nationality                    :-");
l9=new JLabel("Known Language       :-");
l10=new JLabel("Qualification                :-");
l11=new JLabel("Other Qualification     :-");
t1=new JTextField(20);
ta1=new JTextArea(20,20);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
JScrollPane s=new JScrollPane(ta1,v,h);
t2=new JTextField(20);
t3=new JTextField(20);
t4=new JTextField(20);
c1=new JComboBox();
c1.addItem("Married");
c1.addItem("Unmarried");
rb1=new JRadioButton("Male");
rb2=new JRadioButton("Female");
bg1=new ButtonGroup();
bg1.add(rb1);
bg1.add(rb2);
t5=new JTextField(20);
ch1=new JCheckBox("Marathi");
ch2=new JCheckBox("Hindi");
ch3=new JCheckBox("English");
ta2=new JTextArea(20,20);

String col[]={"Sr No.","Exam Detail","University/Boards","Year Of     Passing","Grade/Class","Percentage"};
String row[][]=new String[4][6];
model = new DefaultTableModel(row, col);
tb1 = new JTable(model);


 
JScrollPane s1=new JScrollPane(tb1,v,h);
JScrollPane s2=new JScrollPane(ta2,v,h);
b1=new JButton("Submit");
b2=new JButton("Cancel");
JPanel p=new JPanel();
p.setLayout(null);

l.setBounds(200,30,200,50);
l1.setBounds(80,80,150,30);
l2.setBounds(80,130,150,30);
l3.setBounds(80,180,150,30);
l4.setBounds(80,220,150,30);
l5.setBounds(80,260,150,30);
l6.setBounds(80,300,150,30);
l7.setBounds(80,340,150,30);
l8.setBounds(80,380,150,30);
l9.setBounds(80,420,150,30);
l10.setBounds(80,460,150,30);
l11.setBounds(80,600,150,30);

t1.setBounds(250,80,200,25);
s.setBounds(250,120,200,50);
t2.setBounds(250,180,200,25);
t3.setBounds(250,220,200,25);
t4.setBounds(250,260,200,25);
c1.setBounds(250,300,200,25);
rb1.setBounds(250,340,100,25);
rb2.setBounds(350,340,200,25);
t5.setBounds(250,380,200,25);
ch1.setBounds(250,420,80,20);
ch2.setBounds(330,420,60,20);
ch3.setBounds(400,420,80,20);
s1.setBounds(20,500,600,100);
s2.setBounds(250,610,300,70);
b1.setBounds(200,700,100,30);
b2.setBounds(350,700,100,30);

p.add(l);
p.add(l1);p.add(l2);
p.add(l3);p.add(l4);
p.add(l5);p.add(l6);
p.add(l7);p.add(l8);
p.add(l9);p.add(l10);
p.add(l11);p.add(t1);
p.add(s);p.add(t2);
p.add(t3);p.add(t4);
p.add(c1);p.add(rb1);
p.add(rb2);p.add(t5);
p.add(ch1);p.add(ch2);
p.add(ch3);
p.add(s1);p.add(s2);
p.add(b1);p.add(b2);

f.add(p,BorderLayout.CENTER);
f.add(p);

f.setSize(650,780);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


b1.addActionListener(new ActionListener()
{

            public void actionPerformed(ActionEvent ae)
{
        JOptionPane.showMessageDialog(null, "Data added Successfully ");

            }
        });

}
public static void main(String args[]){
biodata b=new biodata();
}
}






3 April 2013

CalCulator using Java


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
/*
<applet code="calc" width=200 height=200>
</applet>
*/
public class calc extends Frame implements ActionListener
{
String msg= " ";
String ts=" ";
String n1,n2;
char op;
double a,b,c,prev,memory;
Button one,two,three,four,five,six,seven,eight,nine,ten,zero,dot,off;
Button backspace,clear,eq,plus,minus,mul,div,pm,sqrt,obx,sqr,sin,cos,tan;
Button mc,mr,ms,mplus,mstatus;
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();

TextField display;

public calc()
{
setTitle("Calculator");
setLayout(new BorderLayout());
display=new TextField(30);
one=new Button("1");
two=new Button("2");
three=new Button("3");
four=new Button("4");
five=new Button("5");
six=new Button("6");
seven=new Button("7");
eight=new Button("8");
nine=new Button("9");
ten=new Button("10");
zero=new Button("0");
dot=new Button(".");
eq=new Button("=");
plus=new Button("+");
minus=new Button("-");
div=new Button(" / ");
mul=new Button("*");
sqrt=new Button("sqrt");
sin=new Button("sin");
cos=new Button("cos");
tan=new Button("tan");
clear=new Button("C");
mc=new Button("MC");
mr=new Button("MR");
ms=new Button("MS");
mplus=new Button("M+");
mstatus=new Button();

backspace=new Button("B");
off=new Button("off");

p1.add(display);
add(p1,BorderLayout.NORTH);

p4.setLayout(new GridLayout(3,1,5,5));
p4.add(backspace);
p4.add(clear);
p4.add(off);
add(p4,BorderLayout.EAST);

p3.setLayout(new GridLayout(5,2,5,5));
p3.add(mstatus);
p3.add(mc);
p3.add(mr);
p3.add(ms);
p3.add(mplus);
add(p3,BorderLayout.WEST);

p2.setLayout(new GridLayout(5,4,5,5));

p2.add(seven);
p2.add(eight);
p2.add(nine);
p2.add(div);

p2.add(four);
p2.add(five);
p2.add(six);
p2.add(mul);

p2.add(one);
p2.add(two);
p2.add(three);
p2.add(minus);

p2.add(zero);
p2.add(dot);
p2.add(eq);
p2.add(plus);

p2.add(sin);
p2.add(cos);
p2.add(tan);
p2.add(sqrt);

add(p2,BorderLayout.CENTER);

display.setEditable(false);
p1.setBackground(Color.lightGray);
p2.setBackground(Color.lightGray);
p3.setBackground(Color.lightGray);
p4.setBackground(Color.lightGray);

display.addActionListener(this);
one.addActionListener(this);
two.addActionListener(this);
three.addActionListener(this);
four.addActionListener(this);
five.addActionListener(this);
six.addActionListener(this);
seven.addActionListener(this);
eight.addActionListener(this);
nine.addActionListener(this);
zero.addActionListener(this);
dot.addActionListener(this);
eq.addActionListener(this);
plus.addActionListener(this);
minus.addActionListener(this);
clear.addActionListener(this);
backspace.addActionListener(this);
div.addActionListener(this);
mul.addActionListener(this);
sqrt.addActionListener(this);
sin.addActionListener(this);
cos.addActionListener(this);
tan.addActionListener(this);
off.addActionListener(this);
mc.addActionListener(this);
mr.addActionListener(this);
ms.addActionListener(this);
mplus.addActionListener(this);

setVisible(true);
addWindowListener(new w());
setSize(300,300);
setResizable(false);
pack();
}

public void actionPerformed(ActionEvent ae)
{

String str=ae.getActionCommand();
if(str.equals("1"))
{
ts=ts+"1";
display.setText(ts);
}
else if (str.equals("2"))
{
ts=ts+"2";
display.setText(ts);
}
else if (str.equals("3"))
{
ts=ts+"3";
display.setText(ts);
}
else if (str.equals("4"))
{
ts=ts+"4";
display.setText(ts);
}
else if (str.equals("5"))
{
ts=ts+"5";
display.setText(ts);
}
else if (str.equals("6"))
{
ts=ts+"6";
display.setText(ts);
}
else if (str.equals("7"))
{
ts=ts+"7";
display.setText(ts);
}
else if (str.equals("8"))
{
ts=ts+"8";
display.setText(ts);
}
else if (str.equals("9"))
{
ts=ts+"9";
display.setText(ts);
}
else if (str.equals("0"))
{
ts=ts+"0";
display.setText(ts);
}
else if (str.equals("."))
{
ts=ts+".";
display.setText(ts);
}

else if (str.equals("+"))
{
n1=display.getText();
ts=" ";
a=Double.parseDouble(display.getText().trim());
op='+';
display.setText(ts);
}

else if (str.equals("-"))
{
n1=display.getText();
ts=" ";
display.setText(ts);
a=Double.parseDouble(n1.trim());
op='-';
}

else if (str.equals(" / "))
{
n1=display.getText();
ts=" ";
display.setText(ts);
a=Double.parseDouble(n1.trim());
op='/';
}


else if (str.equals("*"))
{
n1=display.getText();
ts=" ";
display.setText(ts);
a=Double.parseDouble(n1.trim());
op='*';
}


else if (str.equals("C"))
{
ts=" ";
display.setText(ts);
n1=" ";
n2=" ";
a=0;b=0;c=0;
op='C';
}

else if (str.equals("B"))
{
msg=display.getText();
ts=msg.substring(0,msg.length()-1);
display.setText(ts);
op='B';
}

else if (str.equals("sqrt"))
{
n1=display.getText();
a=Double.parseDouble(n1.trim());
a=Math.sqrt(a);
ts=" "+a;
display.setText(ts);
//op='*';
}


else if (str.equals("sin"))
{
n1=display.getText();
a=Double.parseDouble(n1.trim());
a=Math.sin(a);
ts=" "+a;
display.setText(ts);
//op='*';
}

else if (str.equals("cos"))
{
n1=display.getText();
a=Double.parseDouble(n1.trim());
a=Math.cos(a);
ts=" "+a;
display.setText(ts);
//op='*';
}


else if (str.equals("tan"))
{
n1=display.getText();
a=Double.parseDouble(n1.trim());
a=Math.tan(a);
ts=" "+a;
display.setText(ts);
//op='*';
}


else if (str.equals("MC"))
{
memory=0;
mstatus.setLabel(" ");
}


else if (str.equals("MS"))
{
n1=display.getText();
if(n1!=null)
{ a=Double.parseDouble(n1.trim());
memory=a;
mstatus.setLabel("M");
}
}

else if (str.equals("MR"))
{
ts=" "+memory;
display.setText(ts);
}

else if (str.equals("M+"))
{
n1=display.getText();
if(n1!=" ")
{
a=Double.parseDouble(n1.trim());
memory=memory+a;
}
}

else if (str.equals("tan"))
{
n1=display.getText();
a=Double.parseDouble(n1.trim());
a=Math.tan(a);
ts=" "+a;
display.setText(ts);
//op='*';
}

else if (str.equals("off"))
{
setVisible(false);
System.exit(0);
}

else if (str.equals("="))
{
String n3=" ";
n2=display.getText();
b=Double.parseDouble(n2.trim());

switch(op)
{
case '+':c=a+b;break;
case '-':c=a-b;break;
case '/':c=a/b;break;
case '*':c=a*b;break;
default:c=b;
}
    n3=n3+c;
op='C';
display.setText(n3);
}


}
public static void main(String args[])
{
calc c = new calc();
};

 class w extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);
}
}
}