Posts

Showing posts with the label basic example

Get Current Thread Example

/* Get Current Thread Example This Java example shows how to get reference of current thread using currentThread method of Java Thread class. */   public class GetCurrentThreadExample {   public static void main ( String [ ] args ) {   /* * To get the reference of currently running thread, use * Thread currentThread() method of Thread class. * * This is a static method. */   Thread currentThread = Thread . currentThread ( ) ; System . out . println ( currentThread ) ;   } }   /* Output of the example would be Thread[main,5,main] */

Get Applet parameter Example

/* Get Applet parameter Example This java example shows how get the parameter passed to an applet using getParameter() method of Java Applet class. */   import java.applet.Applet ; import java.awt.Graphics ;   /*  * To pass a parameter to an Applet use <param> HTML tag.  * Specify name and value attribute to pass a parameter to an applet like  * given below.  *  * <param name="paramName" value="paramValue"/>  *  * You can pass multiple parameters for an Applet using multiple  * <param> HTML tag.  */   /* <applet code="GetAppletParameterExample" width=200 height=200> <param name="msg" value="This is a parameter example program"/> <param name="xPosition" value="50"/> <param name="yPosition" value="50"/> </applet> */   public class GetAppletParameterExample extends Applet {   public void paint ( Graphics g )...

Basic Java Applet Example

/* Basic Java Applet Example  This Java example shows how to create a basic applet using Java Applet class.  */  import java.applet.Applet;  import java.awt.Graphics;  /*  <applet code = "BasicAppletExample" width = 200 height = 200>  </applet>  */  public class BasicAppletExample extends Applet{  public void paint(Graphics g){  //write text using drawString method of Graphics class  g.drawString("This is my First Applet",20,100);  }  }