Recent Post
Home
All posts
Friday, April 21, 2017
Tuesday, April 18, 2017
Tuesday, April 11, 2017
Currency Converter Java
Code::
import javax.swing.*;
import java.awt.event.*;
public class CurrencyConverter extends JFrame
{ JTextField t1=new JTextField();
JTextField t2=new JTextField();
JTextField t3=new JTextField();
JLabel l1=new JLabel("Rupees:");
JLabel l2=new JLabel("US Dollars:");
JLabel l3=new JLabel("Euros:");
CurrencyConverter()
{
setLayout(null);
setTitle("Converter");
setVisible(true);
setSize(400,200);
l1.setBounds(20,30,70,30);
l2.setBounds(20,70,70,30);
l3.setBounds(20,110,70,30);
t1.setBounds(120,30,70,30);
t2.setBounds(120,70,70,30);
t3.setBounds(120,110,70,30);
add(t1);
add(l1);
add(l2);
add(t2);
add(t3);
add(l3);
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
double a=Double.parseDouble(t1.getText());
t2.setText(String.format("%.2f",a*0.015));
t3.setText(String.format("%.2f",a*0.015));
}
});
t2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
double a=Double.parseDouble(t2.getText());
t1.setText(String.format("%.2f",a*64.68));
t3.setText(String.format("%.2f",a*0.94));
}
});
t3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
double a=Double.parseDouble(t3.getText());
t2.setText(String.format("%.2f",a*1.06));
t1.setText(String.format("%.2f",a*68.71));
}
});
}
public static void main(String[] nt)
{
new CurrencyConverter();
}
}
import javax.swing.*;
import java.awt.event.*;
public class CurrencyConverter extends JFrame
{ JTextField t1=new JTextField();
JTextField t2=new JTextField();
JTextField t3=new JTextField();
JLabel l1=new JLabel("Rupees:");
JLabel l2=new JLabel("US Dollars:");
JLabel l3=new JLabel("Euros:");
CurrencyConverter()
{
setLayout(null);
setTitle("Converter");
setVisible(true);
setSize(400,200);
l1.setBounds(20,30,70,30);
l2.setBounds(20,70,70,30);
l3.setBounds(20,110,70,30);
t1.setBounds(120,30,70,30);
t2.setBounds(120,70,70,30);
t3.setBounds(120,110,70,30);
add(t1);
add(l1);
add(l2);
add(t2);
add(t3);
add(l3);
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
double a=Double.parseDouble(t1.getText());
t2.setText(String.format("%.2f",a*0.015));
t3.setText(String.format("%.2f",a*0.015));
}
});
t2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
double a=Double.parseDouble(t2.getText());
t1.setText(String.format("%.2f",a*64.68));
t3.setText(String.format("%.2f",a*0.94));
}
});
t3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
double a=Double.parseDouble(t3.getText());
t2.setText(String.format("%.2f",a*1.06));
t1.setText(String.format("%.2f",a*68.71));
}
});
}
public static void main(String[] nt)
{
new CurrencyConverter();
}
}
Output::
Temperature Converter Java
Code::
import javax.swing.*;
import java.awt.event.*;
public class Converter extends JFrame
{
JTextField t1 =new JTextField();
JTextField t2 =new JTextField();
JLabel l1=new JLabel("Celsius:");
JLabel l2=new JLabel("Fahrenheit:");
Converter()
{
setLayout(null);
setTitle("Converter");
setVisible(true);
setSize(400,200);
l1.setBounds(20,30,70,30);
l2.setBounds(20,70,70,30);
t1.setBounds(120,30,70,30);
t2.setBounds(120,70,70,30);
add(t1);
add(l1);
add(l2);
add(t2);
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(Double.parseDouble(t1.getText()))*1.8+32;
t2.setText(String.format("%.1f",a));
}
});
t2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(((Double.parseDouble(t2.getText()))-32)/1.8);
t1.setText(String.format("%.1f",a));
}
});
}
public static void main(String[] nt) {
new Converter();
}
}
import javax.swing.*;
import java.awt.event.*;
public class Converter extends JFrame
{
JTextField t1 =new JTextField();
JTextField t2 =new JTextField();
JLabel l1=new JLabel("Celsius:");
JLabel l2=new JLabel("Fahrenheit:");
Converter()
{
setLayout(null);
setTitle("Converter");
setVisible(true);
setSize(400,200);
l1.setBounds(20,30,70,30);
l2.setBounds(20,70,70,30);
t1.setBounds(120,30,70,30);
t2.setBounds(120,70,70,30);
add(t1);
add(l1);
add(l2);
add(t2);
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(Double.parseDouble(t1.getText()))*1.8+32;
t2.setText(String.format("%.1f",a));
}
});
t2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(((Double.parseDouble(t2.getText()))-32)/1.8);
t1.setText(String.format("%.1f",a));
}
});
}
public static void main(String[] nt) {
new Converter();
}
}
Output::
Monday, April 10, 2017
Puzzle Game Java
Code::
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Puzzle extends Applet implements ActionListener
{ Button b[]=new Button[9];
Button r=new Button("Reset");
public void init()
{ setLayout(null);
setSize(400,400);
JOptionPane.showMessageDialog(this,"Make sequence 1,2,3... by Clicking on buttons...");
int x=50;
int y=50;
for (int i=0;i<9;i++)
{ b[i]=new Button(String.valueOf(i+1));
b[i].setBounds(x+50,y+50,30,30);
x+=50;
if((i+1)%3==0)
{
y+=50;
x=50;
}
add(b[i]);
b[i].addActionListener(this);
}
b[8].setLabel("2");
b[1].setLabel("");
r.setBounds(140,250,50,50);
r.addActionListener(this);
add(r);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b[0])
{
if(b[1].getLabel()=="")
{
b[1].setLabel(b[0].getLabel());
b[0].setLabel("");
}
if(b[3].getLabel()=="")
{
b[3].setLabel(b[0].getLabel());
b[0].setLabel("");
}
}
if(e.getSource()==b[8])
{
if(b[5].getLabel()=="")
{
b[5].setLabel(b[8].getLabel());
b[8].setLabel("");
}
if(b[7].getLabel()=="")
{
b[7].setLabel(b[8].getLabel());
b[8].setLabel("");
}
}
if(e.getSource()==b[1])
{
if(b[0].getLabel()=="")
{
b[0].setLabel(b[1].getLabel());
b[1].setLabel("");
}
if(b[2].getLabel()=="")
{
b[2].setLabel(b[1].getLabel());
b[1].setLabel("");
}
if(b[4].getLabel()=="")
{
b[4].setLabel(b[1].getLabel());
b[1].setLabel("");
}
}
if(e.getSource()==b[2])
{
if(b[1].getLabel()=="")
{
b[1].setLabel(b[2].getLabel());
b[2].setLabel("");
}
if(b[5].getLabel()=="")
{
b[5].setLabel(b[2].getLabel());
b[2].setLabel("");
}
}
if(e.getSource()==b[3])
{
if(b[0].getLabel()=="")
{
b[0].setLabel(b[3].getLabel());
b[3].setLabel("");
}
if(b[4].getLabel()=="")
{
b[4].setLabel(b[3].getLabel());
b[3].setLabel("");
}
if(b[6].getLabel()=="")
{
b[6].setLabel(b[3].getLabel());
b[3].setLabel("");
}
}
if(e.getSource()==b[4])
{
if(b[1].getLabel()=="")
{
b[1].setLabel(b[4].getLabel());
b[4].setLabel("");
}
if(b[3].getLabel()=="")
{
b[3].setLabel(b[4].getLabel());
b[4].setLabel("");
}
if(b[5].getLabel()=="")
{
b[5].setLabel(b[4].getLabel());
b[4].setLabel("");
}
if(b[7].getLabel()=="")
{
b[7].setLabel(b[4].getLabel());
b[4].setLabel("");
}
}
if(e.getSource()==b[5])
{
if(b[2].getLabel()=="")
{
b[2].setLabel(b[5].getLabel());
b[5].setLabel("");
}
if(b[4].getLabel()=="")
{
b[4].setLabel(b[5].getLabel());
b[5].setLabel("");
}
if(b[8].getLabel()=="")
{
b[8].setLabel(b[5].getLabel());
b[5].setLabel("");
}
}
if(e.getSource()==b[7])
{
if(b[4].getLabel()=="")
{
b[4].setLabel(b[7].getLabel());
b[7].setLabel("");
}
if(b[6].getLabel()=="")
{
b[6].setLabel(b[7].getLabel());
b[7].setLabel("");
}
if(b[8].getLabel()=="")
{
b[8].setLabel(b[7].getLabel());
b[7].setLabel("");
}
}
if(e.getSource()==b[6])
{
if(b[3].getLabel()=="")
{
b[3].setLabel(b[6].getLabel());
b[6].setLabel("");
}
if(b[7].getLabel()=="")
{
b[7].setLabel(b[6].getLabel());
b[6].setLabel("");
}
}
if(b[0].getLabel().equals("1")&&b[1].getLabel().equals("2")&&b[2].getLabel()
.equals("3")&&b[3].getLabel().equals("4")&&b[4].getLabel().equals("5")
&&b[5].getLabel().equals("6")&&b[6].getLabel().equals("7")&&b[7].getLabel()
.equals("8")&&b[8].getLabel().equals(""))
{
JOptionPane.showMessageDialog(this,"Congratulations! You won.");
}
if(e.getSource()==r)
{ for(int i=0;i<9;i++)
{
b[i].setLabel(String.valueOf(i+1));
}
int j=(int)(7*Math.random());
if(j==5)
{
j=(int)(7*Math.random());
}
b[8].setLabel(b[j].getLabel());
b[j].setLabel("");
}
}
public void paint(Graphics g)
{
g.drawImage(getImage(getDocumentBase(),"23.jpg"),0,0,this);
g.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,25));
g.drawString("Puzzle Game",105,40);
g.drawString("By Dishant",125,350);
}
}
Output::
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Puzzle extends Applet implements ActionListener
{ Button b[]=new Button[9];
Button r=new Button("Reset");
public void init()
{ setLayout(null);
setSize(400,400);
JOptionPane.showMessageDialog(this,"Make sequence 1,2,3... by Clicking on buttons...");
int x=50;
int y=50;
for (int i=0;i<9;i++)
{ b[i]=new Button(String.valueOf(i+1));
b[i].setBounds(x+50,y+50,30,30);
x+=50;
if((i+1)%3==0)
{
y+=50;
x=50;
}
add(b[i]);
b[i].addActionListener(this);
}
b[8].setLabel("2");
b[1].setLabel("");
r.setBounds(140,250,50,50);
r.addActionListener(this);
add(r);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b[0])
{
if(b[1].getLabel()=="")
{
b[1].setLabel(b[0].getLabel());
b[0].setLabel("");
}
if(b[3].getLabel()=="")
{
b[3].setLabel(b[0].getLabel());
b[0].setLabel("");
}
}
if(e.getSource()==b[8])
{
if(b[5].getLabel()=="")
{
b[5].setLabel(b[8].getLabel());
b[8].setLabel("");
}
if(b[7].getLabel()=="")
{
b[7].setLabel(b[8].getLabel());
b[8].setLabel("");
}
}
if(e.getSource()==b[1])
{
if(b[0].getLabel()=="")
{
b[0].setLabel(b[1].getLabel());
b[1].setLabel("");
}
if(b[2].getLabel()=="")
{
b[2].setLabel(b[1].getLabel());
b[1].setLabel("");
}
if(b[4].getLabel()=="")
{
b[4].setLabel(b[1].getLabel());
b[1].setLabel("");
}
}
if(e.getSource()==b[2])
{
if(b[1].getLabel()=="")
{
b[1].setLabel(b[2].getLabel());
b[2].setLabel("");
}
if(b[5].getLabel()=="")
{
b[5].setLabel(b[2].getLabel());
b[2].setLabel("");
}
}
if(e.getSource()==b[3])
{
if(b[0].getLabel()=="")
{
b[0].setLabel(b[3].getLabel());
b[3].setLabel("");
}
if(b[4].getLabel()=="")
{
b[4].setLabel(b[3].getLabel());
b[3].setLabel("");
}
if(b[6].getLabel()=="")
{
b[6].setLabel(b[3].getLabel());
b[3].setLabel("");
}
}
if(e.getSource()==b[4])
{
if(b[1].getLabel()=="")
{
b[1].setLabel(b[4].getLabel());
b[4].setLabel("");
}
if(b[3].getLabel()=="")
{
b[3].setLabel(b[4].getLabel());
b[4].setLabel("");
}
if(b[5].getLabel()=="")
{
b[5].setLabel(b[4].getLabel());
b[4].setLabel("");
}
if(b[7].getLabel()=="")
{
b[7].setLabel(b[4].getLabel());
b[4].setLabel("");
}
}
if(e.getSource()==b[5])
{
if(b[2].getLabel()=="")
{
b[2].setLabel(b[5].getLabel());
b[5].setLabel("");
}
if(b[4].getLabel()=="")
{
b[4].setLabel(b[5].getLabel());
b[5].setLabel("");
}
if(b[8].getLabel()=="")
{
b[8].setLabel(b[5].getLabel());
b[5].setLabel("");
}
}
if(e.getSource()==b[7])
{
if(b[4].getLabel()=="")
{
b[4].setLabel(b[7].getLabel());
b[7].setLabel("");
}
if(b[6].getLabel()=="")
{
b[6].setLabel(b[7].getLabel());
b[7].setLabel("");
}
if(b[8].getLabel()=="")
{
b[8].setLabel(b[7].getLabel());
b[7].setLabel("");
}
}
if(e.getSource()==b[6])
{
if(b[3].getLabel()=="")
{
b[3].setLabel(b[6].getLabel());
b[6].setLabel("");
}
if(b[7].getLabel()=="")
{
b[7].setLabel(b[6].getLabel());
b[6].setLabel("");
}
}
if(b[0].getLabel().equals("1")&&b[1].getLabel().equals("2")&&b[2].getLabel()
.equals("3")&&b[3].getLabel().equals("4")&&b[4].getLabel().equals("5")
&&b[5].getLabel().equals("6")&&b[6].getLabel().equals("7")&&b[7].getLabel()
.equals("8")&&b[8].getLabel().equals(""))
{
JOptionPane.showMessageDialog(this,"Congratulations! You won.");
}
if(e.getSource()==r)
{ for(int i=0;i<9;i++)
{
b[i].setLabel(String.valueOf(i+1));
}
int j=(int)(7*Math.random());
if(j==5)
{
j=(int)(7*Math.random());
}
b[8].setLabel(b[j].getLabel());
b[j].setLabel("");
}
}
public void paint(Graphics g)
{
g.drawImage(getImage(getDocumentBase(),"23.jpg"),0,0,this);
g.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,25));
g.drawString("Puzzle Game",105,40);
g.drawString("By Dishant",125,350);
}
}
Output::
Thursday, April 6, 2017
Calculator in Java
Following Code will make a Calculator:
Code::
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Calci extends Applet implements ActionListener {
Button [] b=new Button[14];
TextField t=new TextField();
String Op="";
int n=0,d=0;
Button eq=new Button("=");
Button cl=new Button("CE");
public void init()
{
setLayout(null);
t.setBounds(50,20,110,20);
int x=0;
int y=0;
for(int i=0;i<10;i++)
{ if(i%4==0 && i!=0)
{
y+=50;
x=0;
}
b[i]=new Button(String.valueOf(i));
b[i].setBounds(x+50,y+50,20,20);
x +=30;
add(b[i]);
b[i].addActionListener(this);
}
String[] s={"+","-","*","/"};
int j=0;
int u=0;
int v=150;
for(int i=10;i<14;i++)
{
b[i]=new Button(s[j++]);
b[i].setBounds(u+50,v+50,20,20);
add(b[i]);
u+=30;
b[i].addActionListener(this);
}
eq.addActionListener(this);
eq.setBounds(110,150,20,20);
add(eq);
cl.addActionListener(this);
cl.setBounds(140,150,20,20);
add(cl);
add(t);
setSize(300,300);
}
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<10;i++)
{
if(e.getSource()==b[i])
{
t.setText(t.getText()+b[i].getLabel());
}
}
for(int i=10;i<14;i++)
{
if(e.getSource()==b[i])
{
Op=b[i].getLabel();
d=Integer.parseInt(t.getText());
t.setText("");
}
}
if(e.getSource()==eq)
{ int r=0;
n=Integer.parseInt(t.getText());
switch(Op)
{
case "+": r=d+n;
break;
case "-": r=d-n;
break;
case "*": r=d*n;
break;
case "/": r=d/n;
break;
}
t.setText(String.valueOf(r));
}
if(e.getSource()==cl)
{
t.setText("");
}
}
public void paint(Graphics g)
{ Image p=getImage(getDocumentBase(),"23.jpg");
g.drawImage(p, 0, 0, this);
g.setFont(new Font("",Font.TYPE1_FONT,25));
g.drawString("By Dishant",50, 280);
}
}
Code::
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Calci extends Applet implements ActionListener {
Button [] b=new Button[14];
TextField t=new TextField();
String Op="";
int n=0,d=0;
Button eq=new Button("=");
Button cl=new Button("CE");
public void init()
{
setLayout(null);
t.setBounds(50,20,110,20);
int x=0;
int y=0;
for(int i=0;i<10;i++)
{ if(i%4==0 && i!=0)
{
y+=50;
x=0;
}
b[i]=new Button(String.valueOf(i));
b[i].setBounds(x+50,y+50,20,20);
x +=30;
add(b[i]);
b[i].addActionListener(this);
}
String[] s={"+","-","*","/"};
int j=0;
int u=0;
int v=150;
for(int i=10;i<14;i++)
{
b[i]=new Button(s[j++]);
b[i].setBounds(u+50,v+50,20,20);
add(b[i]);
u+=30;
b[i].addActionListener(this);
}
eq.addActionListener(this);
eq.setBounds(110,150,20,20);
add(eq);
cl.addActionListener(this);
cl.setBounds(140,150,20,20);
add(cl);
add(t);
setSize(300,300);
}
public void actionPerformed(ActionEvent e)
{
for(int i=0;i<10;i++)
{
if(e.getSource()==b[i])
{
t.setText(t.getText()+b[i].getLabel());
}
}
for(int i=10;i<14;i++)
{
if(e.getSource()==b[i])
{
Op=b[i].getLabel();
d=Integer.parseInt(t.getText());
t.setText("");
}
}
if(e.getSource()==eq)
{ int r=0;
n=Integer.parseInt(t.getText());
switch(Op)
{
case "+": r=d+n;
break;
case "-": r=d-n;
break;
case "*": r=d*n;
break;
case "/": r=d/n;
break;
}
t.setText(String.valueOf(r));
}
if(e.getSource()==cl)
{
t.setText("");
}
}
public void paint(Graphics g)
{ Image p=getImage(getDocumentBase(),"23.jpg");
g.drawImage(p, 0, 0, this);
g.setFont(new Font("",Font.TYPE1_FONT,25));
g.drawString("By Dishant",50, 280);
}
}
Output::
Subscribe to:
Posts (Atom)