This is the Retirement calculator done by using awt and swings this is good and execute fastley
the source code is :
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.text.PlainDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
class ret12
{
JFrame x;
JTextField t1,t2,t3,t4,t5,t6;
JLabel l1,l2,l3,l4,l5,l7;
Button b1,b2;
ret12()
{
x=new JFrame("RETIRMENT CALUCULATOR");
l1=new JLabel("PRESENT AGE");
l2=new JLabel("RETIRED AGE");
l3=new JLabel(" INTEREST RATE");
l4=new JLabel("TOTAL MONEY");
l5=new JLabel("AMOUNT DEPOSIT");
l7=new JLabel("TOTAL YEARS");
t1=new JTextField(new numbers(2),"",10);
t2=new JTextField(new numbers(2),"",10);
t3=new JTextField("",10);
t4=new JTextField("",10);
t5=new JTextField(new numbers(5),"",10);
t6=new JTextField("",10);
b1=new Button("CHECK");
b2=new Button("CLEAR");
x.setLayout(null);
x.setResizable(false);
l1.setBounds(30,40,120,40);
t1.setBounds(220,50,150,25);
l2.setBounds(30,80,120,35);
t2.setBounds(220,85,150,25);
l5.setBounds(30,120,150,35);
t5.setBounds(220,125,150,25);
l3.setBounds(28,160,150,35);
t3.setBounds(220,165,150,25);
l7.setBounds(30,200,120,35);
t6.setBounds(220,205,150,25);
l1.setFont(new Font("italic",Font.BOLD,16));
l2.setFont(new Font("italic",Font.BOLD,16));
l3.setFont(new Font("italic",Font.BOLD,16));
l4.setFont(new Font("italic",Font.BOLD,16));
l5.setFont(new Font("italic",Font.BOLD,16));
l7.setFont(new Font("italic",Font.BOLD,16));
l4.setBounds(30,240,120,35);
t4.setBounds(220,245,150,25);
t4.setEditable(false);
b1.setBounds(60,300,100,30);
b2.setBounds(210,300,100,30);
Font f=new Font("Arial",Font.BOLD,30);
x.add(l1);
x.add(t1);
x.add(l2);
x.add(t2);
x.add(l5);
x.add(t5);
x.add(l3);
x.add(t3);
x.add(l7);
x.add(t6);
x.add(l4);
x.add(t4);
x.add(b1);
x.add(b2);
x.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent ee)
{
System.exit(0);
}
});
t1.setBackground(Color.PINK);
t2.setBackground(Color.PINK);
t3.setBackground(Color.PINK);
t5.setBackground(Color.PINK);
t6.setEditable(false);
x.setSize(400,400);
x.setVisible(true);
b1.addKeyListener(new KeyAdapter()
{
public void KeyPressed(KeyEvent e)
{
try
{
int key=e.getKeyCode();
if(key==KeyEvent.VK_SPACE)
{
if(t1.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter the Present Age");
else if(Integer.parseInt(t1.getText())<20||Integer.parseInt(t1.getText())>55)
JOptionPane.showMessageDialog(x,"enter the present age between 20 and 55");
else if(t2.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Retired Age");
else if(Integer.parseInt(t2.getText())<50||Integer.parseInt(t2.getText())>65)
JOptionPane.showMessageDialog(x,"enter the Retirment age between 50 and 65");
else if(t5.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Deposit Amount");
else if(Double.parseDouble(t5.getText())<=0||Double.parseDouble(t5.getText())>20000)
JOptionPane.showMessageDialog(x,"enter the amount between 1 and 13000");
else if(t3.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Intrest Rate");
else if(Double.parseDouble(t3.getText())<=0||Double.parseDouble(t3.getText())>12)
JOptionPane.showMessageDialog(x,"enter the Intrest Rate between 1 and 12");
myfunction();
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(x,"Check all the fields correctly without any Blanks and Alphabets");
}
}
});
b2.addKeyListener(new KeyAdapter()
{
public void KeyPressed(KeyEvent e)
{
int key1=e.getKeyCode();
if(key1==KeyEvent.VK_SPACE)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
}
}
});
b1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
try
{
if(t1.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter the Present Age");
else if(Integer.parseInt(t1.getText())<20||Integer.parseInt(t1.getText())>55)
JOptionPane.showMessageDialog(x,"Please Enter the Present Age Between 20 and 55");
else if(t2.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Retired Age");
else if(Integer.parseInt(t2.getText())<50||Integer.parseInt(t2.getText())>65)
JOptionPane.showMessageDialog(x,"Please Enter the Retirment Age Between 50 and 65");
else if(t5.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Deposit Amount");
else if(Double.parseDouble(t5.getText())<=0||Double.parseDouble(t5.getText())>50000)
JOptionPane.showMessageDialog(x,"Please Enter the Amount Between 1 and 50000");
else if(t3.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Intrest Rate");
else if(Double.parseDouble(t3.getText())<=0||Double.parseDouble(t3.getText())>20)
JOptionPane.showMessageDialog(x,"Please Enter the Intrest Rate Between 1 and 20");
myfunction();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(x,"Please Enter the Intrest Rate With Out Any Charectres");
t6.setText("");
t4.setText("");
}
}
});
b2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
}
});
}
public void myfunction()
{
Double p=Double.parseDouble(t5.getText());
Double i=Double.parseDouble(t3.getText())/100;
Double q=12.0;
int p1=Integer.parseInt(t2.getText());
int p2=Integer.parseInt(t1.getText());
Double p3=Double.parseDouble(t3.getText());
int n=Integer.parseInt(t2.getText())-Integer.parseInt(t1.getText());
Double tot=0.0;
Double n2=60.0;
for(int j=0;j<n;j++)
{
tot=p+(tot+(tot*i));
}
if((p2>=20||p2<=55)&&(p1>=50&&p1<=65)&&(p3>0&&p3<=20)&&(p>=0&&p<=50000))
{
Long l=(new Double(Math.round(tot))).longValue();
String s=(Long.toString(l));
String s1=" ";
if(s.length()==5)
{
s1+=(s.substring(0,2))+","+(s.substring(2,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==6)
{
s1+=(s.substring(0,1))+","+(s.substring(1,3))+","+(s.substring(3,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==7)
{
s1+=(s.substring(0,2))+","+(s.substring(2,4))+","+(s.substring(4,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==8)
{
s1+=(s.substring(0,1))+","+(s.substring(1,3))+","+(s.substring(3,5))+","+(s.substring(5,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==9)
{
s1+=(s.substring(0,2))+","+(s.substring(2,4))+","+(s.substring(4,6))+","+(s.substring(6,s.length()));
t4.setText("Rs:"+s1);
}
}
else
{
t4.setText("");
}
if((n>0&&n<=45)&&(p2>=20&&p2<=55)&&(p1>=50&&p1<=65)&&(p3>0&&p3<=20)&&(p>=0&&p<=50000))
{
t6.setText(Integer.toString(n));
}
else
{
t6.setText("");
}
}
class numbers extends PlainDocument
{
private int limit;
numbers(int limit)
{
super();
this.limit = limit;
}
numbers(int limit, boolean upper)
{
super();
this.limit = limit;
}
public void insertString(int offset, String str, AttributeSet a)
throws BadLocationException
{
for (int i = 0; i < str.length(); i++)
{
if (!Character.isDigit(str.charAt(i)))
{
return;
}
}
if (str == null)
return;
if ((getLength() + str.length()) <= limit)
{
super.insertString(offset, str, a);
}
}
}
public static void main(String[] args)
{
ret12 r=new ret12();
}
}
it executs perfectly
thank you
the source code is :
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.text.PlainDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
class ret12
{
JFrame x;
JTextField t1,t2,t3,t4,t5,t6;
JLabel l1,l2,l3,l4,l5,l7;
Button b1,b2;
ret12()
{
x=new JFrame("RETIRMENT CALUCULATOR");
l1=new JLabel("PRESENT AGE");
l2=new JLabel("RETIRED AGE");
l3=new JLabel(" INTEREST RATE");
l4=new JLabel("TOTAL MONEY");
l5=new JLabel("AMOUNT DEPOSIT");
l7=new JLabel("TOTAL YEARS");
t1=new JTextField(new numbers(2),"",10);
t2=new JTextField(new numbers(2),"",10);
t3=new JTextField("",10);
t4=new JTextField("",10);
t5=new JTextField(new numbers(5),"",10);
t6=new JTextField("",10);
b1=new Button("CHECK");
b2=new Button("CLEAR");
x.setLayout(null);
x.setResizable(false);
l1.setBounds(30,40,120,40);
t1.setBounds(220,50,150,25);
l2.setBounds(30,80,120,35);
t2.setBounds(220,85,150,25);
l5.setBounds(30,120,150,35);
t5.setBounds(220,125,150,25);
l3.setBounds(28,160,150,35);
t3.setBounds(220,165,150,25);
l7.setBounds(30,200,120,35);
t6.setBounds(220,205,150,25);
l1.setFont(new Font("italic",Font.BOLD,16));
l2.setFont(new Font("italic",Font.BOLD,16));
l3.setFont(new Font("italic",Font.BOLD,16));
l4.setFont(new Font("italic",Font.BOLD,16));
l5.setFont(new Font("italic",Font.BOLD,16));
l7.setFont(new Font("italic",Font.BOLD,16));
l4.setBounds(30,240,120,35);
t4.setBounds(220,245,150,25);
t4.setEditable(false);
b1.setBounds(60,300,100,30);
b2.setBounds(210,300,100,30);
Font f=new Font("Arial",Font.BOLD,30);
x.add(l1);
x.add(t1);
x.add(l2);
x.add(t2);
x.add(l5);
x.add(t5);
x.add(l3);
x.add(t3);
x.add(l7);
x.add(t6);
x.add(l4);
x.add(t4);
x.add(b1);
x.add(b2);
x.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent ee)
{
System.exit(0);
}
});
t1.setBackground(Color.PINK);
t2.setBackground(Color.PINK);
t3.setBackground(Color.PINK);
t5.setBackground(Color.PINK);
t6.setEditable(false);
x.setSize(400,400);
x.setVisible(true);
b1.addKeyListener(new KeyAdapter()
{
public void KeyPressed(KeyEvent e)
{
try
{
int key=e.getKeyCode();
if(key==KeyEvent.VK_SPACE)
{
if(t1.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter the Present Age");
else if(Integer.parseInt(t1.getText())<20||Integer.parseInt(t1.getText())>55)
JOptionPane.showMessageDialog(x,"enter the present age between 20 and 55");
else if(t2.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Retired Age");
else if(Integer.parseInt(t2.getText())<50||Integer.parseInt(t2.getText())>65)
JOptionPane.showMessageDialog(x,"enter the Retirment age between 50 and 65");
else if(t5.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Deposit Amount");
else if(Double.parseDouble(t5.getText())<=0||Double.parseDouble(t5.getText())>20000)
JOptionPane.showMessageDialog(x,"enter the amount between 1 and 13000");
else if(t3.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Intrest Rate");
else if(Double.parseDouble(t3.getText())<=0||Double.parseDouble(t3.getText())>12)
JOptionPane.showMessageDialog(x,"enter the Intrest Rate between 1 and 12");
myfunction();
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(x,"Check all the fields correctly without any Blanks and Alphabets");
}
}
});
b2.addKeyListener(new KeyAdapter()
{
public void KeyPressed(KeyEvent e)
{
int key1=e.getKeyCode();
if(key1==KeyEvent.VK_SPACE)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
}
}
});
b1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
try
{
if(t1.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter the Present Age");
else if(Integer.parseInt(t1.getText())<20||Integer.parseInt(t1.getText())>55)
JOptionPane.showMessageDialog(x,"Please Enter the Present Age Between 20 and 55");
else if(t2.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Retired Age");
else if(Integer.parseInt(t2.getText())<50||Integer.parseInt(t2.getText())>65)
JOptionPane.showMessageDialog(x,"Please Enter the Retirment Age Between 50 and 65");
else if(t5.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Deposit Amount");
else if(Double.parseDouble(t5.getText())<=0||Double.parseDouble(t5.getText())>50000)
JOptionPane.showMessageDialog(x,"Please Enter the Amount Between 1 and 50000");
else if(t3.getText().equals(""))
JOptionPane.showMessageDialog(x,"Please Enter Intrest Rate");
else if(Double.parseDouble(t3.getText())<=0||Double.parseDouble(t3.getText())>20)
JOptionPane.showMessageDialog(x,"Please Enter the Intrest Rate Between 1 and 20");
myfunction();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(x,"Please Enter the Intrest Rate With Out Any Charectres");
t6.setText("");
t4.setText("");
}
}
});
b2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
}
});
}
public void myfunction()
{
Double p=Double.parseDouble(t5.getText());
Double i=Double.parseDouble(t3.getText())/100;
Double q=12.0;
int p1=Integer.parseInt(t2.getText());
int p2=Integer.parseInt(t1.getText());
Double p3=Double.parseDouble(t3.getText());
int n=Integer.parseInt(t2.getText())-Integer.parseInt(t1.getText());
Double tot=0.0;
Double n2=60.0;
for(int j=0;j<n;j++)
{
tot=p+(tot+(tot*i));
}
if((p2>=20||p2<=55)&&(p1>=50&&p1<=65)&&(p3>0&&p3<=20)&&(p>=0&&p<=50000))
{
Long l=(new Double(Math.round(tot))).longValue();
String s=(Long.toString(l));
String s1=" ";
if(s.length()==5)
{
s1+=(s.substring(0,2))+","+(s.substring(2,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==6)
{
s1+=(s.substring(0,1))+","+(s.substring(1,3))+","+(s.substring(3,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==7)
{
s1+=(s.substring(0,2))+","+(s.substring(2,4))+","+(s.substring(4,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==8)
{
s1+=(s.substring(0,1))+","+(s.substring(1,3))+","+(s.substring(3,5))+","+(s.substring(5,s.length()));
t4.setText("Rs:"+s1);
}
else if(s.length()==9)
{
s1+=(s.substring(0,2))+","+(s.substring(2,4))+","+(s.substring(4,6))+","+(s.substring(6,s.length()));
t4.setText("Rs:"+s1);
}
}
else
{
t4.setText("");
}
if((n>0&&n<=45)&&(p2>=20&&p2<=55)&&(p1>=50&&p1<=65)&&(p3>0&&p3<=20)&&(p>=0&&p<=50000))
{
t6.setText(Integer.toString(n));
}
else
{
t6.setText("");
}
}
class numbers extends PlainDocument
{
private int limit;
numbers(int limit)
{
super();
this.limit = limit;
}
numbers(int limit, boolean upper)
{
super();
this.limit = limit;
}
public void insertString(int offset, String str, AttributeSet a)
throws BadLocationException
{
for (int i = 0; i < str.length(); i++)
{
if (!Character.isDigit(str.charAt(i)))
{
return;
}
}
if (str == null)
return;
if ((getLength() + str.length()) <= limit)
{
super.insertString(offset, str, a);
}
}
}
public static void main(String[] args)
{
ret12 r=new ret12();
}
}
it executs perfectly
thank you
kekaaaaaaaa
ReplyDelete