skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

  • Home
 
  • RSS
  • Twitter
Tuesday, August 7, 2012

Java applet to display sildeshow to images from a given folder

Posted by Admin at 1:43 PM – 0 comments
 
Java applet to display sildeshow to images from a given folder in thumbnail form, images can be selected one by one and can be enable/disable slideshow of images. The thumbnail images are placed in slides folder, the download button(rectangle) downloads the images from the web server, hence a webserver is required eg : any webserver even tomcat webserver with download folder with images*/

Requirements
1. Name of java file : Sildeshow.java
2. Name of images folder : slides
3. Names of images 1.jpg, 2.jpg and so on upto 8.jpg.
3. Name of download folder in webserver : download
4. Download images given below and paste them in slides folder :
1.jpg │2.jpg │3.jpg │4.jpg │5.jpg │6.jpg │7.jpg │8.jpg
5. Download images given below and paste them in download folder in webserver :
1.jpg │ 2.jpg │ 3.jpg │4.jpg │5.jpg │6.jpg │7.jpg │8.jpg

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class Slideshow extends Applet implements Runnable {
 // Variable Declaration
 Thread runner;
 boolean left,right,click,auto;
 boolean but0,but1;
 boolean b0,b1;
 boolean waitMessage = true;
 String str_desc[] = { // Display Messages
  " This is an Abstract piece.Painted on:20/11/86.",
  " This picture is an Abstract work.Painted on:10/1/89.",
  " This picture is a Canvas oil painting (15/8/92).",
  " This is a Pastel painting (2/10/99).",
  " This picture is an Abstract piece.Painted on:6/5/03.",
  " This is a Brush painting (2/6/05).",
  " This a painted collage (30/1/83).",
  " This is my Graphical art piece.Painted on:20/12/08."};
 int number=1;
 static final int MAX=8;
 Image Picture[]=new Image[MAX]; // Image variable
 Image Buffer;
 Graphics gBuffer; // Graphics Variable
 Font a = new Font("Helvetica", Font.PLAIN,12);
 Font b = new Font("Dialog", Font.PLAIN,10);
 Font c = new Font("Helvetica", Font.BOLD,13);
 Rectangle r0=new Rectangle(400,70,50,20); // ON / OFF
 Rectangle r1=new Rectangle(400,195,120,20); // Click Here
 
 void loadGraphics() { //
  Track the status of a number of media objects
  MediaTracker t=new MediaTracker(this);
  for(int i=0;i< MAX;i++) {
    // Load an image in an applet
   Picture[i]=getImage(getCodeBase(),"slides/"+(i+1)+".jpg");
   t.addImage(Picture[i],0);
   try{
    t.waitForAll(0);
   } catch(InterruptedException e) {
   
   }
   waitMessage=false;
  }
 }

 public void init() {
  // Creates an image
  Buffer=createImage(size().width,size().height);
  gBuffer=Buffer.getGraphics();
  // Creates a graphics context for this component
 }

 public void start() {
  if (runner == null) {
   runner = new Thread (this);
   runner.start();
  }
 }
 
 public void stop() {
  if (runner != null) {
   runner.stop();
   runner = null;
  }
 }
 
 public void run() {
  while(true) {
   try {
    runner.sleep(2500);
   } catch (Exception e) { }
   if(auto) {
    if(number< MAX)
    number++;
    else
    number=1;
   }
   repaint();
  }
  }
  
 public void update(Graphics g){ paint(g); }
 
 public void drawArrow(int w,int h,int x,int y,boolean left,boolean over,boolean click) {
  if(click&&over) // set color to yellow on click or mouse over
   gBuffer.setColor(Color.yellow);
  else if(over) // set color to orange on mouse over
   gBuffer.setColor(Color.orange);
  else
  // set color to red on click
   gBuffer.setColor(Color.red);
  if(left) {
   int al[] = {x,x+w,x+w};
   int bl[] = {y+h/2,y,y+h};
   gBuffer.fillPolygon(al, bl, 3);
  } else {
   int ar[] = {x,x,x+w};
   int br[] = {y,y+h,y+h/2};
   gBuffer.fillPolygon(ar, br, 3);
  }
 }

 public void drawPanel() {
  gBuffer.setColor(Color.white);
  gBuffer.fillRect(0,0,size().width,size().height);
  // Display Text
  drawArrow(40,40,330+70,120,true,left,click);
  // Display Left Arrow
  drawArrow(40,40,380+70,120,false,right,click);
  // Display Right Arrow
  gBuffer.setColor(Color.lightGray);
  gBuffer.setFont(b);
  gBuffer.setColor(auto?Color.orange:Color.lightGray);
  gBuffer.fill3DRect(400,70,50,20,!but0);
  // Rectangle for ON rectangle
  gBuffer.setColor(b0?Color.red:Color.black);
  // Color For ON rectangle
  String s=auto?"OFF":"ON";
  gBuffer.drawString(s,410,85);
  gBuffer.setColor(Color.lightGray);
  // Download
  s="Click Here";
  gBuffer.fill3DRect(400,190,120,20,!but1);
  gBuffer.setFont(a);
  gBuffer.setColor(b1?Color.red:Color.black);
  gBuffer.drawString(s,430,205);
  // Display Image
  gBuffer.drawImage(Picture[number-1],20,20,this);
  gBuffer.setColor(Color.black);
  gBuffer.setFont(c);
  gBuffer.drawString("Slideshow:",300,80);
  gBuffer.drawString("Scroll:",300,140);
  gBuffer.drawString("Download it!",300,200);
  gBuffer.drawString("Description:",300,35);
  gBuffer.setFont(a);
  gBuffer.drawString(str_desc[number-1],300,50);
 }

 public boolean mouseDown(Event evt,int x,int y) {
  if(r0.inside(x,y)) {
   but0=true; auto^=true;
  }
  if(r1.inside(x,y))
  {
  but1=true;
  auto=false;
  }
  if(but1)
  {
  String link ="http://localhost:8080/download/"+number+".jpg";
  try {
  // corresponds to an applet's environment
  AppletContext a = getAppletContext();
  URL url = new URL(link);
  // url of the image to be downloaded
  a.showDocument(url,"_blank");
  }
  catch (MalformedURLException e){
  System.out.println(e.getMessage());
  }
  }
  if(left)
  {
  auto=false;
  if(number>1)
  number--;
  else number=8;
  }
  if(right)
  {
  auto=false;

  if(number< MAX)
  number++;
  else
  number=1;
  }
  click=true;
  repaint();
  return true;
  }
 
 public boolean mouseUp(Event evt,int x,int y) {
  but0=but1=click=false;
  repaint();
  return true;
 }

 public boolean mouseMove(Event evt,int x,int y)  {
  Rectangle rl=new Rectangle(330+70,120,40,40);
  Rectangle rr=new Rectangle(380+70,120,40,40);
  if(rl.inside(x,y))
   left=true;
  else
   left=false;
  
  if(rr.inside(x,y))
   right=true;
  else
   right=false;
  
  if(r0.inside(x,y))
   b0=true;
  else
   b0=false;
  
  if(r1.inside(x,y))
   b1=true;
  else
   b1=false;
  repaint();
  return true;
 }
 
 public void paint(Graphics g) {
  if(waitMessage) { 
   g.setColor(Color.blue);
   g.drawString("Loading images, please wait...",200,100);
   loadGraphics();
  } else {
   drawPanel();
   g.drawImage (Buffer,0,0, this);
  }
 }
}

Labels: JAVA Applet , Slideshow Email This BlogThis! Share to Twitter Share to Facebook

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )

List of Java Programs

  • Java Program to check Greater between the Two Number
  • Java Program to find that given number is Palindrome or not
  • Java Program to Demonstrate the Use of Pre and Post Operator
  • Java Program to Reverse the Given Number
  • Java Program to Print Number in the Given Data Type
  • Program to Demonstrate Skipping using Continue
  • Program to find whether entered character is a vowel or Consonant
  • Java Program to Calculate the Sum of Digits of Given Number
  • How to swap two numbers using only two variables
  • Checking the Given Number is Armstrong or Not
  • Average an Array of Values
  • Display ASCII Code Instead of Character
  • Comparison of Two Variable using If
  • Printing Table In java using While Loop
  • Generate Random Number Using Math.Random Function
  • To Find roots of Quadratic Equation
  • Performing Arithmetic Opration on Two Variable
  • Concatenation of Two String in Java
  • Command Line Argument in JAVA
  • Java Hello World Program
  • Calculate Circle Perimeter | Java Program
  • Calculate the Area of Circle | Java Program
  • To Find Whether Given Year is a Leap Year or not
  • Popular
  • Recent
  • Archives

Total Pageviews

Sparkline

Followers

Popular Posts of This Week

  • Java Class to Calculate the Volume of Box
    Here is a Java Class to Calculate the Volume of Box. class Box { double width; double height; double depth; // This is the con...
  • Demonstrate if-else-if statements by displaying Season
    Here is a Java Program to Demonstrate if-else-if statements class IfElse { public static void main(String args[]) { int month = 4; ...
  • Java class that defines an integer stack that can hold 10 values
    Here is a Java class that defines an integer stack that can hold 10 values. class Stack { int stck[] = new int[10]; int tos; // ...
  • Password Encryption Decryption using PBE With MD5 And DES algorithm in java
    In Some applications, at User registration time, we need to Encrypt the password field and then store into the database. After that ...
  • Conversion of Numeric Amount to Words
    This java program will spell the numeric amount in words /** * AmountToWordConverter is used to convert the given amount string into wor...
  • UDP Client Server Communication using Java
    UDP uses a simple transmission model without implicit handshaking dialogues for providing reliability, ordering, or data integrity. Here ...
  • Convert TEXT to PDF file using Java
    To create a PDF file from the TEXT file using Java. The Text file withe path is given as input and the created PDF will be saved in the same...
  • Prevent Concurrent Logins from the Same UserID
    This code snippet mainly addresses the problem of Implementation to avoid Concurrent Logins from the Same User ID in Java. This is implem...
  • Define a class to represent a weight in tons, kilograms, and grams | Java Program
    Define a class, tkgWeight, to represent a weight in tons, kilograms, and grams and Demonstrate this class by creating and combining some cl...
  • Java Program to Demonstrate Simple example of Inheritance
    This is a Simple example of Inheritance. It is a Super Class that will be Extended later in Example class A { int i, j; void show...
Powered by Blogger.

Archives

  • ►  2014 ( 4 )
    • ►  August ( 4 )
  • ►  2013 ( 6 )
    • ►  August ( 1 )
    • ►  April ( 5 )
  • ▼  2012 ( 673 )
    • ►  November ( 9 )
    • ►  October ( 223 )
    • ►  September ( 272 )
    • ▼  August ( 2 )
      • Java applet to display sildeshow to images from a ...
      • JDK Version 7.0 VS JDK Version 6.0
    • ►  June ( 1 )
    • ►  February ( 67 )
    • ►  January ( 99 )
 

Our Blogs

  • Linux Tutorial
  • C Programming Tutorial

Labels

  • Agile Methodology ( 1 )
  • Algorithm ( 3 )
  • AntiSamy ( 1 )
  • Arithmetic Operation ( 1 )
  • Array Example ( 9 )
  • ArrayList Examples ( 11 )
  • Average an Array of Values ( 1 )
  • Barcode Example ( 1 )
  • Basic Java Programs ( 34 )
  • Bing API Example ( 2 )
  • BitSet Example ( 1 )
  • Boolean Example ( 1 )
  • Bouncy Castle API ( 1 )
  • Break Statement ( 2 )
  • BufferedReader Example ( 2 )
  • Calendar Example ( 1 )
  • Chart Generation Example ( 1 )
  • Command Line Argument ( 1 )
  • Comparator Example ( 1 )
  • Concatenation of String ( 1 )
  • Continue Statement ( 1 )
  • Control Structure ( 1 )
  • Copy File Example ( 1 )
  • CRC Example ( 1 )
  • CSV Example ( 6 )
  • Data Structure ( 5 )
  • Date Example ( 2 )
  • Directory Example ( 1 )
  • Do - While Loop Example ( 1 )
  • Domino Database ( 1 )
  • Email Example ( 8 )
  • Encryption Example ( 3 )
  • Excel Example ( 15 )
  • Factorial Example ( 1 )
  • File Upload Example ( 1 )
  • Find Roots of Quadratic Equation ( 1 )
  • FTP Example ( 2 )
  • Graph Examples ( 1 )
  • Greater between Two Numbers ( 1 )
  • GSON Library ( 1 )
  • HashMap Example ( 1 )
  • HashSet Example ( 1 )
  • Hello World Program ( 1 )
  • If Condition ( 2 )
  • Inner Class Example ( 1 )
  • iText Example ( 3 )
  • JAR File ( 1 )
  • JAVA Applet ( 1 )
  • Java Applications ( 1 )
  • Java AWT Example ( 9 )
  • Java Certification ( 1 )
  • Java Class Examples ( 15 )
  • Java Collection Example ( 1 )
  • Java Command Example ( 4 )
  • Java Constructor Examples ( 1 )
  • Java Currency Example ( 1 )
  • Java Database Example ( 3 )
  • Java Date and Time Example ( 3 )
  • Java DateFormat Example ( 3 )
  • Java Examples ( 2 )
  • Java Exception Example ( 5 )
  • Java File Example ( 22 )
  • Java GUI Example ( 1 )
  • Java Image Examle ( 3 )
  • Java Inheritance Example ( 3 )
  • Java Input Output Example ( 1 )
  • Java IO Example ( 3 )
  • Java Jar Example ( 1 )
  • Java JSON Example ( 3 )
  • Java Mail Examples ( 4 )
  • Java Map Example ( 5 )
  • Java MapReduce Example ( 2 )
  • Java MultiThreading Example ( 7 )
  • Java Network Example ( 9 )
  • Java Package ( 1 )
  • Java Programs ( 1 )
  • Java RMI ( 1 )
  • Java Robot Class Examples ( 2 )
  • Java Runtime Example ( 1 )
  • Java Swing Example ( 9 )
  • Java Util Example ( 1 )
  • Java Vector Example ( 4 )
  • Java Voice Example ( 1 )
  • Java Webservice Example ( 1 )
  • Java XML Example ( 3 )
  • Java Zip Class Examples ( 2 )
  • JDBC ( 9 )
  • JDK Version Comparison ( 1 )
  • JFrame Example ( 3 )
  • JOptionPane Dialog Example ( 1 )
  • JPanel Example ( 1 )
  • JSP Example ( 2 )
  • JSTL Example ( 1 )
  • jUnit Example ( 2 )
  • LinkedList Example ( 2 )
  • List Example ( 1 )
  • Long Variable ( 1 )
  • Lottery Nubmer ( 1 )
  • MD5 Hashing Example ( 3 )
  • Memory Management Example ( 1 )
  • Method Override ( 1 )
  • MIDI Sound ( 8 )
  • Module Operator Example ( 2 )
  • Multiplication Table ( 1 )
  • Observer Interface Example ( 1 )
  • Operator Example ( 5 )
  • Pagination ( 1 )
  • Palindrome Number ( 1 )
  • Pass By Reference Example ( 1 )
  • Pass By Value Example ( 1 )
  • PDF File Example ( 3 )
  • PDF Generation Example ( 4 )
  • Pre and Post Operator ( 2 )
  • Prime Number ( 3 )
  • Progress Bar Example ( 1 )
  • Property List Example ( 2 )
  • Random Function ( 7 )
  • Recursion Example ( 2 )
  • Regex Example ( 2 )
  • Remote Host Example ( 2 )
  • Robot Class ( 4 )
  • Searching Example ( 3 )
  • Slideshow ( 1 )
  • Sorting Example ( 7 )
  • SpringLayout Example ( 1 )
  • Stack Example ( 4 )
  • Static Variable ( 1 )
  • StreamTokenizer Example ( 2 )
  • String Example ( 19 )
  • Struts2 Example ( 1 )
  • Sum of Digits ( 1 )
  • Swap Two Numbers ( 1 )
  • Switch Case ( 3 )
  • Tapestry Components ( 1 )
  • Thumbnail Example ( 2 )
  • TimerTask Example ( 2 )
  • To Calculate Volume ( 1 )
  • To Check Armstrong Number ( 1 )
  • Tree Example ( 1 )
  • TreeMap Example ( 1 )
  • TreeSet Example ( 1 )
  • Two Dimensional Array Example ( 1 )
  • UUID ( 1 )
  • Validation Example ( 2 )
  • Variable Casting ( 1 )
  • While Loop ( 1 )
  • XML Parsing ( 7 )
  • XSS Attacks ( 1 )
  • Zip File ( 15 )

Popular Posts

  • Java Class to Calculate the Volume of Box
    Here is a Java Class to Calculate the Volume of Box. class Box { double width; double height; double depth; // This is the con...
  • UDP Client Server Communication using Java
    UDP uses a simple transmission model without implicit handshaking dialogues for providing reliability, ordering, or data integrity. Here ...
  • Run Excel Macro from Java
    This is a java code snippet which will run VB script (.vbs file) which in turn will run an excel macro. 1. The excel macro called "...
  • Excel report generator based on the Input provided through an xml file
    This tool can generate one or more xls report based on the input provided inside a xml file. import javax.xml.parsers.DocumentBui...
  • Remove Duplicate Rows in Excel using Java
    This is a reusable code written in Java with a simple Standalone program. User can just run this program with the two command line arguments...
  • Java Program to Generate the Lottery Number between 1 to 49
     A lottery requires that you select six different numbers from the integers 1 to 49. Write a program to do this for you and generate five s...
  • Connecting Sybase using JDBC
    This is a java code snippet which can be used to connect Sybase database using JDBC driver (SybDriver). Jconnect is the name of the packag...
  • SPLIT HUGE FILES INTO SMALL TEXT FILES
    This code snippet is used for automatic splitting of files conatining large content into smaller text files with specific number of recor...
  • Convert TEXT to PDF file using Java
    To create a PDF file from the TEXT file using Java. The Text file withe path is given as input and the created PDF will be saved in the same...
  • Java Program to display the sign of the Zodiac corresponding to a Birth Date
    Write a program to display the sign of the Zodiac corresponding to a birth date entered through the keyboard. import java.io.BufferedRea...
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger