Friday, 19 June 2015

Analog Clock program in java

1]. Seconds hand completes 360 degrees in 1 minute.
2]. Minute hand completes 360 degrees in 1 hour.
3]. Hour hand completes 360 degrees in 12 hours.
4]. Set of points traced by circle is given by :
                                                        x=cx+r*angle; y=cy+r*angle;
# (cx,cy)=coordinates of centre of circle.
# r= radius.
                                      => i.e path traced by minute and seconds hands in same.

                                      =>Where as hour hand cover 5 degrees when minute hand sweeps 360 degrees.(360/5=12 used in looping).





                                                                                      ......................HAPPY CODING

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Random;
public class WallClock extends Applet implements Runnable {
Thread ct= null ;
int cx=330,cy=230,rs=100,rm=75,rh=55,pxs,pys,pxm,pym,pxh,pyh;int  ts=0,tm=0,th=0;float cs,cm,ch;
public void start() {
   if (ct == null) {
     ct = new Thread(this);
     ct.start();}}

 public void run() {
   Thread myThread = Thread.currentThread();
   while (ct == myThread) { repaint(); }  }
public void paint(Graphics g)
{Font f = new Font("MV Boli",Font.ITALIC,30);
    g.setFont(f);
    int R = (int)(Math.random()*256);
    int G = (int)(Math.random()*256);
    int B= (int)(Math.random()*256);
    Color c = new Color(R, G, B);
    g.setColor(c);
g.drawString("ViswaDeep",460,380);

g.setColor(Color.pink);
g.fillOval(200, 100, 260, 260);
g.setColor(Color.orange);
g.drawOval(199, 99, 262, 262);
g.drawOval(198, 98, 264, 264);
g.drawOval(197, 97, 266, 266);
g.drawOval(196, 96, 268, 268);
Font font = new Font("Arial",Font.BOLD,30);
   g.setFont(font);
g.setColor(Color.darkGray);
g.drawString("12", 313, 130);
g.drawString("6", 325, 352);
g.drawString("9", 206, 245);
g.drawString("3", 430, 240);

if(ts%60==0&&ts!=0){tm++;}
cm=(float) (0.105*tm);
pxm = (int) (cx + rm * Math.sin(cm));
pym = (int) (cy - rm * Math.cos(cm));
   g.setColor(Color.red);
g.drawLine(cx, cy, pxm, pym);

if(tm%12==0&&tm!=0){if(ts%60==0&&ts!=0){th++;}}
ch=(float) (0.105*th);
pxh = (int) (cx + rh * Math.sin(ch));
pyh = (int) (cy - rh * Math.cos(ch));
   g.setColor(Color.BLUE);
g.drawLine(cx, cy, pxh, pyh);

cs=(float) (0.105*ts);
pxs = (int) (cx + rs * Math.sin(cs));
pys = (int) (cy - rs * Math.cos(cs));
g.setColor(Color.black);
g.drawLine(cx, cy, pxs, pys);
try {Thread.sleep(1000);} catch (InterruptedException e){ }

ts++;
}
}

Friday, 12 June 2015

Photo Application in java

                             Photo Application in java


1]. Import different photos which you want in photo application.
2]. Place photo name in function getImage(getCodeBase(), "acura.jpg"). where photo name                       is acura.jpg.
3]. Don't forget to add extensions like jpg  to your photo name.


                                                                               ............Happy Coding







*********************************************************************************************************************

import java.applet.Applet;

import java.awt.Button;

import java.awt.Color;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Set;




public class VisuPhotoApp extends Applet implements ActionListener
{
Image i1;
int i=0,k;
  MediaTracker tr;
  Button b1 ,b2,b3;
  
  public void init()
  {   setLayout(null);
  
      b1 = new Button(" SLIDE SHOW ");
  b1.setBounds(650,10,90,30);
      b1.addActionListener(this);
      b1.setBackground(Color.RED);
          b1.setForeground(Color.WHITE);
      add(b1);
      b2 = new Button(" < PRE ");
  b2.setBounds(10,300,70,30);
  b2.addActionListener(this);
      b2.setBackground(Color.green);
  add(b2);
  b3 = new Button(" NEXT >");
  b3.setBounds(1275,300,70,30);
  b3.addActionListener(this);
      b3.setBackground(Color.green);
  add(b3);
 
  }
 
  public void paint(Graphics g) 
  {
     tr = new MediaTracker(this);
     switch (k) 
     {
          case 0: 
         b2.setVisible(false);
     i1 = getImage(getCodeBase(), "acura.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     delay(999999999);
     break;
     
          case 1:
          {
         b2.setVisible(true);b3.setVisible(true);
     i1 = getImage(getCodeBase(), "Audi-RS7.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     //delay(999999999);
     break;
          }
          case 2:
          {
         b2.setVisible(true);b3.setVisible(true);
     i1 = getImage(getCodeBase(), "Audi.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     //delay(999999999);
     break;
          }
          case 3:
          {
         b2.setVisible(true);b3.setVisible(true);
          
     i1 = getImage(getCodeBase(), "honda1.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550,this);
     //delay(999999999);
     break;
          }
          case 4:
          {
         b2.setVisible(true);b3.setVisible(true);
          
     i1 = getImage(getCodeBase(), "Lamborghini-Huracan.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     //delay(999999999);
     break;
          }
          case 5:
          {
         b2.setVisible(true);b3.setVisible(true);
     i1 = getImage(getCodeBase(), "Lamborghini.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     //delay(999999999);
     
          break;
          
          }
          case 6:
          {
         b2.setVisible(true);b3.setVisible(true);
          
     i1= getImage(getCodeBase(), "maybach.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     //delay(999999999);
     break;
          }
          case 7:
          {
         b3.setVisible(false);b2.setVisible(true);
          
     i1= getImage(getCodeBase(), "McLaren.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     break;
          }
          case 8:
          { 
     i1 = getImage(getCodeBase(), "acura.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     delay(999999999);
     i1 = getImage(getCodeBase(), "Audi-RS7.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     delay(999999999);
     i1 = getImage(getCodeBase(), "Audi.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     delay(999999999);
     i1 = getImage(getCodeBase(), "honda1.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550,this);
     delay(999999999);
     i1 = getImage(getCodeBase(), "Lamborghini-Huracan.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     delay(999999999);
     i1 = getImage(getCodeBase(), "Lamborghini.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     delay(999999999);
     i1 = getImage(getCodeBase(), "maybach.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     delay(999999999);
     i1 = getImage(getCodeBase(), "McLaren.jpg");
     tr.addImage(i1,0);
     g.drawImage(i1, 90,50,1180,550, this);
     b3.setVisible(false);
     i=7;
   break;
          }
          }
          
  }
  public void delay(int y)
{
int p;for(p=0;p<y+55;p++)
{}
}
public void actionPerformed(ActionEvent v) {
//Button2.setVisible(false);b1.setVisible(false);
if (v.getSource() == b1) 
{i=8;repaint();}
if (v.getSource() == b2) 
{i--;repaint();}
if (v.getSource() == b3) 
{i++;repaint();}
}