Pages

Ads 468x60px

Showing posts with label Applet. Show all posts
Showing posts with label Applet. Show all posts

Monday, 17 December 2012

mouse events along with seperate 2k10 set3 pragram



16.WAJP for handling mouse events.
Program:
                                        Download link for mouse events along with 2k10 set-3 program
import java.awt.*;

import java.awt.event.*;

import java.applet.*;

/*<applet code="mouse.class" height=800 width=800>
 </applet>*/

public class mouse extends Applet implements MouseListener,MouseMotionListener
{
  String msg;
 
  int mousex=0,mousey=0;
 
  public void init()
  {
   addMouseListener(this);
  
   addMouseMotionListener(this);
  }
 
  public void mouseClicked(MouseEvent m)
  {
    mousex=0;
   
    mousey=0;
   
    msg="mouse clicked";
   
    repaint();
  }
 
  public void mouseReleased(MouseEvent m)
  {
    mousex=m.getX();
   
    mousey=m.getY();
   
    msg="up";
   
    repaint();
  }
 
  public void mouseEntered(MouseEvent m)
  {
   mousex=m.getX();
  
   mousey=m.getY();
  
   msg="mouse entered";
  
   repaint();
  }
 
  public void mouseExited(MouseEvent m)
  {
   mousex=m.getX();
  
   mousey=m.getY();
  
   msg="mouse exited";
  
   repaint();
  }
 
  public void mousePressed(MouseEvent m)
  {
   mousex=m.getX();
  
   mousey=m.getY();
  
   msg="mouse pressed";
  
   repaint();
  }
 
  public void mouseDragged(MouseEvent m)
  {
   mousex=m.getX();
  
   mousey=m.getY();
  
   msg="mouse dragged";
  
   repaint();
  }
 
  public void mouseMoved(MouseEvent m)
  {
   mousex=m.getX();
  
   mousey=m.getY();
  
   showStatus("moving at:"+mousex+","+mousey);
  }
 
  public void paint(Graphics g)
  {
    g.drawString(msg,mousex,mousey);
  }
}     


Run process:-

1- develop the applet code(.java)

2-compile the applet code(.class)

3-write the basic HTML structure format

4-develop the APPLET tag for the applet

5-insert the APPLET tag in HTML code

6-run it using appletviewer (appletviewer ______.htmlfile) or

                       double clicking on (.htmlfile) you created.





Applet to display ovals rectangles and lines



20.Write an Applet that displays the content of a file.
Program:
                                       Download link to applet to display ovals and lines
/*<applet code="Lines.class"height=500 width=500>
</applet>*/
import java.awt.*;
import java.applet.Applet;
  class Lines extends Applet
{
public void paint(Graphics g)
{
g.drawLine(10,10,50,50);
g.drawRect(10,60,40,30);
g.fillRect(60,10,30,80);
g.drawRoundRect(10,100,80,50,10,10);
g.drawLine(100,10,230,140);
g.drawLine(100,140,230,10);
g.drawOval(20,20,200,120);
g.setColor(Color.green);
g.fillOval(70,30,100,100);
}
}   

Html code:
<html>
<body>
<applet code="Lines.class"height=500 width=500>
</applet>
</body>
</html>

Run process:-
1- develop the applet code(.java)
2-compile the applet code(.class)
3-write the basic HTML structure format
4-develop the APPLET tag for the applet 
5-insert the APPLET tag in HTML code 
6-run it using appletviewer (appletviewer ______.html) or 
                       double clicking on (.htmlfile) you created.





 

Sample text

Sample Text

Sample Text