0N/A/*
3851N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
4378N/A/*
4378N/A * This source code is provided to illustrate the usage of a given feature
4378N/A * or technique and has been deliberately simplified. Additional steps
4378N/A * required for a production-quality application, such as security checks,
4378N/A * input validation and proper error handling, might not be present in
4378N/A * this sample code.
4378N/A */
4378N/A
4378N/A
0N/A
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.Font;
0N/Aimport java.applet.Applet;
3851N/Aimport java.awt.event.MouseEvent;
3851N/Aimport java.awt.event.MouseListener;
3851N/A
0N/A
0N/A/**
0N/A * An applet that displays jittering text on the screen.
0N/A *
0N/A * @author Daniel Wyszynski 04/12/95
3851N/A * @author 05/09/95 kwalrath Changed string; added thread suspension
3851N/A * @author 02/06/98 madbot removed use of suspend and resume and cleaned up
0N/A */
3851N/A@SuppressWarnings("serial")
3851N/Apublic class NervousText extends Applet implements Runnable, MouseListener {
0N/A
0N/A String banner; // The text to be displayed
0N/A char bannerChars[]; // The same text as an array of characters
0N/A char attributes[]; // Character attributes ('^' for superscript)
0N/A Thread runner = null; // The thread that is displaying the text
0N/A boolean threadSuspended; // True when thread suspended (via mouse click)
0N/A static final int REGULAR_WD = 15;
0N/A static final int REGULAR_HT = 36;
0N/A static final int SMALL_WD = 12;
0N/A static final int SMALL_HT = 24;
0N/A Font regularFont = new Font("Serif", Font.BOLD, REGULAR_HT);
0N/A Font smallFont = new Font("Serif", Font.BOLD, SMALL_HT);
0N/A
3851N/A @Override
0N/A public void init() {
0N/A banner = getParameter("text");
0N/A if (banner == null) {
0N/A banner = "HotJava";
0N/A }
0N/A
0N/A int bannerLength = banner.length();
3851N/A StringBuilder bc = new StringBuilder(bannerLength);
3851N/A StringBuilder attrs = new StringBuilder(bannerLength);
0N/A int wd = 0;
0N/A for (int i = 0; i < bannerLength; i++) {
0N/A char c = banner.charAt(i);
0N/A char a = 0;
0N/A if (c == '^') {
0N/A i++;
0N/A if (i < bannerLength) {
0N/A c = banner.charAt(i);
0N/A a = '^';
0N/A wd += SMALL_WD - REGULAR_WD;
0N/A } else {
0N/A break;
0N/A }
0N/A }
0N/A bc.append(c);
0N/A attrs.append(a);
0N/A wd += REGULAR_WD;
0N/A }
0N/A
0N/A bannerLength = bc.length();
3851N/A bannerChars = new char[bannerLength];
0N/A attributes = new char[bannerLength];
0N/A bc.getChars(0, bannerLength, bannerChars, 0);
0N/A attrs.getChars(0, bannerLength, attributes, 0);
0N/A
0N/A threadSuspended = false;
0N/A resize(wd + 10, 50);
0N/A addMouseListener(this);
0N/A }
0N/A
3851N/A @Override
0N/A public void destroy() {
0N/A removeMouseListener(this);
0N/A }
0N/A
3851N/A @Override
0N/A public void start() {
0N/A runner = new Thread(this);
0N/A runner.start();
0N/A }
0N/A
3851N/A @Override
0N/A public synchronized void stop() {
0N/A runner = null;
0N/A if (threadSuspended) {
0N/A threadSuspended = false;
0N/A notify();
0N/A }
0N/A }
0N/A
3851N/A @Override
0N/A public void run() {
0N/A Thread me = Thread.currentThread();
0N/A while (runner == me) {
0N/A try {
0N/A Thread.sleep(100);
3851N/A synchronized (this) {
0N/A while (threadSuspended) {
0N/A wait();
0N/A }
0N/A }
3851N/A } catch (InterruptedException e) {
0N/A }
0N/A repaint();
0N/A }
0N/A }
0N/A
3851N/A @Override
0N/A public void paint(Graphics g) {
0N/A int length = bannerChars.length;
0N/A for (int i = 0, x = 0; i < length; i++) {
0N/A int wd, ht;
0N/A if (attributes[i] == '^') {
0N/A wd = SMALL_WD;
0N/A ht = SMALL_HT;
0N/A g.setFont(smallFont);
0N/A } else {
0N/A wd = REGULAR_WD;
0N/A ht = REGULAR_HT;
0N/A g.setFont(regularFont);
0N/A }
0N/A int px = (int) (10 * Math.random() + x);
0N/A int py = (int) (10 * Math.random() + ht);
0N/A g.drawChars(bannerChars, i, 1, px, py);
0N/A x += wd;
0N/A }
0N/A }
0N/A
3851N/A @Override
0N/A public synchronized void mousePressed(MouseEvent e) {
0N/A e.consume();
0N/A threadSuspended = !threadSuspended;
3851N/A if (!threadSuspended) {
0N/A notify();
3851N/A }
0N/A }
0N/A
3851N/A @Override
0N/A public void mouseReleased(MouseEvent e) {
0N/A }
0N/A
3851N/A @Override
0N/A public void mouseEntered(MouseEvent e) {
0N/A }
0N/A
3851N/A @Override
0N/A public void mouseExited(MouseEvent e) {
0N/A }
0N/A
3851N/A @Override
0N/A public void mouseClicked(MouseEvent e) {
0N/A }
0N/A
3851N/A @Override
0N/A public String getAppletInfo() {
3851N/A return "Title: NervousText\nAuthor: Daniel Wyszynski\n"
3851N/A + "Displays a text banner that jitters.";
0N/A }
0N/A
3851N/A @Override
0N/A public String[][] getParameterInfo() {
0N/A String pinfo[][] = {
3851N/A { "text", "string", "Text to display" }, };
0N/A return pinfo;
0N/A }
0N/A}