Applet with parameters : Applet « Swing JFC « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Swing JFC » AppletScreenshots 
Applet with parameters
   
//File: applet.html
/*
<applet code="ColorScribble.class"
  codebase="."
  width=400 height=400>
  <param name="foreground" value="FF0000">
  <param name="background" value="CCFFCC">
</applet>

*/

/*
 * Copyright (c) 2000 David Flanagan.  All rights reserved.
 * This code is from the book Java Examples in a Nutshell, 2nd Edition.
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
 * You may study, use, and modify it for any non-commercial purpose.
 * You may distribute it non-commercially as long as you retain this notice.
 * For a commercial use license, or to purchase the book (recommended),
 * visit http://www.davidflanagan.com/javaexamples2.
 */

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

/**
 * A version of the Scribble applet that reads two applet parameters to set the
 * foreground and background colors. It also returns information about itself
 * when queried.
 */
public class ColorScribble extends Applet{
  // Read in two color parameters and set the colors.
  public void init() {
    Color foreground = getColorParameter("foreground");
    Color background = getColorParameter("background");
    if (foreground != null)
      this.setForeground(foreground);
    if (background != null)
      this.setBackground(background);
  }

  public void paint(Graphics g) {
    g.setColor(getForeground());
    g.drawString("Parameter",1010 );

  }

  // Read the specified parameter. Interpret it as a hexadecimal
  // number of the form RRGGBB and convert it to a color.
  protected Color getColorParameter(String name) {
    String value = this.getParameter(name);
    try {
      return new Color(Integer.parseInt(value, 16));
    catch (Exception e) {
      return null;
    }
  }

  // Return information suitable for display in an About dialog box.
  public String getAppletInfo() {
    return "ColorScribble v. 0.03.  Written by David Flanagan.";
  }

  // Return info about the supported parameters. Web browsers and applet
  // viewers should display this information, and may also allow users to
  // set the parameter values.
  public String[][] getParameterInfo() {
    return info;
  }

  // Here's the information that getParameterInfo() returns.
  // It is an array of arrays of strings describing each parameter.
  // Format: parameter name, parameter type, parameter description
  private String[][] info = {
      "foreground""hexadecimal color value""foreground color" },
      "background""hexadecimal color value""background color" } };
}


           
         
    
    
  
Related examples in the same category
1.Icon Demo Applet
2.Socket Applet
3.Applet Socket Quote
4.Applet Print
5.Applet System Properties
6.Applet Sound
7.Show Document
8.Applet communication (talk to each other)
9.Get Applets
10.JDBC applet
11.An application and an appletAn application and an applet
12.Applet and Swing ComponentsApplet and Swing Components
13.Icon behavior in JbuttonsIcon behavior in Jbuttons
14.Signed Applet
15.Load resource in Applet
16.Scribble AppletScribble Applet
17.Toggle buttonToggle button
18.Bouncing CircleBouncing Circle
19.Applet Menu Bar Demo
20.Applet clock demoApplet clock demo
21.Applet event testerApplet event tester
22.First applet
23.AppletViewer - a simple Applet Viewer program
24.A simple loan calculator appletA simple loan calculator applet
25.URLButton -- a Button-like object that jumps to a URL
26.Get list of APPLET tags in one HTML file
27.Demonstration of Applet Methods
28.Demonstrates getParameterInfo() and getAppletInfo()
29.Walking Text Demo
30.Java Applets Can Run CGI's (on some browsers)
31.Demo Choice Applet
32.Demo Applet: Connect to Legacy System
33.ShowDocApplet: try out showDocument()
34.Bookmarks
35.Java Wave Applet Demo
36.Slide Puzzle
37.A class to allow use of the ncsa ISMAP format in java applets
38.Image Loader Applet
39.Thread Race Applet
40.Applet: Print from an Applet
41.Calling methods of an Applet from JavaScript code
42.Read an applet parameters
43.Change an applet background color
44.Passing Parameters to Java Applet
45.Display message in browser status bar
46.Your own Applet runtime environment
47.This applet is a simple button that plays an audio clip when pushed
48.EventQueue.invokeLater and JApplet
49.An applet component that draws a bar chart
50.This applet displays a greeting from the authors
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.