Java-Loading Images

Loading Images Basic image handling in java is easy. The java.awt provides Image class. This is used to represent the common behavior of an image. To display an image in your applet. You must load the image into your java program. So you have to tell where to find them. Applet class provides a method … Read more…

Java-GetCodeBase and GetDocumentBase

GetCodeBase and GetDocumentBase You will create applets that will need to explicitly  load media and text. Java will allow the applet to load data from the directory holding the html file that started the applet (the document base) and the directory from which the applet’s class file was loaded (the code base). These directories are … Read more…

Java-GetHeight and GetWidth

GetHeight and GetWidth If you can get the width and height of the applet window through the methods getWidth() and getHeight(). Program Program Source import java.applet.Applet import java.awt.Graphics; public class Javaapp extends Applet{ public void paint(Graphics g) { g.drawString(“Height : “+getHeight()+” Width : “+getWidth(), 10, 10); g.fillOval(30, 30, getWidth()-60, getHeight()-60); } }

Java-Text Moving Animation

Program Program Source import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; import java.awt.Font; public class Javaapp extends Applet implements Runnable{ private String msg = “123456789”; private Thread t; public void start() { t = new Thread(this,”Animation”); t.start(); } public void run() { for(;;) { try{ Thread.sleep(2000); }catch(InterruptedException ex){} msg +=msg.charAt(0); msg = msg.substring(1,msg.length()); repaint(); } } public … Read more…

Java-Stop and Destroy

Stop The stop( ) method is called by the web browser or the appletviewer to suspend the execution of an applet. When a user switches over from a web page that contains the applet to another web page, the execution of that web page will be suspended. Remember that the stop( ) method will be … Read more…

Java-Repaint

Repaint The Repaint( ) method is used to repaint the window. Program Program Source import java.applet.Applet; import java.awt.Graphics; public class Javaapp extends Applet { int i; public void paint(Graphics g) { g.drawString(“i = “+i, 100, 100); try{ Thread.sleep(1000); }catch(InterruptedException ex){} i++; repaint(); } }