-->

Friday, December 19, 2014

How to run Applet in Netbean IDE

We are very familiar with java programming, when we come to applet programming then we need some resources like browsers, AppletViewer etc to run the applet code. When i run the applet code in command prompt using following command:
appletviewer filename.html
 Applet viewer was not appear in windows 8.1. Then lastly i was decide that i shall install Netbean IDE for applet code.

import java.awt.*;
 import java.applet.*;

public class design extends Applet
 {
 public void paint(Graphics g)
{
g.drawString("Hello World",50,100);
}
}

Now, copy this code and following some instructions which is given in the youtube video

Thursday, December 4, 2014

HTML applet tag and their attributes

Applet is a tag in html that is used to create an applet window or applet in an html document.
  Example
<!DOCTYPE html>
<html>
<head>
<title>HTML applet Tags and their attributes</title>
</head>
<body>
<applet code="classname.class" width="300" height="200">
</applet>
</body>
</html>

  Applet tag has following attributes

  Code : This attribute takes the class name of the applet code that is to be displayed . Class is the compiled code for applet
  e.g.   <applet code="abc.class" width="200" height="200" />

  Height : This attribute takes values in pixels to define the height of the applet.

  Width : This attribute takes values in pixels to define the width of the applet.

  Vspace : This attribute takes values in pixels to specify how much space is to be left above and below the object.

  Hspace : This attribute takes values in pixels to specify how much space is to be left to the right and left of the object.

  Align  : This attribute is used to align the object in the applet.

  Title : This attribute takes a string in input which is a title name or short information about the applet. This information is shown as a tooltip which pops when the move is brought over the applet.


Example
<!DOCTYPE html>
<html>
<head>
<title>Example of Line in the applet</title>
</head>
<body>
<applet code="designline.class" width="300" height="200">
</applet>
</body>
</html>

Here is the designline.java file:
import java.applet.*;
import java.awt.*;

public class designline extends Applet
{
 public void paint (Graphics gh)
   {
      gh.drawLine(10,10,200,200);
   }
}

Tuesday, November 11, 2014

How to draw rectangle in applet

Four coordinate are required For drawing the rectangle in the java applet. First two coordinate define the origin point of the rectangle. Origin point start from upper left corner and further x-coordinate increases width of the rectangle in right side and y-coordinate increases height of the rectangle in downward.

Syntax of drawRect in Java Applet

Graphics_Instance . drawRect(int X1, Int Y1, int Width, int Height);

If you want to set border color of the rectangle then use setColor( ) method of Graphics class, which is exist in java.awt package.

Example - designline.java

import java.awt.*;
import java.applet.*;
public class designline extends Applet
{
int width, height;

   public void init() {
   
      setBackground( Color.gray);
   }

   public void paint( Graphics g ) {

   

      g.setColor( Color.red );
      g.drawRect( 11, 22, 101, 50 );
}
}
First to compile the code and create the class file for this
First to compile the code and create the class file for this
Prepare the HTML file in the same location with <applet> tag. Like

<applet code="designline" width="400" height="400" />

Save the .html file in same location also run in any browser.

How to draw rectangle in applet

How to draw Line in Applet

Four coordinate are required For drawing the line in the java applet. First two coordinate define the origin point of the line. Origin point start from upper left corner and further x-coordinate increase in right side and y-coordinate increase downward.

Syntax of drawLine in Java Applet

Graphics_Instance . drawLine(int X1, Int Y1, int X2, int Y2);

If you want to set color on line then use setColor( ) method of Graphics class, which is exist in java.awt package.

Example - designline.java

import java.awt.*;
import java.applet.*;
public class designline extends Applet
{
int width,height;
public void init()
{
setBackground(Color.black);

}
public void paint(Graphics g)
{

g.setColor(Color.green);
g.drawLine(0,0,200,200);
}
}

Compilation of Applet code and generate the class file

Compilation of Applet code and generate the class file

Prepare the HTML file in the same location with <applet> tag. Like

<applet code="designline" width="400" height="400" />

Save the .html file in same location also run in any browser.

Code Generate the following output

How to draw Line in Applet

Using the init ( ) method, you can set the back ground color of the applet. Also set the line color using the graphics class. 
© Copyright 2013 Computer Programming | All Right Reserved