8205494: Convert or remove all AWT applet demos

Reviewed-by: serb, erikj
This commit is contained in:
Phil Race 2018-06-22 13:21:23 -07:00
parent 52d487c316
commit 075d860ee6
55 changed files with 0 additions and 10572 deletions

View File

@ -68,55 +68,6 @@ $(eval $(call SetupTextFileProcessing, BUILD_JAVA_MANIFEST, \
@@COMPANY_NAME@@ => $(COMPANY_NAME) , \
))
################################################################################
# Build applet demos.
# Setup make rules for building a demo applet.
#
# Parameter 1 is the name of the rule. This name is used as variable prefix,
# and the targets generated are listed in a variable by that name. It is also
# used to locate the name of the applet subdir, and to determine the name
# of the output directory.
#
# Remaining parameters are named arguments. These include:
# SRC_DIR Alternative source directory to use for the demos.
# DISABLE_SJAVAC Passed to SetupJavaCompilation
SetupBuildAppletDemo = $(NamedParamsMacroTemplate)
define SetupBuildAppletDemoBody
ifeq ($$($1_SRC_DIR), )
$1_SRC_DIR := $(DEMO_SHARE_SRC)/applets
endif
$$(eval $$(call SetupJavaCompilation, BUILD_DEMO_APPLET_$1, \
SETUP := GENERATE_USINGJDKBYTECODE, \
SRC := $$($1_SRC_DIR)/$1, \
BIN := $(SUPPORT_OUTPUTDIR)/demos/image/applets/$1, \
COPY := .html .java .xyz .obj .au .gif, \
DISABLE_SJAVAC := $$($1_DISABLE_SJAVAC), \
))
$1 := $$(BUILD_DEMO_APPLET_$1)
TARGETS += $$($1)
endef
ifneq ($(OPENJDK_TARGET_OS), solaris)
$(eval $(call SetupBuildAppletDemo, ArcTest))
$(eval $(call SetupBuildAppletDemo, BarChart))
$(eval $(call SetupBuildAppletDemo, Blink))
$(eval $(call SetupBuildAppletDemo, CardTest))
$(eval $(call SetupBuildAppletDemo, Clock))
$(eval $(call SetupBuildAppletDemo, DitherTest))
$(eval $(call SetupBuildAppletDemo, DrawTest))
$(eval $(call SetupBuildAppletDemo, Fractal))
$(eval $(call SetupBuildAppletDemo, GraphicsTest))
$(eval $(call SetupBuildAppletDemo, NervousText))
$(eval $(call SetupBuildAppletDemo, SimpleGraph))
$(eval $(call SetupBuildAppletDemo, SortDemo))
$(eval $(call SetupBuildAppletDemo, SpreadSheet))
endif
################################################################################
# Build normal demos.
@ -220,21 +171,6 @@ $(CODEPOINT_METAINF_SERVICE_FILE): $(DEMO_SHARE_SRC)/jfc/CodePointIM/$(CODEPOINT
$(BUILD_DEMO_CodePointIM_JAR): $(CODEPOINT_METAINF_SERVICE_FILE)
ifneq ($(OPENJDK_TARGET_OS), solaris)
$(eval $(call SetupBuildDemo, MoleculeViewer, \
DEMO_SUBDIR := applets, \
MAIN_CLASS := XYZChemModel, \
EXTRA_COPY_TO_IMAGE := *.java, \
))
$(eval $(call SetupBuildDemo, WireFrame, \
DEMO_SUBDIR := applets, \
MAIN_CLASS := ThreeD, \
EXTRA_COPY_TO_IMAGE := *.java, \
))
endif
$(eval $(call SetupBuildDemo, FileChooserDemo, \
DEMO_SUBDIR := jfc, \
))

View File

@ -1,217 +0,0 @@
<HTML>
<!--
Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Oracle nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="keywords" CONTENT="Java(tm) Plug-in">
<META NAME="GENERATOR" CONTENT="Mozilla/4.02 [en] (X11; U; SunOS 5.5.1 sun4u) [Netscape]">
<TITLE>Java(tm) Plug-in Demo Page</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<!-- begin main page table -->
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 >
<TR>
<TD VALIGN=TOP WIDTH="157"><!-------------------------------><!-- SERVER SIDE INCLUDE FOR --><!-- NAVIGATION MENU AT LEFT --><!-------------------------------><!--#include virtual="/share/include/navigate.html"--></TD>
<TD VALIGN=TOP WIDTH="452"><!-- begin header table -->
<TABLE BORDER=0 WIDTH="452" >
<CAPTION><!-------------------------------><!-- SERVER SIDE INCLUDE FOR --><!-- HEADER AT TOP OF PAGE --><!-------------------------------><!--#include virtual="/share/include/normal.header.html"--><!-- breadcrumb trail --></CAPTION>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP HEIGHT="25"></TD>
</TR>
<TR>
<TD></TD>
</TR>
<TR>
<TD ALIGN=RIGHT COLSPAN="2"><!-- page headline --><!-------------------------------><!--EDIT THE PAGE HEADLINE HERE--><!------------BEGIN-HEADLINE-----><FONT SIZE=+2>JAVA&trade; PLUG-IN</FONT> &nbsp;
<BR><B>Demonstration Applets</B>&nbsp;
<BR><!-------------END-HEADLINE------><!-- END OF PAGE HEADLINE --><!-------------------------------></TD>
</TR>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP COLSPAN="2" HEIGHT="30"><!-- subcategories of the current topic --><!-------------------------------><!-- MAKE DUPLICATE LINKS HERE --><!--OF LINKS THAT OCCUR THROUGH--><!-- OUT THE BODY OF THIS DOC --><!------------BEGIN-SUB TOPICS---><FONT SIZE=-1><A HREF="http://java.sun.com/products/plugin/index.html">Java
Plug-in home page</A> | <A HREF="http://java.sun.com/javase/MKTG_VERSION/docs/technotes/guides/plugin/developer_guide/faq/index.html">FAQ</A>
| <A HREF="http://java.sun.com/javase/MKTG_VERSION/docs/technotes/guides/plugin/developer_guide/contents.html">Documentation</A>&nbsp;</FONT>&nbsp;
</TD>
</TR>
</TABLE>
&nbsp;
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0 WIDTH="452" >
<TR>
<TD COLSPAN="2" WIDTH="452">
<TABLE WIDTH="100%" NOSAVE >
<TR>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
<!-- Begin Page Data --><!-------------------------------><!-- EDIT PAGE CONTENT HERE --><!------------BEGIN-CONTENT------><!-- Beginning of the more info table -->
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="466" >
<TR>
<TD ALIGN=RIGHT VALIGN=TOP ROWSPAN="2" WIDTH="8"></TD>
<TD>
<DIV ALIGN=right><!--<TD WIDTH=466 VALIGN=TOP ALIGN=RIGHT><BR>--><!-- <IMG WIDTH=60 HEIGHT=1 SRC="/images/dot_clear.gif"> --></DIV>
</TD>
</TR>
<TR>
<TD ALIGN=LEFT VALIGN=TOP WIDTH="466"><!-- Beginning of the more info table -->
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3 >
<CAPTION><!-- #===================== DOWNLOAD HOTJAVA 1.1 BETA 2 ===================== --></CAPTION>
<TR>
<TD ALIGN=RIGHT VALIGN=TOP><!-- <FONT COLOR="#FF0000" SIZE="+2"><STRONG>2.</STRONG></FONT> --></TD>
<TD><!--<IMG SRC="/images/chiclet2.jpg" WIDTH=14 HEIGHT=11 BORDER=0 ALT="Bullet">
<FONT SIZE="+1"><STRONG>Java Plug-in Demo Page</STRONG></FONT><BR> --></TD>
</TR>
<TR>
<TD></TD>
<TD><!-- start -->
<P>The examples on this page provide demonstration applets for
the purpose of demonstrating and evaluating Java Plug-in. Hence, the HTML
of each page explicitly specifies the use of the Java<SUP><FONT SIZE=-2>TM</FONT></SUP>Plug-in
rather than the default Java virtual machine contained in your browser.&nbsp;
<P>Java Plug-in is installed as part of the public Java<SUP><FONT SIZE=-2>TM</FONT></SUP> SE Runtime Environment.
Once installed, the Java Plug-in loads automatically
and transparently to render Java applets.&nbsp;
<P>All of these applets leverage Java<SUP><FONT SIZE=-2>TM</FONT></SUP> SE Development Kit MKTG_VERSION features, and are thus dependent
on features in that version.&nbsp; For information on compatibility, see <A HREF="http://java.sun.com/javase/MKTG_VERSION/compatibility.html">Compatibility
with Previous Releases</A>.&nbsp;&nbsp; The applets include those in the <TT>demo</TT>
directory of the Java SE Development Kit, plus a few extras.&nbsp; Each applet is viewed
by opening the respective web page (see the links below) in your
Web browser.&nbsp;
<H3>
<A NAME="educational"></A>Educational Applets</H3>
<UL><!-- NEW APPLETS GO HERE --><!-- Please note the date you add the applet. --><!-- Also include the author's name. -->
<LI>
<!--James Gosling--><A HREF="applets/MoleculeViewer/example1.html">3D Chemical Models</A>
<BR>(see also <A HREF="applets/MoleculeViewer/example2.html">example2</A>
and <A HREF="applets/MoleculeViewer/example3.html">example3</A>)</LI></UL>
<!--educational-->
<H3>
<A NAME="utilities"></A>Utilities</H3>
<UL><!-- NEW APPLETS GO HERE --><!-- Please note the date you add the applet. --><!-- Also include the author's name. -->
<LI>
<!--Rachel Gollub--><A HREF="applets/Clock/example1.html">A
Clock</A></LI>
<LI>
<!--Sami Shaio--><A HREF="applets/SpreadSheet/example1.html">A
Simple Spreadsheet</A></LI>
<LI>
<!--Sami Shaio--><A HREF="applets/BarChart/example1.html">A
Simple Bar Chart Applet</A></LI>
</UL>
<!--utilities-->
<H3>
<A NAME="programmers"></A>For Programmers Only</H3>
<UL><!-- NEW APPLETS GO HERE --><!-- Please note the date you add the applet. --><!-- Also include the author's name. -->
<LI>
<A HREF="applets/ArcTest/example1.html">ArcTest</A></LI>
<LI>
<A HREF="applets/CardTest/example1.html">CardTest</A></LI>
<LI>
<A HREF="applets/DitherTest/example1.html">DitherTest</A></LI>
<LI>
<A HREF="applets/DrawTest/example1.html">DrawTest</A></LI>
<LI>
<A HREF="applets/GraphicsTest/example1.html">GraphicsTest</A></LI>
<LI>
<A HREF="applets/SimpleGraph/example1.html">SimpleGraph</A></LI>
</UL>
<H3>
<A NAME="spice"></A>Applets to Enhance a Web Page</H3>
<UL><!-- NEW APPLETS GO HERE --><!-- Please note the date you add the applet. --><!-- Also include the author's name. --><!-- <LI>
by Arthur van Hoff; added 10/12/95<A HREF="ImageLoop/1.1/index.html">ImageLoop,
the Original Animation Applet</A></LI> -->
<!--Arthur van Hoff--><A HREF="applets/Blink/example1.html">Blinking
Text</A></LI>
</UL>
<H3>
<A NAME="spice"></A>JFC Applets</H3>
<UL><!-- Please note the date you add the applet. --><!-- Also include the author's name. --><!-- <LI>
by Arthur van Hoff; added 10/12/95<A HREF="ImageLoop/1.1/index.html">ImageLoop,
the Original Animation Applet</A></LI> -->
<!--spice--><!-- end -->
<LI>
<!----><A HREF="jfc/Java2D/Java2Demo.html">Java
2D</A></LI>
<!--spice--><!-- end --></UL>
</TD>
</TR>
<TR>
<TD></TD>
</TR>
</TABLE>
&nbsp;</TD>
</TR>
</TABLE>
<!-------------END-CONTENT-------><!-- END OF PAGE DATA --><!-------------------------------><!-- End Page Data --></TD>
</TR>
</TABLE>
&nbsp;</TD>
</TR>
</TABLE>
<!-- Footer table --><!-------------------------------><!-- SERVER SIDE INCLUDE FOR --><!-- FOOTER AT BOTTOM OF PAGE --><!-------------------------------><!--#include virtual="/share/include/normal.footer.html"-->
</BODY>
</HTML>

View File

@ -1,276 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
* An interactive test of the Graphics.drawArc and Graphics.fillArc
* routines. Can be run either as a standalone application by
* typing "java ArcTest" or as an applet in the AppletViewer.
*/
@SuppressWarnings("serial")
public class ArcTest extends Applet {
ArcControls controls; // The controls for marking and filling arcs
ArcCanvas canvas; // The drawing area to display arcs
@Override
public void init() {
setLayout(new BorderLayout());
canvas = new ArcCanvas();
add("Center", canvas);
add("South", controls = new ArcControls(canvas));
}
@Override
public void destroy() {
remove(controls);
remove(canvas);
}
@Override
public void start() {
controls.setEnabled(true);
}
@Override
public void stop() {
controls.setEnabled(false);
}
@Override
public void processEvent(AWTEvent e) {
if (e.getID() == Event.WINDOW_DESTROY) {
System.exit(0);
}
}
public static void main(String args[]) {
Frame f = new Frame("ArcTest");
ArcTest arcTest = new ArcTest();
arcTest.init();
arcTest.start();
f.add("Center", arcTest);
f.setSize(300, 300);
f.setVisible(true);
}
@Override
public String getAppletInfo() {
return "An interactive test of the Graphics.drawArc and \nGraphics."
+ "fillArc routines. Can be run \neither as a standalone "
+ "application by typing 'java ArcTest' \nor as an applet in "
+ "the AppletViewer.";
}
}
@SuppressWarnings("serial")
class ArcCanvas extends Canvas {
int startAngle = 0;
int extent = 45;
boolean filled = false;
Font font = new java.awt.Font("SansSerif", Font.PLAIN, 12);
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
int hlines = r.height / 10;
int vlines = r.width / 10;
g.setColor(Color.pink);
for (int i = 1; i <= hlines; i++) {
g.drawLine(0, i * 10, r.width, i * 10);
}
for (int i = 1; i <= vlines; i++) {
g.drawLine(i * 10, 0, i * 10, r.height);
}
g.setColor(Color.red);
if (filled) {
g.fillArc(0, 0, r.width - 1, r.height - 1, startAngle, extent);
} else {
g.drawArc(0, 0, r.width - 1, r.height - 1, startAngle, extent);
}
g.setColor(Color.black);
g.setFont(font);
g.drawLine(0, r.height / 2, r.width, r.height / 2);
g.drawLine(r.width / 2, 0, r.width / 2, r.height);
g.drawLine(0, 0, r.width, r.height);
g.drawLine(r.width, 0, 0, r.height);
int sx = 10;
int sy = r.height - 28;
g.drawString("Start = " + startAngle, sx, sy);
g.drawString("Extent = " + extent, sx, sy + 14);
}
public void redraw(boolean filled, int start, int extent) {
this.filled = filled;
this.startAngle = start;
this.extent = extent;
repaint();
}
}
@SuppressWarnings("serial")
class ArcControls extends Panel
implements ActionListener {
TextField startTF;
TextField extentTF;
ArcCanvas canvas;
@SuppressWarnings("LeakingThisInConstructor")
public ArcControls(ArcCanvas canvas) {
Button b = null;
this.canvas = canvas;
add(startTF = new IntegerTextField("0", 4));
add(extentTF = new IntegerTextField("45", 4));
b = new Button("Fill");
b.addActionListener(this);
add(b);
b = new Button("Draw");
b.addActionListener(this);
add(b);
}
@Override
public void actionPerformed(ActionEvent ev) {
String label = ev.getActionCommand();
int start, extent;
try {
start = Integer.parseInt(startTF.getText().trim());
} catch (NumberFormatException ignored) {
start = 0;
}
try {
extent = Integer.parseInt(extentTF.getText().trim());
} catch (NumberFormatException ignored) {
extent = 0;
}
canvas.redraw(label.equals("Fill"), start, extent);
}
}
@SuppressWarnings("serial")
class IntegerTextField extends TextField {
String oldText = null;
public IntegerTextField(String text, int columns) {
super(text, columns);
enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.TEXT_EVENT_MASK);
oldText = getText();
}
// Consume non-digit KeyTyped events
// Note that processTextEvent kind of eliminates the need for this
// function, but this is neater, since ideally, it would prevent
// the text from appearing at all. Sigh. See bugid 4100317/4114565.
//
@Override
protected void processEvent(AWTEvent evt) {
int id = evt.getID();
if (id != KeyEvent.KEY_TYPED) {
super.processEvent(evt);
return;
}
KeyEvent kevt = (KeyEvent) evt;
char c = kevt.getKeyChar();
// Digits, backspace, and delete are okay
// Note that the minus sign is allowed, but not the decimal
if (Character.isDigit(c) || (c == '\b') || (c == '\u007f') || (c
== '\u002d')) {
super.processEvent(evt);
return;
}
Toolkit.getDefaultToolkit().beep();
kevt.consume();
}
// Should consume TextEvents for non-integer Strings
// Store away the text in the tf for every TextEvent
// so we can revert to it on a TextEvent (paste, or
// legal key in the wrong location) with bad text
//
@Override
protected void processTextEvent(TextEvent te) {
// The empty string is okay, too
String newText = getText();
if (newText.equals("") || textIsInteger(newText)) {
oldText = newText;
super.processTextEvent(te);
return;
}
Toolkit.getDefaultToolkit().beep();
setText(oldText);
}
// Returns true for Integers (zero and negative
// values are allowed).
// Note that the empty string is not allowed.
//
private boolean textIsInteger(String textToCheck) {
try {
Integer.parseInt(textToCheck, 10);
return true;
} catch (NumberFormatException ignored) {
return false;
}
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>Arc Test (1.1)</title>
</head>
<body>
<h1>Arc Test (1.1)</h1>
<hr>
<applet code=ArcTest.class width=400 height=400>
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="ArcTest.java">The source</a>.
</body>
</html>

View File

@ -1,324 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.awt.*;
/**
* A simple bar chart demo
* @author Sami Shaio
* @modified 06/21/00 Daniel Peek : refactored, comments
*/
@SuppressWarnings("serial")
public class BarChart extends java.applet.Applet {
private static final int VERTICAL = 0;
private static final int HORIZONTAL = 1;
private static final int SOLID = 0;
private static final int STRIPED = 1;
private int orientation;
private String title;
private Font font;
private FontMetrics metrics;
private int columns;
private int values[];
private Color colors[];
private String labels[];
private int styles[];
private int scale = 10;
private int maxLabelWidth = 0;
private int barSpacing = 10;
private int maxValue = 0;
@Override
public void init() {
getSettings();
values = new int[columns];
labels = new String[columns];
styles = new int[columns];
colors = new Color[columns];
for (int i = 0; i < columns; i++) {
parseValue(i);
parseLabel(i);
parseStyle(i);
parseColor(i);
}
}
private void getSettings() {
font = new java.awt.Font("Monospaced", Font.BOLD, 12);
metrics = getFontMetrics(font);
title = getParameter("title");
if (title == null) {
title = "Chart";
}
String temp = getParameter("columns");
if (temp == null) {
columns = 5;
} else {
columns = Integer.parseInt(temp);
}
temp = getParameter("scale");
if (temp == null) {
scale = 10;
} else {
scale = Integer.parseInt(temp);
}
temp = getParameter("orientation");
if (temp == null) {
orientation = VERTICAL;
} else if (temp.equalsIgnoreCase("horizontal")) {
orientation = HORIZONTAL;
} else {
orientation = VERTICAL;
}
}
private void parseValue(int i) {
String temp = getParameter("C" + (i + 1));
try {
values[i] = Integer.parseInt(temp);
} catch (NumberFormatException e) {
values[i] = 0;
} catch (NullPointerException e) {
values[i] = 0;
}
maxValue = Math.max(maxValue, values[i]);
}
private void parseLabel(int i) {
String temp = getParameter("C" + (i + 1) + "_label");
if (temp == null) {
labels[i] = "";
} else {
labels[i] = temp;
}
maxLabelWidth = Math.max(metrics.stringWidth(labels[i]), maxLabelWidth);
}
private void parseStyle(int i) {
String temp = getParameter("C" + (i + 1) + "_style");
if (temp == null || temp.equalsIgnoreCase("solid")) {
styles[i] = SOLID;
} else if (temp.equalsIgnoreCase("striped")) {
styles[i] = STRIPED;
} else {
styles[i] = SOLID;
}
}
private void parseColor(int i) {
String temp = getParameter("C" + (i + 1) + "_color");
if (temp != null) {
temp = temp.toLowerCase();
if (temp.equals("red")) {
colors[i] = Color.red;
} else if (temp.equals("green")) {
colors[i] = Color.green;
} else if (temp.equals("blue")) {
colors[i] = Color.blue;
} else if (temp.equals("pink")) {
colors[i] = Color.pink;
} else if (temp.equals("orange")) {
colors[i] = Color.orange;
} else if (temp.equals("magenta")) {
colors[i] = Color.magenta;
} else if (temp.equals("cyan")) {
colors[i] = Color.cyan;
} else if (temp.equals("white")) {
colors[i] = Color.white;
} else if (temp.equals("yellow")) {
colors[i] = Color.yellow;
} else if (temp.equals("gray")) {
colors[i] = Color.gray;
} else if (temp.equals("darkgray")) {
colors[i] = Color.darkGray;
} else {
colors[i] = Color.gray;
}
} else {
colors[i] = Color.gray;
}
}
@Override
public void paint(Graphics g) {
// draw the title centered at the bottom of the bar graph
g.setColor(Color.black);
g.setFont(font);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
int titleWidth = metrics.stringWidth(title);
int cx = Math.max((getSize().width - titleWidth) / 2, 0);
int cy = getSize().height - metrics.getDescent();
g.drawString(title, cx, cy);
// draw the bars and their titles
if (orientation == HORIZONTAL) {
paintHorizontal(g);
} else { // VERTICAL
paintVertical(g);
}
}
private void paintHorizontal(Graphics g) {
// x and y coordinates to draw/write to
int cx, cy;
int barHeight = metrics.getHeight();
for (int i = 0; i < columns; i++) {
// set the X coordinate for this bar and label and center it
int widthOfItems = maxLabelWidth + 3 + (maxValue * scale) + 5
+ metrics.stringWidth(Integer.toString(maxValue));
cx = Math.max((getSize().width - widthOfItems) / 2, 0);
// set the Y coordinate for this bar and label
cy = getSize().height - metrics.getDescent() - metrics.getHeight()
- barSpacing
- ((columns - i - 1) * (barSpacing + barHeight));
// draw the label
g.setColor(Color.black);
g.drawString(labels[i], cx, cy);
cx += maxLabelWidth + 3;
// draw the shadow
g.fillRect(cx + 4, cy - barHeight + 4,
(values[i] * scale), barHeight);
// draw the bar
g.setColor(colors[i]);
if (styles[i] == STRIPED) {
for (int k = 0; k <= values[i] * scale; k += 2) {
g.drawLine(cx + k, cy - barHeight, cx + k, cy);
}
} else { // SOLID
g.fillRect(cx, cy - barHeight,
(values[i] * scale) + 1, barHeight + 1);
}
cx += (values[i] * scale) + 4;
// draw the value at the end of the bar
g.setColor(g.getColor().darker());
g.drawString(Integer.toString(values[i]), cx, cy);
}
}
private void paintVertical(Graphics g) {
int barWidth = maxLabelWidth;
for (int i = 0; i < columns; i++) {
// X coordinate for this label and bar (centered)
int widthOfItems = (barWidth + barSpacing) * columns - barSpacing;
int cx = Math.max((getSize().width - widthOfItems) / 2, 0);
cx += (maxLabelWidth + barSpacing) * i;
// Y coordinate for this label and bar
int cy = getSize().height - metrics.getHeight()
- metrics.getDescent() - 4;
// draw the label
g.setColor(Color.black);
g.drawString(labels[i], cx, cy);
cy -= metrics.getHeight() - 3;
// draw the shadow
g.fillRect(cx + 4, cy - (values[i] * scale) - 4,
barWidth, (values[i] * scale));
// draw the bar
g.setColor(colors[i]);
if (styles[i] == STRIPED) {
for (int k = 0; k <= values[i] * scale; k += 2) {
g.drawLine(cx, cy - k,
cx + barWidth, cy - k);
}
} else {
g.fillRect(cx, cy - (values[i] * scale),
barWidth + 1, (values[i] * scale) + 1);
}
cy -= (values[i] * scale) + 5;
// draw the value on top of the bar
g.setColor(g.getColor().darker());
g.drawString(Integer.toString(values[i]), cx, cy);
}
}
@Override
public String getAppletInfo() {
return "Title: Bar Chart \n"
+ "Author: Sami Shaio \n"
+ "A simple bar chart demo.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "title", "string", "The title of bar graph. Default is 'Chart'" },
{ "scale", "int", "The scale of the bar graph. Default is 10." },
{ "columns", "int", "The number of columns/rows. Default is 5." },
{ "orientation", "{VERTICAL, HORIZONTAL}",
"The orienation of the bar graph. Default is VERTICAL." },
{ "c#", "int", "Subsitute a number for #. "
+ "The value/size of bar #. Default is 0." },
{ "c#_label", "string", "The label for bar #. "
+ "Default is an empty label." },
{ "c#_style", "{SOLID, STRIPED}", "The style of bar #. "
+ "Default is SOLID." },
{ "c#_color", "{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, "
+ "WHITE, YELLOW, GRAY, DARKGRAY}",
"The color of bar #. Default is GRAY." }
};
return info;
}
}

View File

@ -1,41 +0,0 @@
<html>
<head>
<title>Bar Chart (1.1)</title>
</head>
<body>
<h1>Bar Chart (1.1)</h1>
<hr>
<applet code="BarChart.class" width=250 height=130>
<param name=title value="Performance">
<param name=columns value="4">
<param name=orientation value="horizontal">
<param name=scale value="5">
<param name=c1_label value="Q1">
<param name=c1 value="10">
<param name=c1_color value="blue">
<param name=c1_style value="striped">
<param name=c2_label value="Q2">
<param name=c2 value="20">
<param name=c2_color value="green">
<param name=c2_style value="solid">
<param name=c3_label value="Q3">
<param name=c3 value="5">
<param name=c3_color value="magenta">
<param name=c3_style value="striped">
<param name=c4_label value="Q4">
<param name=c4 value="30">
<param name=c4_color value="yellow">
<param name=c4_style value="solid">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="BarChart.java">The source</a>.
</body>
</html>

View File

@ -1,51 +0,0 @@
<html>
<head>
<title>Bar Chart (1.1)</title>
</head>
<body>
<h1>Bar Chart (1.1)</h1>
<hr>
<applet code="BarChart.class" width=400 height=300>
<param name=title value="Fruits">
<param name=columns value="6">
<param name=orientation value="vertical">
<param name=scale value="6">
<param name=c1_label value="Apple">
<param name=c1 value="10">
<param name=c1_color value="red">
<param name=c1_style value="solid">
<param name=c2_label value="Orange">
<param name=c2 value="20">
<param name=c2_color value="orange">
<param name=c2_style value="striped">
<param name=c3_label value="Lemon">
<param name=c3 value="5">
<param name=c3_color value="yellow">
<param name=c3_style value="solid">
<param name=c4_label value="Peach">
<param name=c4 value="30">
<param name=c4_color value="pink">
<param name=c4_style value="striped">
<param name=c5_label value="Pear">
<param name=c5 value="40">
<param name=c5_color value="green">
<param name=c5_style value="solid">
<param name=c6_label value="Plum">
<param name=c6 value="17">
<param name=c6_color value="magenta">
<param name=c6_style value="striped">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="BarChart.java">The source</a>.
</body>
</html>

View File

@ -1,143 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* I love blinking things.
*
* @author Arthur van Hoff
* @author 04/24/96 Jim Hagen use getBackground
* @author 02/05/98 Mike McCloskey removed use of deprecated methods
* @author 04/23/99 Josh Bloch, use timer instead of explicit multithreading.
* @author 07/10/00 Daniel Peek brought to code conventions, minor changes
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.StringTokenizer;
import java.util.Timer;
import java.util.TimerTask;
public class Blink extends java.applet.Applet {
private static final long serialVersionUID = -775844794477507646L;
private Timer timer; // Schedules the blinking
private String labelString; // The label for the window
private int delay; // the delay time between blinks
@Override
public void init() {
String blinkFrequency = getParameter("speed");
delay = (blinkFrequency == null) ? 400
: (1000 / Integer.parseInt(blinkFrequency));
labelString = getParameter("lbl");
if (labelString == null) {
labelString = "Blink";
}
Font font = new java.awt.Font("Serif", Font.PLAIN, 24);
setFont(font);
}
@Override
public void start() {
timer = new Timer(); //creates a new timer to schedule the blinking
timer.schedule(new TimerTask() { //creates a timertask to schedule
// overrides the run method to provide functionality
@Override
public void run() {
repaint();
}
}, delay, delay);
}
@Override
public void paint(Graphics g) {
int fontSize = g.getFont().getSize();
int x = 0, y = fontSize, space;
int red = (int) (50 * Math.random());
int green = (int) (50 * Math.random());
int blue = (int) (256 * Math.random());
Dimension d = getSize();
g.setColor(Color.black);
FontMetrics fm = g.getFontMetrics();
space = fm.stringWidth(" ");
for (StringTokenizer t = new StringTokenizer(labelString);
t.hasMoreTokens();) {
String word = t.nextToken();
int w = fm.stringWidth(word) + space;
if (x + w > d.width) {
x = 0;
y += fontSize; //move word to next line if it doesn't fit
}
if (Math.random() < 0.5) {
g.setColor(new java.awt.Color((red + y * 30) % 256,
(green + x / 3) % 256, blue));
} else {
g.setColor(getBackground());
}
g.drawString(word, x, y);
x += w; //shift to the right to draw the next word
}
}
@Override
public void stop() {
timer.cancel(); //stops the timer
}
@Override
public String getAppletInfo() {
return "Title: Blinker\n"
+ "Author: Arthur van Hoff\n"
+ "Displays multicolored blinking text.";
}
@Override
public String[][] getParameterInfo() {
String pinfo[][] = {
{ "speed", "string", "The blink frequency" },
{ "lbl", "string", "The text to blink." }, };
return pinfo;
}
}

View File

@ -1,19 +0,0 @@
<html>
<head>
<title>Blinking Text</title>
</head>
<body>
<h1>Blinking Text</h1>
<hr>
<applet code="Blink.class" width=300 height=100>
<param name=lbl value="This is the next best thing to sliced bread! Toas
t, toast, toast, butter, jam, toast, marmite, toast.">
<param name=speed value="4">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't runni
ng the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="Blink.java">The source.</a>
</body>
</html>

View File

@ -1,195 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Choice;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
@SuppressWarnings("serial")
final class CardPanel extends Panel {
ActionListener listener;
Panel create(LayoutManager layout) {
Button b = null;
Panel p = new Panel();
p.setLayout(layout);
b = new Button("one");
b.addActionListener(listener);
p.add("North", b);
b = new Button("two");
b.addActionListener(listener);
p.add("West", b);
b = new Button("three");
b.addActionListener(listener);
p.add("South", b);
b = new Button("four");
b.addActionListener(listener);
p.add("East", b);
b = new Button("five");
b.addActionListener(listener);
p.add("Center", b);
b = new Button("six");
b.addActionListener(listener);
p.add("Center", b);
return p;
}
CardPanel(ActionListener actionListener) {
listener = actionListener;
setLayout(new CardLayout());
add("one", create(new FlowLayout()));
add("two", create(new BorderLayout()));
add("three", create(new GridLayout(2, 2)));
add("four", create(new BorderLayout(10, 10)));
add("five", create(new FlowLayout(FlowLayout.LEFT, 10, 10)));
add("six", create(new GridLayout(2, 2, 10, 10)));
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 100);
}
}
@SuppressWarnings("serial")
public class CardTest extends Applet
implements ActionListener,
ItemListener {
CardPanel cards;
@SuppressWarnings("LeakingThisInConstructor")
public CardTest() {
setLayout(new BorderLayout());
add("Center", cards = new CardPanel(this));
Panel p = new Panel();
p.setLayout(new FlowLayout());
add("South", p);
Button b = new Button("first");
b.addActionListener(this);
p.add(b);
b = new Button("next");
b.addActionListener(this);
p.add(b);
b = new Button("previous");
b.addActionListener(this);
p.add(b);
b = new Button("last");
b.addActionListener(this);
p.add(b);
Choice c = new Choice();
c.addItem("one");
c.addItem("two");
c.addItem("three");
c.addItem("four");
c.addItem("five");
c.addItem("six");
c.addItemListener(this);
p.add(c);
}
@Override
public void itemStateChanged(ItemEvent e) {
((CardLayout) cards.getLayout()).show(cards,
(String) (e.getItem()));
}
@Override
public void actionPerformed(ActionEvent e) {
String arg = e.getActionCommand();
if ("first".equals(arg)) {
((CardLayout) cards.getLayout()).first(cards);
} else if ("next".equals(arg)) {
((CardLayout) cards.getLayout()).next(cards);
} else if ("previous".equals(arg)) {
((CardLayout) cards.getLayout()).previous(cards);
} else if ("last".equals(arg)) {
((CardLayout) cards.getLayout()).last(cards);
} else {
((CardLayout) cards.getLayout()).show(cards, arg);
}
}
public static void main(String args[]) {
Frame f = new Frame("CardTest");
CardTest cardTest = new CardTest();
cardTest.init();
cardTest.start();
f.add("Center", cardTest);
f.setSize(300, 300);
f.setVisible(true);
}
@Override
public String getAppletInfo() {
return "Demonstrates the different types of layout managers.";
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>Card Test (1.1)</title>
</head>
<body>
<h1>Card Test (1.1)</h1>
<hr>
<applet code=CardTest.class width=455 height=300>
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="CardTest.java">The source</a>.
</body>
</html>

View File

@ -1,250 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
* Time!
*
* @author Rachel Gollub
* @author Daniel Peek replaced circle drawing calculation, few more changes
*/
@SuppressWarnings("serial")
public class Clock extends Applet implements Runnable {
private volatile Thread timer; // The thread that displays clock
private int lastxs, lastys, lastxm,
lastym, lastxh, lastyh; // Dimensions used to draw hands
private SimpleDateFormat formatter; // Formats the date displayed
private String lastdate; // String to hold date displayed
private Font clockFaceFont; // Font for number display on clock
private Date currentDate; // Used to get date to display
private Color handColor; // Color of main hands and dial
private Color numberColor; // Color of second hand and numbers
private int xcenter = 80, ycenter = 55; // Center position
@Override
public void init() {
lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy",
Locale.getDefault());
currentDate = new Date();
lastdate = formatter.format(currentDate);
clockFaceFont = new Font("Serif", Font.PLAIN, 14);
handColor = Color.blue;
numberColor = Color.darkGray;
try {
setBackground(new Color(Integer.parseInt(getParameter("bgcolor"),
16)));
} catch (NullPointerException e) {
} catch (NumberFormatException e) {
}
try {
handColor = new Color(Integer.parseInt(getParameter("fgcolor1"),
16));
} catch (NullPointerException e) {
} catch (NumberFormatException e) {
}
try {
numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"),
16));
} catch (NullPointerException e) {
} catch (NumberFormatException e) {
}
resize(300, 300); // Set clock window size
}
/**
* Paint is the main part of the program
*/
@Override
public void update(Graphics g) {
int xh, yh, xm, ym, xs, ys;
int s = 0, m = 10, h = 10;
String today;
currentDate = new Date();
formatter.applyPattern("s");
try {
s = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
s = 0;
}
formatter.applyPattern("m");
try {
m = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
m = 10;
}
formatter.applyPattern("h");
try {
h = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
h = 10;
}
// Set position of the ends of the hands
xs = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 45 + xcenter);
ys = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter);
xm = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter);
ym = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter);
xh = (int) (Math.cos((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2)
* 30
+ xcenter);
yh = (int) (Math.sin((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2)
* 30
+ ycenter);
// Get the date to print at the bottom
formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
today = formatter.format(currentDate);
g.setFont(clockFaceFont);
// Erase if necessary
g.setColor(getBackground());
if (xs != lastxs || ys != lastys) {
g.drawLine(xcenter, ycenter, lastxs, lastys);
g.drawString(lastdate, 5, 125);
}
if (xm != lastxm || ym != lastym) {
g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
}
if (xh != lastxh || yh != lastyh) {
g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
}
// Draw date and hands
g.setColor(numberColor);
g.drawString(today, 5, 125);
g.drawLine(xcenter, ycenter, xs, ys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter - 1, xm, ym);
g.drawLine(xcenter - 1, ycenter, xm, ym);
g.drawLine(xcenter, ycenter - 1, xh, yh);
g.drawLine(xcenter - 1, ycenter, xh, yh);
lastxs = xs;
lastys = ys;
lastxm = xm;
lastym = ym;
lastxh = xh;
lastyh = yh;
lastdate = today;
currentDate = null;
}
@Override
public void paint(Graphics g) {
g.setFont(clockFaceFont);
// Draw the circle and numbers
g.setColor(handColor);
g.drawArc(xcenter - 50, ycenter - 50, 100, 100, 0, 360);
g.setColor(numberColor);
g.drawString("9", xcenter - 45, ycenter + 3);
g.drawString("3", xcenter + 40, ycenter + 3);
g.drawString("12", xcenter - 5, ycenter - 37);
g.drawString("6", xcenter - 3, ycenter + 45);
// Draw date and hands
g.setColor(numberColor);
g.drawString(lastdate, 5, 125);
g.drawLine(xcenter, ycenter, lastxs, lastys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
}
@Override
public void start() {
timer = new Thread(this);
timer.start();
}
@Override
public void stop() {
timer = null;
}
@Override
@SuppressWarnings("SleepWhileHoldingLock")
public void run() {
Thread me = Thread.currentThread();
while (timer == me) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
repaint();
}
}
@Override
public String getAppletInfo() {
return "Title: A Clock \n"
+ "Author: Rachel Gollub, 1995 \n"
+ "An analog clock.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "bgcolor", "hexadecimal RGB number",
"The background color. Default is the color of your browser." },
{ "fgcolor1", "hexadecimal RGB number",
"The color of the hands and dial. Default is blue." },
{ "fgcolor2", "hexadecimal RGB number",
"The color of the second hand and numbers. Default is dark gray." }
};
return info;
}
}

View File

@ -1,47 +0,0 @@
<HTML>
<HEAD>
<TITLE>A Clock (1.6)</TITLE>
</HEAD>
<BODY>
<h1>A Clock (1.6)</h1>
<hr>
<applet code="Clock.class" width=170 height=150>
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<p>
The clock applet now has three parameters; the background
color (bgcolor), the main foreground color (the hands and
dial) (fgcolor1) and the secondary foreground color (the
seconds hand and numbers) (fgcolor2). These three parameters
are hexadecimal RGB numbers (like the ones used for the body
bgcolor tag in HTML). For example:
<p>
&lt;applet code="Clock.class" width=170 height=150&gt;<br>
&lt;param name=bgcolor value="000000"&gt;<br>
&lt;param name=fgcolor1 value="ff0000"&gt;<br>
&lt;param name=fgcolor2 value="ff00ff"&gt;<br>
&lt;/applet&gt;<p>
would give you a black background, a red dial and hands, and purple numbers.
<p>
For those who don't convert to hexadecimal easily, here are some common
values:
<ul>
<li>black = 000000
<li>blue = 0000ff
<li>cyan = 00ffff
<li>darkGray = 404040
<li>gray = 808080
<li>green = 00ff00
<li>lightGray = c0c0c0
<li>magenta = ff00ff
<li>orange = ffc800
<li>pink = ffafaf
<li>red = ff0000
<li>white = ffffff
<li>yellow = ffff00
</ul>
<hr>
<a href="Clock.java">The source</a>.
</BODY>
</HTML>

View File

@ -1,480 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.applet.Applet;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Canvas;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.TextEvent;
import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource;
enum DitherMethod {
NOOP, RED, GREEN, BLUE, ALPHA, SATURATION
};
@SuppressWarnings("serial")
public class DitherTest extends Applet implements Runnable {
private Thread runner;
private DitherControls XControls;
private DitherControls YControls;
private DitherCanvas canvas;
public static void main(String args[]) {
Frame f = new Frame("DitherTest");
DitherTest ditherTest = new DitherTest();
ditherTest.init();
f.add("Center", ditherTest);
f.pack();
f.setVisible(true);
ditherTest.start();
}
@Override
public void init() {
String xspec = null, yspec = null;
int xvals[] = new int[2];
int yvals[] = new int[2];
try {
xspec = getParameter("xaxis");
yspec = getParameter("yaxis");
} catch (NullPointerException ignored) {
//only occurs if run as application
}
if (xspec == null) {
xspec = "red";
}
if (yspec == null) {
yspec = "blue";
}
DitherMethod xmethod = colorMethod(xspec, xvals);
DitherMethod ymethod = colorMethod(yspec, yvals);
setLayout(new BorderLayout());
XControls = new DitherControls(this, xvals[0], xvals[1],
xmethod, false);
YControls = new DitherControls(this, yvals[0], yvals[1],
ymethod, true);
YControls.addRenderButton();
add("North", XControls);
add("South", YControls);
add("Center", canvas = new DitherCanvas());
}
private DitherMethod colorMethod(String s, int vals[]) {
DitherMethod method = DitherMethod.NOOP;
if (s == null) {
s = "";
}
String lower = s.toLowerCase();
for (DitherMethod m : DitherMethod.values()) {
if (lower.startsWith(m.toString().toLowerCase())) {
method = m;
lower = lower.substring(m.toString().length());
}
}
if (method == DitherMethod.NOOP) {
vals[0] = 0;
vals[1] = 0;
return method;
}
int begval = 0;
int endval = 255;
try {
int dash = lower.indexOf('-');
if (dash < 0) {
endval = Integer.parseInt(lower);
} else {
begval = Integer.parseInt(lower.substring(0, dash));
endval = Integer.parseInt(lower.substring(dash + 1));
}
} catch (NumberFormatException ignored) {
}
if (begval < 0) {
begval = 0;
} else if (begval > 255) {
begval = 255;
}
if (endval < 0) {
endval = 0;
} else if (endval > 255) {
endval = 255;
}
vals[0] = begval;
vals[1] = endval;
return method;
}
/**
* Calculates and returns the image. Halts the calculation and returns
* null if the Applet is stopped during the calculation.
*/
private Image calculateImage() {
Thread me = Thread.currentThread();
int width = canvas.getSize().width;
int height = canvas.getSize().height;
int xvals[] = new int[2];
int yvals[] = new int[2];
int xmethod = XControls.getParams(xvals);
int ymethod = YControls.getParams(yvals);
int pixels[] = new int[width * height];
int c[] = new int[4]; //temporarily holds R,G,B,A information
int index = 0;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
c[0] = c[1] = c[2] = 0;
c[3] = 255;
if (xmethod < ymethod) {
applyMethod(c, xmethod, i, width, xvals);
applyMethod(c, ymethod, j, height, yvals);
} else {
applyMethod(c, ymethod, j, height, yvals);
applyMethod(c, xmethod, i, width, xvals);
}
pixels[index++] = ((c[3] << 24) | (c[0] << 16) | (c[1] << 8)
| c[2]);
}
// Poll once per row to see if we've been told to stop.
if (runner != me) {
return null;
}
}
return createImage(new MemoryImageSource(width, height,
ColorModel.getRGBdefault(), pixels, 0, width));
}
private void applyMethod(int c[], int methodIndex, int step,
int total, int vals[]) {
DitherMethod method = DitherMethod.values()[methodIndex];
if (method == DitherMethod.NOOP) {
return;
}
int val = ((total < 2)
? vals[0]
: vals[0] + ((vals[1] - vals[0]) * step / (total - 1)));
switch (method) {
case RED:
c[0] = val;
break;
case GREEN:
c[1] = val;
break;
case BLUE:
c[2] = val;
break;
case ALPHA:
c[3] = val;
break;
case SATURATION:
int max = Math.max(Math.max(c[0], c[1]), c[2]);
int min = max * (255 - val) / 255;
if (c[0] == 0) {
c[0] = min;
}
if (c[1] == 0) {
c[1] = min;
}
if (c[2] == 0) {
c[2] = min;
}
break;
}
}
@Override
public void start() {
runner = new Thread(this);
runner.start();
}
@Override
public void run() {
canvas.setImage(null); // Wipe previous image
Image img = calculateImage();
if (img != null && runner == Thread.currentThread()) {
canvas.setImage(img);
}
}
@Override
public void stop() {
runner = null;
}
@Override
public void destroy() {
remove(XControls);
remove(YControls);
remove(canvas);
}
@Override
public String getAppletInfo() {
return "An interactive demonstration of dithering.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "xaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the Y axis. Default is RED." },
{ "yaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the X axis. Default is BLUE." }
};
return info;
}
}
@SuppressWarnings("serial")
class DitherCanvas extends Canvas {
private Image img;
private static String calcString = "Calculating...";
@Override
public void paint(Graphics g) {
int w = getSize().width;
int h = getSize().height;
if (img == null) {
super.paint(g);
g.setColor(Color.black);
FontMetrics fm = g.getFontMetrics();
int x = (w - fm.stringWidth(calcString)) / 2;
int y = h / 2;
g.drawString(calcString, x, y);
} else {
g.drawImage(img, 0, 0, w, h, this);
}
}
@Override
public void update(Graphics g) {
paint(g);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(20, 20);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 200);
}
public Image getImage() {
return img;
}
public void setImage(Image img) {
this.img = img;
repaint();
}
}
@SuppressWarnings("serial")
class DitherControls extends Panel implements ActionListener {
private CardinalTextField start;
private CardinalTextField end;
private Button button;
private Choice choice;
private DitherTest applet;
private static LayoutManager dcLayout = new FlowLayout(FlowLayout.CENTER,
10, 5);
public DitherControls(DitherTest app, int s, int e, DitherMethod type,
boolean vertical) {
applet = app;
setLayout(dcLayout);
add(new Label(vertical ? "Vertical" : "Horizontal"));
add(choice = new Choice());
for (DitherMethod m : DitherMethod.values()) {
choice.addItem(m.toString().substring(0, 1)
+ m.toString().substring(1).toLowerCase());
}
choice.select(type.ordinal());
add(start = new CardinalTextField(Integer.toString(s), 4));
add(end = new CardinalTextField(Integer.toString(e), 4));
}
/* puts on the button */
public void addRenderButton() {
add(button = new Button("New Image"));
button.addActionListener(this);
}
/* retrieves data from the user input fields */
public int getParams(int vals[]) {
try {
vals[0] = scale(Integer.parseInt(start.getText()));
} catch (NumberFormatException nfe) {
vals[0] = 0;
}
try {
vals[1] = scale(Integer.parseInt(end.getText()));
} catch (NumberFormatException nfe) {
vals[1] = 255;
}
return choice.getSelectedIndex();
}
/* fits the number between 0 and 255 inclusive */
private int scale(int number) {
if (number < 0) {
number = 0;
} else if (number > 255) {
number = 255;
}
return number;
}
/* called when user clicks the button */
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
applet.start();
}
}
}
@SuppressWarnings("serial")
class CardinalTextField extends TextField {
String oldText = null;
public CardinalTextField(String text, int columns) {
super(text, columns);
enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.TEXT_EVENT_MASK);
oldText = getText();
}
// Consume non-digit KeyTyped events
// Note that processTextEvent kind of eliminates the need for this
// function, but this is neater, since ideally, it would prevent
// the text from appearing at all. Sigh. See bugid 4100317/4114565.
//
@Override
protected void processEvent(AWTEvent evt) {
int id = evt.getID();
if (id != KeyEvent.KEY_TYPED) {
super.processEvent(evt);
return;
}
KeyEvent kevt = (KeyEvent) evt;
char c = kevt.getKeyChar();
// Digits, backspace, and delete are okay
// Note that the minus sign is not allowed (neither is decimal)
if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) {
super.processEvent(evt);
return;
}
Toolkit.getDefaultToolkit().beep();
kevt.consume();
}
// Should consume TextEvents for non-integer Strings
// Store away the text in the tf for every TextEvent
// so we can revert to it on a TextEvent (paste, or
// legal key in the wrong location) with bad text
//
// Note: it would be easy to extend this to an eight-bit
// TextField (range 0-255), but I'll leave it as-is.
//
@Override
protected void processTextEvent(TextEvent te) {
// The empty string is okay, too
String newText = getText();
if (newText.equals("") || textIsCardinal(newText)) {
oldText = newText;
super.processTextEvent(te);
return;
}
Toolkit.getDefaultToolkit().beep();
setText(oldText);
}
// Returns true for Cardinal (non-negative) numbers
// Note that the empty string is not allowed
private boolean textIsCardinal(String textToCheck) {
try {
return Integer.parseInt(textToCheck, 10) >= 0;
} catch (NumberFormatException nfe) {
return false;
}
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>Dither Test (1.1)</title>
</head>
<body>
<h1>Dither Test (1.1)</h1>
<hr>
<applet code=DitherTest.class width=455 height=400>
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="DitherTest.java">The source</a>.
</body>
</html>

View File

@ -1,300 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("serial")
public class DrawTest extends Applet {
DrawPanel panel;
DrawControls controls;
@Override
public void init() {
setLayout(new BorderLayout());
panel = new DrawPanel();
controls = new DrawControls(panel);
add("Center", panel);
add("South", controls);
}
@Override
public void destroy() {
remove(panel);
remove(controls);
}
public static void main(String args[]) {
Frame f = new Frame("DrawTest");
DrawTest drawTest = new DrawTest();
drawTest.init();
drawTest.start();
f.add("Center", drawTest);
f.setSize(300, 300);
f.setVisible(true);
}
@Override
public String getAppletInfo() {
return "A simple drawing program.";
}
}
@SuppressWarnings("serial")
class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
public static final int LINES = 0;
public static final int POINTS = 1;
int mode = LINES;
List<Rectangle> lines = new ArrayList<Rectangle>();
List<Color> colors = new ArrayList<Color>();
int x1, y1;
int x2, y2;
@SuppressWarnings("LeakingThisInConstructor")
public DrawPanel() {
setBackground(Color.white);
addMouseMotionListener(this);
addMouseListener(this);
}
public void setDrawMode(int mode) {
switch (mode) {
case LINES:
case POINTS:
this.mode = mode;
break;
default:
throw new IllegalArgumentException();
}
}
@Override
public void mouseDragged(MouseEvent e) {
e.consume();
switch (mode) {
case LINES:
x2 = e.getX();
y2 = e.getY();
break;
case POINTS:
default:
colors.add(getForeground());
lines.add(new Rectangle(x1, y1, e.getX(), e.getY()));
x1 = e.getX();
y1 = e.getY();
break;
}
repaint();
}
@Override
public void mouseMoved(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
e.consume();
switch (mode) {
case LINES:
x1 = e.getX();
y1 = e.getY();
x2 = -1;
break;
case POINTS:
default:
colors.add(getForeground());
lines.add(new Rectangle(e.getX(), e.getY(), -1, -1));
x1 = e.getX();
y1 = e.getY();
repaint();
break;
}
}
@Override
public void mouseReleased(MouseEvent e) {
e.consume();
switch (mode) {
case LINES:
colors.add(getForeground());
lines.add(new Rectangle(x1, y1, e.getX(), e.getY()));
x2 = -1;
break;
case POINTS:
default:
break;
}
repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void paint(Graphics g) {
int np = lines.size();
/* draw the current lines */
g.setColor(getForeground());
for (int i = 0; i < np; i++) {
Rectangle p = lines.get(i);
g.setColor(colors.get(i));
if (p.width != -1) {
g.drawLine(p.x, p.y, p.width, p.height);
} else {
g.drawLine(p.x, p.y, p.x, p.y);
}
}
if (mode == LINES) {
g.setColor(getForeground());
if (x2 != -1) {
g.drawLine(x1, y1, x2, y2);
}
}
}
}
@SuppressWarnings("serial")
class DrawControls extends Panel implements ItemListener {
DrawPanel target;
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
setBackground(Color.lightGray);
target.setForeground(Color.red);
CheckboxGroup group = new CheckboxGroup();
Checkbox b;
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.red);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.green);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.blue);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.pink);
add(b = new Checkbox(null, group, false));
b.addItemListener(this);
b.setForeground(Color.orange);
add(b = new Checkbox(null, group, true));
b.addItemListener(this);
b.setForeground(Color.black);
target.setForeground(b.getForeground());
Choice shapes = new Choice();
shapes.addItemListener(this);
shapes.addItem("Lines");
shapes.addItem("Points");
shapes.setBackground(Color.lightGray);
add(shapes);
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
g.setColor(comp.getForeground());
g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
}
}
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
}
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>Draw Test (1.1)</title>
</head>
<body>
<h1>Draw Test (1.1)</h1>
<hr>
<applet code=DrawTest.class width=400 height=400>
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="DrawTest.java">The source</a>.
</body>
</html>

View File

@ -1,491 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.awt.Graphics;
import java.util.Stack;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
/**
* A (not-yet) Context sensitive L-System Fractal applet class.
*
* The rules for the Context L-system are read from the java.applet.Applet's
* attributes and then the system is iteratively applied for the
* given number of levels, possibly drawing each generation as it
* is generated. Note that the ContextLSystem class does not yet
* handle the lContext and rContext attributes, although this
* class is already designed to parse the '[' and ']' characters
* typically used in Context sensitive L-Systems.
*
* @author Jim Graham
*/
@SuppressWarnings("serial")
public class CLSFractal
extends java.applet.Applet
implements Runnable, MouseListener {
Thread kicker;
ContextLSystem cls;
int fractLevel = 1;
int repaintDelay = 50;
boolean incrementalUpdates;
float startAngle = 0;
float rotAngle = 45;
float Xmin;
float Xmax;
float Ymin;
float Ymax;
int border;
boolean normalizescaling;
@Override
public void init() {
String s;
cls = new ContextLSystem(this);
s = getParameter("level");
if (s != null) {
fractLevel = Integer.parseInt(s);
}
s = getParameter("incremental");
if (s != null) {
incrementalUpdates = s.equalsIgnoreCase("true");
}
s = getParameter("delay");
if (s != null) {
repaintDelay = Integer.parseInt(s);
}
s = getParameter("startAngle");
if (s != null) {
startAngle = Float.valueOf(s).floatValue();
}
s = getParameter("rotAngle");
if (s != null) {
rotAngle = Float.valueOf(s).floatValue();
}
rotAngle = rotAngle / 360 * 2 * 3.14159265358f;
s = getParameter("border");
if (s != null) {
border = Integer.parseInt(s);
}
s = getParameter("normalizescale");
if (s != null) {
normalizescaling = s.equalsIgnoreCase("true");
}
addMouseListener(this);
}
@Override
public void destroy() {
removeMouseListener(this);
}
@Override
public void run() {
Thread me = Thread.currentThread();
boolean needsRepaint = false;
while (kicker == me && cls.getLevel() < fractLevel) {
cls.generate();
if (kicker == me && incrementalUpdates) {
repaint();
try {
Thread.sleep(repaintDelay);
} catch (InterruptedException ignored) {
}
} else {
needsRepaint = true;
}
}
if (kicker == me) {
kicker = null;
if (needsRepaint) {
repaint();
}
}
}
@Override
public void start() {
kicker = new Thread(this);
kicker.start();
}
@Override
public void stop() {
kicker = null;
}
/*1.1 event handling */
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
cls = new ContextLSystem(this);
savedPath = null;
start();
e.consume();
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
String savedPath;
@Override
public void paint(Graphics g) {
String fractalPath = cls.getPath();
if (fractalPath == null) {
super.paint(g);
return;
}
if (savedPath == null || !savedPath.equals(fractalPath)) {
savedPath = fractalPath;
render(null, fractalPath);
}
for (int i = 0; i < border; i++) {
g.draw3DRect(i, i, getSize().width - i * 2, getSize().height - i * 2,
false);
}
render(g, fractalPath);
}
void render(Graphics g, String path) {
Stack<CLSTurtle> turtleStack = new Stack<CLSTurtle>();
CLSTurtle turtle;
if (g == null) {
Xmin = 1E20f;
Ymin = 1E20f;
Xmax = -1E20f;
Ymax = -1E20f;
turtle = new CLSTurtle(startAngle, 0, 0, 0, 0, 1, 1);
} else {
float frwidth = Xmax - Xmin;
if (frwidth == 0) {
frwidth = 1;
}
float frheight = Ymax - Ymin;
if (frheight == 0) {
frheight = 1;
}
float xscale = (getSize().width - border * 2 - 1) / frwidth;
float yscale = (getSize().height - border * 2 - 1) / frheight;
int xoff = border;
int yoff = border;
if (normalizescaling) {
if (xscale < yscale) {
yoff += ((getSize().height - border * 2)
- ((Ymax - Ymin) * xscale)) / 2;
yscale = xscale;
} else if (yscale < xscale) {
xoff += ((getSize().width - border * 2)
- ((Xmax - Xmin) * yscale)) / 2;
xscale = yscale;
}
}
turtle = new CLSTurtle(startAngle, 0 - Xmin, 0 - Ymin,
xoff, yoff, xscale, yscale);
}
for (int pos = 0; pos < path.length(); pos++) {
switch (path.charAt(pos)) {
case '+':
turtle.rotate(rotAngle);
break;
case '-':
turtle.rotate(-rotAngle);
break;
case '[':
turtleStack.push(turtle);
turtle = new CLSTurtle(turtle);
break;
case ']':
turtle = turtleStack.pop();
break;
case 'f':
turtle.jump();
break;
case 'F':
if (g == null) {
includePt(turtle.X, turtle.Y);
turtle.jump();
includePt(turtle.X, turtle.Y);
} else {
turtle.draw(g);
}
break;
default:
break;
}
}
}
void includePt(float x, float y) {
if (x < Xmin) {
Xmin = x;
}
if (x > Xmax) {
Xmax = x;
}
if (y < Ymin) {
Ymin = y;
}
if (y > Ymax) {
Ymax = y;
}
}
@Override
public String getAppletInfo() {
return "Title: CLSFractal 1.1f, 27 Mar 1995 \nAuthor: Jim Graham \nA "
+ "(not yet) Context Sensitive L-System production rule. \n"
+ "This class encapsulates a production rule for a Context "
+ "Sensitive\n L-System \n(pred, succ, lContext, rContext)."
+ " The matches() method, however, does not \n(yet) verify "
+ "the lContext and rContext parts of the rule.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "level", "int", "Maximum number of recursions. Default is 1." },
{ "incremental", "boolean", "Whether or not to repaint between "
+ "recursions. Default is true." },
{ "delay", "integer", "Sets delay between repaints. Default is 50." },
{ "startAngle", "float", "Sets the starting angle. Default is 0." },
{ "rotAngle", "float", "Sets the rotation angle. Default is 45." },
{ "border", "integer", "Width of border. Default is 2." },
{ "normalizeScale", "boolean", "Whether or not to normalize "
+ "the scaling. Default is true." },
{ "pred", "String",
"Initializes the rules for Context Sensitive L-Systems." },
{ "succ", "String",
"Initializes the rules for Context Sensitive L-Systems." },
{ "lContext", "String",
"Initializes the rules for Context Sensitive L-Systems." },
{ "rContext", "String",
"Initializes the rules for Context Sensitive L-Systems." }
};
return info;
}
}
/**
* A Logo turtle class designed to support Context sensitive L-Systems.
*
* This turtle performs a few basic maneuvers needed to support the
* set of characters used in Context sensitive L-Systems "+-fF[]".
*
* @author Jim Graham
*/
class CLSTurtle {
float angle;
float X;
float Y;
float scaleX;
float scaleY;
int xoff;
int yoff;
public CLSTurtle(float ang, float x, float y,
int xorg, int yorg, float sx, float sy) {
angle = ang;
scaleX = sx;
scaleY = sy;
X = x * sx;
Y = y * sy;
xoff = xorg;
yoff = yorg;
}
public CLSTurtle(CLSTurtle turtle) {
angle = turtle.angle;
X = turtle.X;
Y = turtle.Y;
scaleX = turtle.scaleX;
scaleY = turtle.scaleY;
xoff = turtle.xoff;
yoff = turtle.yoff;
}
public void rotate(float theta) {
angle += theta;
}
public void jump() {
X += (float) Math.cos(angle) * scaleX;
Y += (float) Math.sin(angle) * scaleY;
}
public void draw(Graphics g) {
float x = X + (float) Math.cos(angle) * scaleX;
float y = Y + (float) Math.sin(angle) * scaleY;
g.drawLine((int) X + xoff, (int) Y + yoff,
(int) x + xoff, (int) y + yoff);
X = x;
Y = y;
}
}
/**
* A (non-)Context sensitive L-System class.
*
* This class initializes the rules for Context sensitive L-Systems
* (pred, succ, lContext, rContext) from the given java.applet.Applet's attributes.
* The generate() method, however, does not (yet) apply the lContext
* and rContext parts of the rules.
*
* @author Jim Graham
*/
class ContextLSystem {
String axiom;
List<CLSRule> rules = new ArrayList<CLSRule>();
int level;
public ContextLSystem(java.applet.Applet app) {
axiom = app.getParameter("axiom");
int num = 1;
while (true) {
String pred = app.getParameter("pred" + num);
String succ = app.getParameter("succ" + num);
if (pred == null || succ == null) {
break;
}
rules.add(new CLSRule(pred, succ,
app.getParameter("lContext" + num),
app.getParameter("rContext" + num)));
num++;
}
currentPath = new StringBuffer(axiom);
level = 0;
}
public int getLevel() {
return level;
}
StringBuffer currentPath;
public synchronized String getPath() {
return ((currentPath == null) ? null : currentPath.toString());
}
private synchronized void setPath(StringBuffer path) {
currentPath = path;
level++;
}
public void generate() {
StringBuffer newPath = new StringBuffer();
int pos = 0;
while (pos < currentPath.length()) {
CLSRule rule = findRule(pos);
if (rule == null) {
newPath.append(currentPath.charAt(pos));
pos++;
} else {
newPath.append(rule.succ);
pos += rule.pred.length();
}
}
setPath(newPath);
}
public CLSRule findRule(int pos) {
for (int i = 0; i < rules.size(); i++) {
CLSRule rule = rules.get(i);
if (rule.matches(currentPath, pos)) {
return rule;
}
}
return null;
}
}
/**
* A Context sensitive L-System production rule.
*
* This class encapsulates a production rule for a Context sensitive
* L-System (pred, succ, lContext, rContext).
* The matches() method, however, does not (yet) verify the lContext
* and rContext parts of the rule.
*
* @author Jim Graham
*/
class CLSRule {
String pred;
String succ;
String lContext;
String rContext;
public CLSRule(String p, String d, String l, String r) {
pred = p;
succ = d;
lContext = l;
rContext = r;
}
public boolean matches(StringBuffer sb, int pos) {
if (pos + pred.length() > sb.length()) {
return false;
}
char cb[] = new char[pred.length()];
sb.getChars(pos, pos + pred.length(), cb, 0);
return pred.equals(new String(cb));
}
}

View File

@ -1,25 +0,0 @@
<html>
<head>
<title>Fractals 1.1</title>
</head>
<body>
<h1>Fractals 1.1</h1>
<hr>
<applet code="CLSFractal.class" width=500 height=120>
<param name=level value="5">
<param name=rotangle value="45">
<param name=succ1 value="F-F++F-F">
<param name=delay value="1000">
<param name=axiom value="F">
<param name=normalizescale value="true">
<param name=incremental value="true">
<param name=pred1 value="F">
<param name=border value="2">
<param name=startangle value="0">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="CLSFractal.java">The source</a>.
</body>
</html>

View File

@ -1,111 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.awt.Frame;
import java.awt.Event;
import java.awt.Dimension;
import java.applet.Applet;
import java.awt.AWTEvent;
/**
* Applet to Application Frame window
*/
@SuppressWarnings("serial")
class AppletFrame extends Frame {
public static void startApplet(String className,
String title,
String args[]) {
// local variables
Applet a;
Dimension appletSize;
try {
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
} catch (ClassNotFoundException e) {
return;
} catch (InstantiationException e) {
return;
} catch (IllegalAccessException e) {
return;
}
// initialize the applet
a.init();
a.start();
// create new application frame window
AppletFrame f = new AppletFrame(title);
// add applet to frame window
f.add("Center", a);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.getSize();
f.pack();
f.setSize(appletSize);
// show the window
f.setVisible(true);
} // end startApplet()
// constructor needed to pass window title to class Frame
public AppletFrame(String name) {
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
} // end handleEvent()
} // end class AppletFrame

View File

@ -1,481 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.applet.Applet;
@SuppressWarnings("serial")
class GraphicsPanel extends Panel {
ActionListener al;
ItemListener il;
public GraphicsCards cards;
GraphicsPanel(EventListener listener) {
al = (ActionListener) listener;
il = (ItemListener) listener;
setLayout(new BorderLayout());
add("Center", cards = new GraphicsCards());
Panel p = new Panel();
//p.setLayout(new BorderLayout());
Button b = new Button("next");
b.addActionListener(al);
p.add(b);
b = new Button("previous");
b.addActionListener(al);
p.add(b);
p.add(new Label("go to:", Label.RIGHT));
Choice c = new Choice();
c.addItemListener(il);
p.add(c);
c.addItem("Arc");
c.addItem("Oval");
c.addItem("Polygon");
c.addItem("Rect");
c.addItem("RoundRect");
add("North", p);
setSize(400, 400);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 100);
}
}
@SuppressWarnings("serial")
public class GraphicsTest extends Applet
implements ActionListener, ItemListener {
GraphicsPanel mainPanel;
@Override
public void init() {
setLayout(new BorderLayout());
add("Center", mainPanel = new GraphicsPanel(this));
}
@Override
public void destroy() {
remove(mainPanel);
}
@Override
public void actionPerformed(ActionEvent e) {
String arg = e.getActionCommand();
if ("next".equals(arg)) {
((CardLayout) mainPanel.cards.getLayout()).next(mainPanel.cards);
} else if ("previous".equals(arg)) {
((CardLayout) mainPanel.cards.getLayout()).previous(mainPanel.cards);
}
}
@Override
public void itemStateChanged(ItemEvent e) {
((CardLayout) mainPanel.cards.getLayout()).show(mainPanel.cards,
(String) e.getItem());
}
public static void main(String args[]) {
AppletFrame.startApplet("GraphicsTest", "Graphics Test", args);
}
@Override
public String getAppletInfo() {
return "An interactive demonstration of some graphics.";
}
} // end class GraphicsTest
@SuppressWarnings("serial")
class GraphicsCards extends Panel {
public GraphicsCards() {
setLayout(new CardLayout());
add("Arc", new ArcCard());
add("Oval", new ShapeTest(new OvalShape()));
add("Polygon", new ShapeTest(new PolygonShape()));
add("Rect", new ShapeTest(new RectShape()));
add("RoundRect", new ShapeTest(new RoundRectShape()));
}
} // end class GraphicsCards
@SuppressWarnings("serial")
class ArcCard extends Panel {
public ArcCard() {
setLayout(new GridLayout(0, 2));
add(new ArcPanel(true));
add(new ArcPanel(false));
add(new ArcDegreePanel(true));
add(new ArcDegreePanel(false));
}
} // end class ArcCard
@SuppressWarnings("serial")
class ArcDegreePanel extends Panel {
boolean filled;
public ArcDegreePanel(boolean filled) {
this.filled = filled;
}
void arcSteps(Graphics g,
int step,
int x,
int y,
int w,
int h,
Color c1,
Color c2) {
int a1 = 0;
int a2 = step;
int progress = 0;
g.setColor(c1);
for (; (a1 + a2) <= 360; a1 = a1 + a2, a2 += 1) {
if (g.getColor() == c1) {
g.setColor(c2);
} else {
g.setColor(c1);
}
if (filled) {
g.fillArc(x, y, w, h, a1, a2);
} else {
g.drawArc(x, y, w, h, a1, a2);
}
progress = a1 + a2;
} // end for
if (progress != 360) {
if (filled) {
g.fillArc(x, y, w, h, a1, 360 - progress);
} else {
g.drawArc(x, y, w, h, a1, 360 - progress);
}
} // end if
} // end arcSteps()
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
arcSteps(g, 3, 0, 0, r.width, r.height, Color.orange, Color.blue);
arcSteps(g,
2,
r.width / 4,
r.height / 4,
r.width / 2,
r.height / 2,
Color.yellow,
Color.green);
arcSteps(g,
1,
(r.width * 3) / 8,
(r.height * 3) / 8,
r.width / 4,
r.height / 4,
Color.magenta,
Color.white);
} // end paint()
} // end class ArcDegreePanel
@SuppressWarnings("serial")
class ArcPanel extends Panel {
boolean filled;
public ArcPanel(boolean filled) {
this.filled = filled;
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.yellow);
if (filled) {
g.fillArc(0, 0, r.width, r.height, 0, 45);
} else {
g.drawArc(0, 0, r.width, r.height, 0, 45);
}
g.setColor(Color.green);
if (filled) {
g.fillArc(0, 0, r.width, r.height, 90, -45);
} else {
g.drawArc(0, 0, r.width, r.height, 90, -45);
}
g.setColor(Color.orange);
if (filled) {
g.fillArc(0, 0, r.width, r.height, 135, -45);
} else {
g.drawArc(0, 0, r.width, r.height, 135, -45);
}
g.setColor(Color.magenta);
if (filled) {
g.fillArc(0, 0, r.width, r.height, -225, 45);
} else {
g.drawArc(0, 0, r.width, r.height, -225, 45);
}
g.setColor(Color.yellow);
if (filled) {
g.fillArc(0, 0, r.width, r.height, 225, -45);
} else {
g.drawArc(0, 0, r.width, r.height, 225, -45);
}
g.setColor(Color.green);
if (filled) {
g.fillArc(0, 0, r.width, r.height, -135, 45);
} else {
g.drawArc(0, 0, r.width, r.height, -135, 45);
}
g.setColor(Color.orange);
if (filled) {
g.fillArc(0, 0, r.width, r.height, -45, -45);
} else {
g.drawArc(0, 0, r.width, r.height, -45, -45);
}
g.setColor(Color.magenta);
if (filled) {
g.fillArc(0, 0, r.width, r.height, 315, 45);
} else {
g.drawArc(0, 0, r.width, r.height, 315, 45);
}
} // end paint()
} // end class ArcPanel
abstract class Shape {
abstract void draw(Graphics g, int x, int y, int w, int h);
abstract void fill(Graphics g, int x, int y, int w, int h);
}
class RectShape extends Shape {
@Override
void draw(Graphics g, int x, int y, int w, int h) {
g.drawRect(x, y, w, h);
}
@Override
void fill(Graphics g, int x, int y, int w, int h) {
g.fillRect(x, y, w, h);
}
}
class OvalShape extends Shape {
@Override
void draw(Graphics g, int x, int y, int w, int h) {
g.drawOval(x, y, w, h);
}
@Override
void fill(Graphics g, int x, int y, int w, int h) {
g.fillOval(x, y, w, h);
}
}
class RoundRectShape extends Shape {
@Override
void draw(Graphics g, int x, int y, int w, int h) {
g.drawRoundRect(x, y, w, h, 10, 10);
}
@Override
void fill(Graphics g, int x, int y, int w, int h) {
g.fillRoundRect(x, y, w, h, 10, 10);
}
}
class PolygonShape extends Shape {
// class variables
Polygon p;
Polygon pBase;
public PolygonShape() {
pBase = new Polygon();
pBase.addPoint(0, 0);
pBase.addPoint(10, 0);
pBase.addPoint(5, 15);
pBase.addPoint(10, 20);
pBase.addPoint(5, 20);
pBase.addPoint(0, 10);
pBase.addPoint(0, 0);
}
void scalePolygon(float w, float h) {
p = new Polygon();
for (int i = 0; i < pBase.npoints; ++i) {
p.addPoint((int) (pBase.xpoints[i] * w),
(int) (pBase.ypoints[i] * h));
}
}
@Override
void draw(Graphics g, int x, int y, int w, int h) {
Graphics ng = g.create();
try {
ng.translate(x, y);
scalePolygon(((float) w / 10f), ((float) h / 20f));
ng.drawPolygon(p);
} finally {
ng.dispose();
}
}
@Override
void fill(Graphics g, int x, int y, int w, int h) {
Graphics ng = g.create();
try {
ng.translate(x, y);
scalePolygon(((float) w / 10f), ((float) h / 20f));
ng.fillPolygon(p);
} finally {
ng.dispose();
}
}
}
@SuppressWarnings("serial")
class ShapeTest extends Panel {
Shape shape;
int step;
public ShapeTest(Shape shape, int step) {
this.shape = shape;
this.step = step;
}
public ShapeTest(Shape shape) {
this(shape, 10);
}
@Override
public void paint(Graphics g) {
Rectangle bounds = getBounds();
int cx, cy, cw, ch;
Color color;
for (color = Color.red, cx = bounds.x, cy = bounds.y,
cw = bounds.width / 2, ch = bounds.height;
cw > 0 && ch > 0;
cx += step, cy += step, cw -= (step * 2), ch -= (step * 2),
color = ColorUtils.darker(color, 0.9)) {
g.setColor(color);
shape.draw(g, cx, cy, cw, ch);
}
for (cx = bounds.x + bounds.width / 2, cy = bounds.y,
cw = bounds.width / 2, ch = bounds.height;
cw > 0 && ch > 0;
cx += step, cy += step, cw -= (step * 2), ch -= (step * 2)) {
if (g.getColor() == Color.red) {
g.setColor(Color.blue);
} else {
g.setColor(Color.red);
}
shape.fill(g, cx, cy, cw, ch);
} // end for
} // end paint()
} // end class ShapeTest
class ColorUtils {
static Color brighter(Color c, double factor) {
return new Color(Math.min((int) (c.getRed() * (1 / factor)), 255),
Math.min((int) (c.getGreen() * (1 / factor)), 255),
Math.min((int) (c.getBlue() * (1 / factor)), 255));
}
static Color darker(Color c, double factor) {
return new Color(Math.max((int) (c.getRed() * factor), 0),
Math.max((int) (c.getGreen() * factor), 0),
Math.max((int) (c.getBlue() * factor), 0));
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>Graphics Test (1.1)</title>
</head>
<body>
<h1>Graphics Test (1.1)</h1>
<hr>
<applet code=GraphicsTest.class width=400 height=400>
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="GraphicsTest.java">The source</a>.
</body>
</html>

View File

@ -1,248 +0,0 @@
/*
* Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/** A fairly conventional 3D matrix object that can transform sets of
3D points and perform a variety of manipulations on the transform */
class Matrix3D {
float xx, xy, xz, xo;
float yx, yy, yz, yo;
float zx, zy, zz, zo;
static final double pi = 3.14159265;
/** Create a new unit matrix */
Matrix3D() {
xx = 1.0f;
yy = 1.0f;
zz = 1.0f;
}
/** Scale by f in all dimensions */
void scale(float f) {
xx *= f;
xy *= f;
xz *= f;
xo *= f;
yx *= f;
yy *= f;
yz *= f;
yo *= f;
zx *= f;
zy *= f;
zz *= f;
zo *= f;
}
/** Scale along each axis independently */
void scale(float xf, float yf, float zf) {
xx *= xf;
xy *= xf;
xz *= xf;
xo *= xf;
yx *= yf;
yy *= yf;
yz *= yf;
yo *= yf;
zx *= zf;
zy *= zf;
zz *= zf;
zo *= zf;
}
/** Translate the origin */
void translate(float x, float y, float z) {
xo += x;
yo += y;
zo += z;
}
/** rotate theta degrees about the y axis */
void yrot(double theta) {
theta *= (pi / 180);
double ct = Math.cos(theta);
double st = Math.sin(theta);
float Nxx = (float) (xx * ct + zx * st);
float Nxy = (float) (xy * ct + zy * st);
float Nxz = (float) (xz * ct + zz * st);
float Nxo = (float) (xo * ct + zo * st);
float Nzx = (float) (zx * ct - xx * st);
float Nzy = (float) (zy * ct - xy * st);
float Nzz = (float) (zz * ct - xz * st);
float Nzo = (float) (zo * ct - xo * st);
xo = Nxo;
xx = Nxx;
xy = Nxy;
xz = Nxz;
zo = Nzo;
zx = Nzx;
zy = Nzy;
zz = Nzz;
}
/** rotate theta degrees about the x axis */
void xrot(double theta) {
theta *= (pi / 180);
double ct = Math.cos(theta);
double st = Math.sin(theta);
float Nyx = (float) (yx * ct + zx * st);
float Nyy = (float) (yy * ct + zy * st);
float Nyz = (float) (yz * ct + zz * st);
float Nyo = (float) (yo * ct + zo * st);
float Nzx = (float) (zx * ct - yx * st);
float Nzy = (float) (zy * ct - yy * st);
float Nzz = (float) (zz * ct - yz * st);
float Nzo = (float) (zo * ct - yo * st);
yo = Nyo;
yx = Nyx;
yy = Nyy;
yz = Nyz;
zo = Nzo;
zx = Nzx;
zy = Nzy;
zz = Nzz;
}
/** rotate theta degrees about the z axis */
void zrot(double theta) {
theta *= (pi / 180);
double ct = Math.cos(theta);
double st = Math.sin(theta);
float Nyx = (float) (yx * ct + xx * st);
float Nyy = (float) (yy * ct + xy * st);
float Nyz = (float) (yz * ct + xz * st);
float Nyo = (float) (yo * ct + xo * st);
float Nxx = (float) (xx * ct - yx * st);
float Nxy = (float) (xy * ct - yy * st);
float Nxz = (float) (xz * ct - yz * st);
float Nxo = (float) (xo * ct - yo * st);
yo = Nyo;
yx = Nyx;
yy = Nyy;
yz = Nyz;
xo = Nxo;
xx = Nxx;
xy = Nxy;
xz = Nxz;
}
/** Multiply this matrix by a second: M = M*R */
void mult(Matrix3D rhs) {
float lxx = xx * rhs.xx + yx * rhs.xy + zx * rhs.xz;
float lxy = xy * rhs.xx + yy * rhs.xy + zy * rhs.xz;
float lxz = xz * rhs.xx + yz * rhs.xy + zz * rhs.xz;
float lxo = xo * rhs.xx + yo * rhs.xy + zo * rhs.xz + rhs.xo;
float lyx = xx * rhs.yx + yx * rhs.yy + zx * rhs.yz;
float lyy = xy * rhs.yx + yy * rhs.yy + zy * rhs.yz;
float lyz = xz * rhs.yx + yz * rhs.yy + zz * rhs.yz;
float lyo = xo * rhs.yx + yo * rhs.yy + zo * rhs.yz + rhs.yo;
float lzx = xx * rhs.zx + yx * rhs.zy + zx * rhs.zz;
float lzy = xy * rhs.zx + yy * rhs.zy + zy * rhs.zz;
float lzz = xz * rhs.zx + yz * rhs.zy + zz * rhs.zz;
float lzo = xo * rhs.zx + yo * rhs.zy + zo * rhs.zz + rhs.zo;
xx = lxx;
xy = lxy;
xz = lxz;
xo = lxo;
yx = lyx;
yy = lyy;
yz = lyz;
yo = lyo;
zx = lzx;
zy = lzy;
zz = lzz;
zo = lzo;
}
/** Reinitialize to the unit matrix */
void unit() {
xo = 0;
xx = 1;
xy = 0;
xz = 0;
yo = 0;
yx = 0;
yy = 1;
yz = 0;
zo = 0;
zx = 0;
zy = 0;
zz = 1;
}
/** Transform nvert points from v into tv. v contains the input
coordinates in floating point. Three successive entries in
the array constitute a point. tv ends up holding the transformed
points as integers; three successive entries per point */
void transform(float v[], int tv[], int nvert) {
float lxx = xx, lxy = xy, lxz = xz, lxo = xo;
float lyx = yx, lyy = yy, lyz = yz, lyo = yo;
float lzx = zx, lzy = zy, lzz = zz, lzo = zo;
for (int i = nvert * 3; (i -= 3) >= 0;) {
float x = v[i];
float y = v[i + 1];
float z = v[i + 2];
tv[i] = (int) (x * lxx + y * lxy + z * lxz + lxo);
tv[i + 1] = (int) (x * lyx + y * lyy + z * lyz + lyo);
tv[i + 2] = (int) (x * lzx + y * lzy + z * lzz + lzo);
}
}
@Override
public String toString() {
return ("[" + xo + "," + xx + "," + xy + "," + xz + ";"
+ yo + "," + yx + "," + yy + "," + yz + ";"
+ zo + "," + zx + "," + zy + "," + zz + "]");
}
}

View File

@ -1,584 +0,0 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.applet.Applet;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.net.URL;
import java.awt.image.IndexColorModel;
import java.awt.image.MemoryImageSource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* A set of classes to parse, represent and display Chemical compounds in
* .xyz format (see http://chem.leeds.ac.uk/Project/MIME.html)
*/
/** The representation of a Chemical .xyz model */
final class XYZChemModel {
float vert[];
Atom atoms[];
int tvert[];
int ZsortMap[];
int nvert, maxvert;
static final Map<String, Atom> atomTable = new HashMap<String, Atom>();
static Atom defaultAtom;
static {
atomTable.put("c", new Atom(0, 0, 0));
atomTable.put("h", new Atom(210, 210, 210));
atomTable.put("n", new Atom(0, 0, 255));
atomTable.put("o", new Atom(255, 0, 0));
atomTable.put("p", new Atom(255, 0, 255));
atomTable.put("s", new Atom(255, 255, 0));
atomTable.put("hn", new Atom(150, 255, 150)); /* !!*/
defaultAtom = new Atom(255, 100, 200);
}
boolean transformed;
Matrix3D mat;
float xmin, xmax, ymin, ymax, zmin, zmax;
XYZChemModel() {
mat = new Matrix3D();
mat.xrot(20);
mat.yrot(30);
}
/** Create a Chemical model by parsing an input stream */
XYZChemModel(InputStream is) throws Exception {
this();
StreamTokenizer st = new StreamTokenizer(
new BufferedReader(new InputStreamReader(is, "UTF-8")));
st.eolIsSignificant(true);
st.commentChar('#');
try {
scan:
while (true) {
switch (st.nextToken()) {
case StreamTokenizer.TT_EOF:
break scan;
default:
break;
case StreamTokenizer.TT_WORD:
String name = st.sval;
double x = 0,
y = 0,
z = 0;
if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
x = st.nval;
if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
y = st.nval;
if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
z = st.nval;
}
}
}
addVert(name, (float) x, (float) y, (float) z);
while (st.ttype != StreamTokenizer.TT_EOL
&& st.ttype != StreamTokenizer.TT_EOF) {
st.nextToken();
}
} // end Switch
} // end while
is.close();
} // end Try
catch (IOException e) {
}
if (st.ttype != StreamTokenizer.TT_EOF) {
throw new Exception(st.toString());
}
} // end XYZChemModel()
/** Add a vertex to this model */
int addVert(String name, float x, float y, float z) {
int i = nvert;
if (i >= maxvert) {
if (vert == null) {
maxvert = 100;
vert = new float[maxvert * 3];
atoms = new Atom[maxvert];
} else {
maxvert *= 2;
float nv[] = new float[maxvert * 3];
System.arraycopy(vert, 0, nv, 0, vert.length);
vert = nv;
Atom na[] = new Atom[maxvert];
System.arraycopy(atoms, 0, na, 0, atoms.length);
atoms = na;
}
}
Atom a = atomTable.get(name.toLowerCase());
if (a == null) {
a = defaultAtom;
}
atoms[i] = a;
i *= 3;
vert[i] = x;
vert[i + 1] = y;
vert[i + 2] = z;
return nvert++;
}
/** Transform all the points in this model */
void transform() {
if (transformed || nvert <= 0) {
return;
}
if (tvert == null || tvert.length < nvert * 3) {
tvert = new int[nvert * 3];
}
mat.transform(vert, tvert, nvert);
transformed = true;
}
/** Paint this model to a graphics context. It uses the matrix associated
with this model to map from model space to screen space.
The next version of the browser should have double buffering,
which will make this *much* nicer */
void paint(Graphics g) {
if (vert == null || nvert <= 0) {
return;
}
transform();
int v[] = tvert;
int zs[] = ZsortMap;
if (zs == null) {
ZsortMap = zs = new int[nvert];
for (int i = nvert; --i >= 0;) {
zs[i] = i * 3;
}
}
/*
* I use a bubble sort since from one iteration to the next, the sort
* order is pretty stable, so I just use what I had last time as a
* "guess" of the sorted order. With luck, this reduces O(N log N)
* to O(N)
*/
for (int i = nvert - 1; --i >= 0;) {
boolean flipped = false;
for (int j = 0; j <= i; j++) {
int a = zs[j];
int b = zs[j + 1];
if (v[a + 2] > v[b + 2]) {
zs[j + 1] = a;
zs[j] = b;
flipped = true;
}
}
if (!flipped) {
break;
}
}
int lim = nvert;
if (lim <= 0 || nvert <= 0) {
return;
}
for (int i = 0; i < lim; i++) {
int j = zs[i];
int grey = v[j + 2];
if (grey < 0) {
grey = 0;
}
if (grey > 15) {
grey = 15;
}
// g.drawString(names[i], v[j], v[j+1]);
atoms[j / 3].paint(g, v[j], v[j + 1], grey);
// g.drawImage(iBall, v[j] - (iBall.width >> 1), v[j + 1] -
// (iBall.height >> 1));
}
}
/** Find the bounding box of this model */
void findBB() {
if (nvert <= 0) {
return;
}
float v[] = vert;
float _xmin = v[0], _xmax = _xmin;
float _ymin = v[1], _ymax = _ymin;
float _zmin = v[2], _zmax = _zmin;
for (int i = nvert * 3; (i -= 3) > 0;) {
float x = v[i];
if (x < _xmin) {
_xmin = x;
}
if (x > _xmax) {
_xmax = x;
}
float y = v[i + 1];
if (y < _ymin) {
_ymin = y;
}
if (y > _ymax) {
_ymax = y;
}
float z = v[i + 2];
if (z < _zmin) {
_zmin = z;
}
if (z > _zmax) {
_zmax = z;
}
}
this.xmax = _xmax;
this.xmin = _xmin;
this.ymax = _ymax;
this.ymin = _ymin;
this.zmax = _zmax;
this.zmin = _zmin;
}
}
/** An applet to put a Chemical model into a page */
@SuppressWarnings("serial")
public class XYZApp extends Applet implements Runnable, MouseListener,
MouseMotionListener {
XYZChemModel md;
boolean painted = true;
float xfac;
int prevx, prevy;
float scalefudge = 1;
Matrix3D amat = new Matrix3D(), tmat = new Matrix3D();
String mdname = null;
String message = null;
Image backBuffer;
Graphics backGC;
Dimension backSize;
private synchronized void newBackBuffer() {
backBuffer = createImage(getSize().width, getSize().height);
if (backGC != null) {
backGC.dispose();
}
backGC = backBuffer.getGraphics();
backSize = getSize();
}
@Override
public void init() {
mdname = getParameter("model");
try {
scalefudge = Float.valueOf(getParameter("scale")).floatValue();
} catch (Exception ignored) {
}
amat.yrot(20);
amat.xrot(20);
if (mdname == null) {
mdname = "model.obj";
}
resize(getSize().width <= 20 ? 400 : getSize().width,
getSize().height <= 20 ? 400 : getSize().height);
newBackBuffer();
addMouseListener(this);
addMouseMotionListener(this);
}
@Override
public void destroy() {
removeMouseListener(this);
removeMouseMotionListener(this);
}
@Override
public void run() {
InputStream is = null;
try {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
is = getClass().getResourceAsStream(mdname);
XYZChemModel m = new XYZChemModel(is);
Atom.setApplet(this);
md = m;
m.findBB();
float xw = m.xmax - m.xmin;
float yw = m.ymax - m.ymin;
float zw = m.zmax - m.zmin;
if (yw > xw) {
xw = yw;
}
if (zw > xw) {
xw = zw;
}
float f1 = getSize().width / xw;
float f2 = getSize().height / xw;
xfac = 0.7f * (f1 < f2 ? f1 : f2) * scalefudge;
} catch (Exception e) {
Logger.getLogger(XYZApp.class.getName()).log(Level.SEVERE, null, e);
md = null;
message = e.toString();
}
try {
if (is != null) {
is.close();
}
} catch (Exception ignored) {
}
repaint();
}
@Override
public void start() {
if (md == null && message == null) {
new Thread(this).start();
}
}
@Override
public void stop() {
}
/* event handling */
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
prevx = e.getX();
prevy = e.getY();
e.consume();
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
tmat.unit();
float xtheta = (prevy - y) * (360.0f / getSize().width);
float ytheta = (x - prevx) * (360.0f / getSize().height);
tmat.xrot(xtheta);
tmat.yrot(ytheta);
amat.mult(tmat);
if (painted) {
painted = false;
repaint();
}
prevx = x;
prevy = y;
e.consume();
}
@Override
public void mouseMoved(MouseEvent e) {
}
@Override
public void update(Graphics g) {
if (backBuffer == null) {
g.clearRect(0, 0, getSize().width, getSize().height);
}
paint(g);
}
@Override
public void paint(Graphics g) {
if (md != null) {
md.mat.unit();
md.mat.translate(-(md.xmin + md.xmax) / 2,
-(md.ymin + md.ymax) / 2,
-(md.zmin + md.zmax) / 2);
md.mat.mult(amat);
// md.mat.scale(xfac, -xfac, 8 * xfac / getSize().width);
md.mat.scale(xfac, -xfac, 16 * xfac / getSize().width);
md.mat.translate(getSize().width / 2, getSize().height / 2, 8);
md.transformed = false;
if (backBuffer != null) {
if (!backSize.equals(getSize())) {
newBackBuffer();
}
backGC.setColor(getBackground());
backGC.fillRect(0, 0, getSize().width, getSize().height);
md.paint(backGC);
g.drawImage(backBuffer, 0, 0, this);
} else {
md.paint(g);
}
setPainted();
} else if (message != null) {
g.drawString("Error in model:", 3, 20);
g.drawString(message, 10, 40);
}
}
private synchronized void setPainted() {
painted = true;
notifyAll();
}
@Override
public String getAppletInfo() {
return "Title: XYZApp \nAuthor: James Gosling \nAn applet to put"
+ " a Chemical model into a page.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "model", "path string", "The path to the model to be displayed"
+ " in .xyz format "
+ "(see http://chem.leeds.ac.uk/Project/MIME.html)."
+ " Default is model.obj." },
{ "scale", "float", "Scale factor. Default is 1 (i.e. no scale)." }
};
return info;
}
} // end class XYZApp
class Atom {
private static Applet applet;
private static byte[] data;
private static final int R = 40;
private static final int hx = 15;
private static final int hy = 15;
private static final int bgGrey = 192;
private static final int nBalls = 16;
private static int maxr;
private int Rl;
private int Gl;
private int Bl;
private Image balls[];
static {
data = new byte[R * 2 * R * 2];
int mr = 0;
for (int Y = 2 * R; --Y >= 0;) {
int x0 = (int) (Math.sqrt(R * R - (Y - R) * (Y - R)) + 0.5);
int p = Y * (R * 2) + R - x0;
for (int X = -x0; X < x0; X++) {
int x = X + hx;
int y = Y - R + hy;
int r = (int) (Math.sqrt(x * x + y * y) + 0.5);
if (r > mr) {
mr = r;
}
data[p++] = r <= 0 ? 1 : (byte) r;
}
}
maxr = mr;
}
static void setApplet(Applet app) {
applet = app;
}
Atom(int Rl, int Gl, int Bl) {
this.Rl = Rl;
this.Gl = Gl;
this.Bl = Bl;
}
private int blend(int fg, int bg, float fgfactor) {
return (int) (bg + (fg - bg) * fgfactor);
}
private void Setup() {
balls = new Image[nBalls];
byte red[] = new byte[256];
red[0] = (byte) bgGrey;
byte green[] = new byte[256];
green[0] = (byte) bgGrey;
byte blue[] = new byte[256];
blue[0] = (byte) bgGrey;
for (int r = 0; r < nBalls; r++) {
float b = (float) (r + 1) / nBalls;
for (int i = maxr; i >= 1; --i) {
float d = (float) i / maxr;
red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b);
green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b);
blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b);
}
IndexColorModel model = new IndexColorModel(8, maxr + 1,
red, green, blue, 0);
balls[r] = applet.createImage(
new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2));
}
}
void paint(Graphics gc, int x, int y, int r) {
Image ba[] = balls;
if (ba == null) {
Setup();
ba = balls;
}
Image i = ba[r];
int size = 10 + r;
gc.drawImage(i, x - (size >> 1), y - (size >> 1), size, size, applet);
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>MoleculeViewer (example 1)</title>
</head>
<body>
<h1>MoleculeViewer (example 1)</h1>
<hr>
<applet code=XYZApp.class archive=MoleculeViewer.jar width=300 height=300>
<param name=model value="models/HyaluronicAcid.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="XYZApp.java">The source</a>.
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>MoleculeViewer (example 2)</title>
</head>
<body>
<h1>MoleculeViewer (example 2)</h1>
<hr>
<applet code=XYZApp.class archive=MoleculeViewer.jar width=300 height=300>
<param name=model value="models/buckminsterfullerine.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="XYZApp.java">The source</a>.
</body>
</html>

View File

@ -1,35 +0,0 @@
<html>
<head>
<title>MoleculeViewer (example 3)</title>
</head>
<body>
<h1>MoleculeViewer (example 3)</h1>
<hr>
<applet code=XYZApp.class archive=MoleculeViewer.jar width=100 height=100>
<param name=model value="models/water.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<p>
<applet code=XYZApp.class archive=MoleculeViewer.jar width=100 height=100>
<param name=model value="models/benzene.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<p>
<applet code=XYZApp.class archive=MoleculeViewer.jar width=100 height=100>
<param name=model value="models/ethane.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<p>
<applet code=XYZApp.class archive=MoleculeViewer.jar width=100 height=100>
<param name=model value="models/cyclohexane.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="XYZApp.java">The source</a>.
</body>
</html>

View File

@ -1,172 +0,0 @@
C 2.239 -2.685 1.669
C 2.855 -3.796 2.510
C 1.869 -4.276 3.564
C 1.354 -3.098 4.381
C .821 -2.009 3.456
C .399 -.762 4.204
O 3.247 -4.867 1.659
O 2.510 -5.217 4.426
O .299 -3.516 5.245
O 1.838 -1.612 2.523
O -.802 -.735 4.550
O 1.305 .081 4.380
H 1.361 -3.074 1.132
H 3.765 -3.422 3.002
H 1.023 -4.780 3.073
H 2.171 -2.692 4.995
H -.053 -2.388 2.907
C .387 -3.112 6.571
C -.990 -3.246 7.207
C -.920 -2.952 8.698
C .148 -3.814 9.357
C 1.472 -3.671 8.613
C 2.547 -4.592 9.151
O -2.190 -3.215 9.298
O .342 -3.416 10.712
O 1.298 -3.997 7.226
O 3.792 -4.400 8.482
H .742 -2.076 6.677
H -1.369 -4.266 7.052
H -.681 -1.889 8.852
H -.169 -4.867 9.342
H 1.835 -2.636 8.706
H 2.697 -4.395 10.223
H 2.238 -5.638 9.011
N -1.932 -2.323 6.533
C -3.286 -2.571 6.622
C -4.126 -1.552 5.889
O -3.760 -3.516 7.231
H -3.588 -.594 5.847
H -4.324 -1.906 4.867
H -5.080 -1.413 6.420
HN -1.600 -1.576 6.050
C -2.685 -2.239 10.154
C -3.796 -2.855 10.995
C -4.276 -1.869 12.049
C -3.098 -1.354 12.866
C -2.009 -.821 11.941
C -.762 -.399 12.689
O -4.867 -3.247 10.144
O -5.217 -2.510 12.911
O -3.516 -.299 13.730
O -1.612 -1.838 11.008
O -.735 .802 13.035
O .081 -1.305 12.865
H -3.074 -1.361 9.617
H -3.422 -3.765 11.487
H -4.780 -1.023 11.558
H -2.692 -2.171 13.480
H -2.388 .053 11.392
C -3.112 -.387 15.056
C -3.246 .990 15.692
C -2.952 .920 17.183
C -3.814 -.148 17.842
C -3.671 -1.472 17.098
C -4.592 -2.547 17.636
O -3.215 2.190 17.783
O -3.416 -.342 19.197
O -3.997 -1.298 15.711
O -4.400 -3.792 16.967
H -2.076 -.742 15.162
H -4.266 1.369 15.537
H -1.889 .681 17.337
H -4.867 .169 17.827
H -2.636 -1.835 17.191
H -4.395 -2.697 18.708
H -5.638 -2.238 17.496
N -2.323 1.932 15.018
C -2.571 3.286 15.107
C -1.552 4.126 14.374
O -3.516 3.760 15.716
H -.594 3.588 14.332
H -1.906 4.324 13.352
H -1.413 5.080 14.905
HN -1.576 1.600 14.535
C -2.239 2.685 18.639
C -2.855 3.796 19.480
C -1.869 4.276 20.534
C -1.354 3.098 21.351
C -.821 2.009 20.426
C -.399 .762 21.174
O -3.247 4.867 18.629
O -2.510 5.217 21.396
O -.299 3.516 22.215
O -1.838 1.612 19.493
O .802 .735 21.520
O -1.305 -.081 21.350
H -1.361 3.074 18.102
H -3.765 3.422 19.972
H -1.023 4.780 20.043
H -2.171 2.692 21.965
H .053 2.388 19.877
C -.387 3.112 23.541
C .990 3.246 24.177
C .920 2.952 25.668
C -.148 3.814 26.327
C -1.472 3.671 25.583
C -2.547 4.592 26.121
O 2.190 3.215 26.268
O -.342 3.416 27.682
O -1.298 3.997 24.196
O -3.792 4.400 25.452
H -.742 2.076 23.647
H 1.369 4.266 24.022
H .681 1.889 25.822
H .169 4.867 26.312
H -1.835 2.636 25.676
H -2.697 4.395 27.193
H -2.238 5.638 25.981
N 1.932 2.323 23.503
C 3.286 2.571 23.592
C 4.126 1.552 22.859
O 3.760 3.516 24.201
H 3.588 .594 22.817
H 4.324 1.906 21.837
H 5.080 1.413 23.390
HN 1.600 1.576 23.020
C 2.685 2.239 27.124
C 3.796 2.855 27.965
C 4.276 1.869 29.019
C 3.098 1.354 29.836
C 2.009 .821 28.911
C .762 .399 29.659
O 4.867 3.247 27.114
O 5.217 2.510 29.881
O 3.516 .299 30.700
O 1.612 1.838 27.978
O .735 -.802 30.005
O -.081 1.305 29.835
H 3.074 1.361 26.587
H 3.422 3.765 28.457
H 4.780 1.023 28.528
H 2.692 2.171 30.450
H 2.388 -.053 28.362
C 3.112 .387 32.026
C 3.246 -.990 32.662
C 2.952 -.920 34.153
C 3.814 .148 34.812
C 3.671 1.472 34.068
C 4.592 2.547 34.606
O 3.215 -2.190 34.754
O 3.416 .342 36.167
O 3.997 1.298 32.681
O 4.400 3.792 33.937
H 2.076 .742 32.132
H 4.266 -1.369 32.507
H 1.889 -.681 34.307
H 4.867 -.169 34.797
H 2.636 1.835 34.161
H 4.395 2.697 35.678
H 5.638 2.238 34.466
N 2.323 -1.932 31.988
C 2.571 -3.286 32.077
C 1.552 -4.126 31.344
O 3.516 -3.760 32.686
H .594 -3.588 31.302
H 1.906 -4.324 30.322
H 1.413 -5.080 31.875
HN 1.576 -1.600 31.505
NA -.446 .954 2.480
NA .954 .446 10.965
NA .446 -.954 19.450
NA -.954 -.446 27.935

View File

@ -1,12 +0,0 @@
C 0.0998334 0.995004 0
H 0.159733 1.59201 0
C 0.911616 0.411044 0
H 1.45859 0.65767 0
C 0.811782 -0.58396 0
H 1.29885 -0.934337 0
C -0.0998334 -0.995004 0
H -0.159733 -1.59201 0
C -0.911616 -0.411044 0
H -1.45858 -0.65767 0
C -0.811782 0.583961 0
H -1.29885 0.934337 0

View File

@ -1,63 +0,0 @@
# buckmisterfullerine http://chem.leeds.ac.uk/Project/MIME.html
60
C 1.22650000 0.00000000 3.31450000
C 0.37900000 1.16640000 3.31450000
C -0.99220000 0.72090000 3.31450000
C -0.99220000 -0.72090000 3.31450000
C 0.37900000 -1.16640000 3.31450000
C 3.40840000 0.72090000 0.59480000
C 2.79510000 1.16640000 1.82130000
C 2.41610000 0.00000000 2.57930000
C 2.79510000 -1.16640000 1.82130000
C 3.40840000 -0.72090000 0.59480000
C 0.36760000 3.46430000 0.59480000
C -0.24560000 3.01880000 1.82130000
C 0.74660000 2.29790000 2.57930000
C 1.97310000 2.29790000 1.82130000
C 1.73890000 3.01880000 0.59480000
C -3.18120000 1.42020000 0.59480000
C -2.94690000 0.69930000 1.82130000
C -1.95470000 1.42020000 2.57930000
C -1.57570000 2.58660000 1.82130000
C -2.33370000 2.58660000 0.59480000
C -2.33370000 -2.58660000 0.59480000
C -1.57570000 -2.58660000 1.82130000
C -1.95470000 -1.42020000 2.57930000
C -2.94690000 -0.69930000 1.82130000
C -3.18120000 -1.42020000 0.59480000
C 1.73890000 -3.01880000 0.59480000
C 1.97310000 -2.29790000 1.82130000
C 0.74660000 -2.29790000 2.57930000
C -0.24560000 -3.01880000 1.82130000
C 0.36760000 -3.46430000 0.59480000
C 0.99220000 0.72090000 -3.31450000
C -0.37900000 1.16640000 -3.31450000
C -1.22650000 0.00000000 -3.31450000
C -0.37900000 -1.16640000 -3.31450000
C 0.99220000 -0.72090000 -3.31450000
C 2.33370000 2.58660000 -0.59480000
C 1.57570000 2.58660000 -1.82130000
C 1.95470000 1.42020000 -2.57930000
C 2.94690000 0.69930000 -1.82130000
C 3.18120000 1.42020000 -0.59480000
C -1.73890000 3.01880000 -0.59480000
C -1.97310000 2.29790000 -1.82130000
C -0.74660000 2.29790000 -2.57930000
C 0.24560000 3.01880000 -1.82130000
C -0.36760000 3.46430000 -0.59480000
C -3.40840000 -0.72090000 -0.59480000
C -2.79510000 -1.16640000 -1.82130000
C -2.41610000 0.00000000 -2.57930000
C -2.79510000 1.16640000 -1.82130000
C -3.40840000 0.72090000 -0.59480000
C -0.36760000 -3.46430000 -0.59480000
C 0.24560000 -3.01880000 -1.82130000
C -0.74660000 -2.29790000 -2.57930000
C -1.97310000 -2.29790000 -1.82130000
C -1.73890000 -3.01880000 -0.59480000
C 3.18120000 -1.42020000 -0.59480000
C 2.94690000 -0.69930000 -1.82130000
C 1.95470000 -1.42020000 -2.57930000
C 1.57570000 -2.58660000 -1.82130000
C 2.33370000 -2.58660000 -0.59480000

View File

@ -1,18 +0,0 @@
H 0.0998334 0.995004 -1.2
H 0.139767 1.39301 -0.12
C 0.0998334 0.995004 -0.2
H 0.911616 0.411044 1.2
H 1.27626 0.575461 0.12
C 0.911616 0.411044 0.2
H 0.811782 -0.58396 -1.2
H 1.1365 -0.817544 -0.12
C 0.811782 -0.58396 -0.2
H -0.0998334 -0.995004 1.2
H -0.139767 -1.39301 0.12
C -0.0998334 -0.995004 0.2
H -0.911616 -0.411044 -1.2
H -1.27626 -0.575461 -0.12
C -0.911616 -0.411044 -0.2
H -0.811782 0.583961 1.2
H -1.13649 0.817545 0.12
C -0.811782 0.583961 0.2

View File

@ -1,8 +0,0 @@
H 0.0998334 0.995004 -0.6
H 0.911616 0.411044 1.6
H 0.811782 -0.58396 -0.6
H -0.0998334 -0.995004 1.6
H -0.911616 -0.411044 -0.6
H -0.811782 0.583961 1.6
C 0 0 0
C 0 0 1

View File

@ -1,4 +0,0 @@
# water -- this is *wrong* Just a guess
o 0 0 0
h -1 1 0
h 1 1 0

View File

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

View File

@ -1,7 +0,0 @@
<title>Nervous Text 1.1</title>
<hr>
<applet code="NervousText.class" width=534 height=50>
<param name=text value="Java Development Kit (JDK) ">
</applet>
<hr>
<a href="NervousText.java">The source.</a>

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.awt.Graphics;
@SuppressWarnings("serial")
public class GraphApplet extends java.applet.Applet {
double f(double x) {
return (Math.cos(x / 5) + Math.sin(x / 7) + 2) * getSize().height / 4;
}
@Override
public void paint(Graphics g) {
for (int x = 0; x < getSize().width; x++) {
g.drawLine(x, (int) f(x), x + 1, (int) f(x + 1));
}
}
@Override
public String getAppletInfo() {
return "Draws a sin graph.";
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>Simple Graph (1.1)</title>
</head>
<body>
<h1>Simple Graph(1.1)</h1>
<hr>
<applet code=GraphApplet.class width=300 height=120>
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="GraphApplet.java">The source</a>.
</body>
</html>

View File

@ -1,93 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* A bi-directional bubble sort demonstration algorithm
* SortAlgorithm.java, Thu Oct 27 10:32:35 1994
*
* @author James Gosling
*/
class BidirBubbleSortAlgorithm extends SortAlgorithm {
@Override
void sort(int a[]) throws Exception {
int j;
int limit = a.length;
int st = -1;
while (st < limit) {
st++;
limit--;
boolean swapped = false;
for (j = st; j < limit; j++) {
if (stopRequested) {
return;
}
if (a[j] > a[j + 1]) {
int T = a[j];
a[j] = a[j + 1];
a[j + 1] = T;
swapped = true;
}
pause(st, limit);
}
if (!swapped) {
return;
} else {
swapped = false;
}
for (j = limit; --j >= st;) {
if (stopRequested) {
return;
}
if (a[j] > a[j + 1]) {
int T = a[j];
a[j] = a[j + 1];
a[j + 1] = T;
swapped = true;
}
pause(st, limit);
}
if (!swapped) {
return;
}
}
}
}

View File

@ -1,71 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* A bubble sort demonstration algorithm
* SortAlgorithm.java, Thu Oct 27 10:32:35 1994
*
* @author James Gosling
*/
class BubbleSortAlgorithm extends SortAlgorithm {
@Override
void sort(int a[]) throws Exception {
for (int i = a.length; --i >= 0;) {
boolean swapped = false;
for (int j = 0; j < i; j++) {
if (stopRequested) {
return;
}
if (a[j] > a[j + 1]) {
int T = a[j];
a[j] = a[j + 1];
a[j + 1] = T;
swapped = true;
}
pause(i, j);
}
if (!swapped) {
return;
}
}
}
}

View File

@ -1,139 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* A quick sort demonstration algorithm
* SortAlgorithm.java
*
* @author James Gosling
* @author Kevin A. Smith
*/
public class QSortAlgorithm extends SortAlgorithm {
/**
* A version of pause() that makes it easier to ensure that we pause
* exactly the right number of times.
*/
private boolean pauseTrue(int lo, int hi) throws Exception {
super.pause(lo, hi);
return true;
}
/** This is a generic version of C.A.R Hoare's Quick Sort
* algorithm. This will handle arrays that are already
* sorted, and arrays with duplicate keys.<BR>
*
* If you think of a one dimensional array as going from
* the lowest index on the left to the highest index on the right
* then the parameters to this function are lowest index or
* left and highest index or right. The first time you call
* this function it will be with the parameters 0, a.length - 1.
*
* @param a an integer array
* @param lo0 left boundary of array partition
* @param hi0 right boundary of array partition
*/
void QuickSort(int a[], int lo0, int hi0) throws Exception {
int lo = lo0;
int hi = hi0;
int mid;
if (hi0 > lo0) {
/* Arbitrarily establishing partition element as the midpoint of
* the array.
*/
mid = a[(lo0 + hi0) / 2];
// loop through the array until indices cross
while (lo <= hi) {
/* find the first element that is greater than or equal to
* the partition element starting from the left Index.
*/
while ((lo < hi0) && pauseTrue(lo0, hi0) && (a[lo] < mid)) {
++lo;
}
/* find an element that is smaller than or equal to
* the partition element starting from the right Index.
*/
while ((hi > lo0) && pauseTrue(lo0, hi0) && (a[hi] > mid)) {
--hi;
}
// if the indexes have not crossed, swap
if (lo <= hi) {
swap(a, lo, hi);
++lo;
--hi;
}
}
/* If the right index has not reached the left side of array
* must now sort the left partition.
*/
if (lo0 < hi) {
QuickSort(a, lo0, hi);
}
/* If the left index has not reached the right side of array
* must now sort the right partition.
*/
if (lo < hi0) {
QuickSort(a, lo, hi0);
}
}
}
private void swap(int a[], int i, int j) {
int T;
T = a[i];
a[i] = a[j];
a[j] = T;
}
@Override
public void sort(int a[]) throws Exception {
QuickSort(a, 0, a.length - 1);
}
}

View File

@ -1,116 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* A generic sort demonstration algorithm
* SortAlgorithm.java, Thu Oct 27 10:32:35 1994
*
* @author James Gosling
*/
class SortAlgorithm {
/**
* The sort item.
*/
private SortItem parent;
/**
* When true stop sorting.
*/
protected boolean stopRequested = false;
/**
* Set the parent.
*/
public void setParent(SortItem p) {
parent = p;
}
/**
* Pause for a while.
*/
protected void pause() throws Exception {
if (stopRequested) {
throw new Exception("Sort Algorithm");
}
parent.pause(parent.h1, parent.h2);
}
/**
* Pause for a while and mark item 1.
*/
protected void pause(int H1) throws Exception {
if (stopRequested) {
throw new Exception("Sort Algorithm");
}
parent.pause(H1, parent.h2);
}
/**
* Pause for a while and mark item 1 & 2.
*/
protected void pause(int H1, int H2) throws Exception {
if (stopRequested) {
throw new Exception("Sort Algorithm");
}
parent.pause(H1, H2);
}
/**
* Stop sorting.
*/
public void stop() {
stopRequested = true;
}
/**
* Initialize
*/
public void init() {
stopRequested = false;
}
/**
* This method will be called to
* sort an array of integers.
*/
void sort(int a[]) throws Exception {
}
}

View File

@ -1,331 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* A simple applet class to demonstrate a sort algorithm.
* You can specify a sorting algorithm using the "alg"
* attribute. When you click on the applet, a thread is
* forked which animates the sorting algorithm.
*
* @author James Gosling
*/
@SuppressWarnings("serial")
public class SortItem extends java.applet.Applet implements Runnable,
MouseListener {
/**
* The thread that is sorting (or null).
*/
private Thread kicker;
/**
* The array that is being sorted.
*/
int arr[];
/**
* The high water mark.
*/
int h1 = -1;
/**
* The low water mark.
*/
int h2 = -1;
/**
* The name of the algorithm.
*/
String algName;
/**
* The sorting algorithm (or null).
*/
SortAlgorithm algorithm;
Dimension initialSize = null;
/**
* Fill the array with random numbers from 0..n-1.
*/
void scramble() {
initialSize = getSize();
int a[] = new int[initialSize.height / 2];
double f = initialSize.width / (double) a.length;
for (int i = a.length; --i >= 0;) {
a[i] = (int) (i * f);
}
for (int i = a.length; --i >= 0;) {
int j = (int) (i * Math.random());
int t = a[i];
a[i] = a[j];
a[j] = t;
}
arr = a;
}
/**
* Pause a while.
* @see SortAlgorithm
*/
void pause() {
pause(-1, -1);
}
/**
* Pause a while, and draw the high water mark.
* @see SortAlgorithm
*/
void pause(int H1) {
pause(H1, -1);
}
/**
* Pause a while, and draw the low&high water marks.
* @see SortAlgorithm
*/
void pause(int H1, int H2) {
h1 = H1;
h2 = H2;
if (kicker != null) {
repaint();
}
try {
Thread.sleep(20);
} catch (InterruptedException e) {
}
}
/**
* Initialize the applet.
*/
@Override
public void init() {
String at = getParameter("alg");
if (at == null) {
at = "BubbleSort";
}
algName = at + "Algorithm";
scramble();
resize(100, 100);
addMouseListener(this);
}
@Override
public void start() {
h1 = h2 = -1;
scramble();
repaint();
showStatus(getParameter("alg"));
}
/**
* Deallocate resources of applet.
*/
@Override
public void destroy() {
removeMouseListener(this);
}
/**
* Paint the array of numbers as a list
* of horizontal lines of varying lengths.
*/
@Override
public void paint(Graphics g) {
int a[] = arr;
int y = 0;
int deltaY = 0, deltaX = 0, evenY = 0;
Dimension currentSize = getSize();
int currentHeight = currentSize.height;
int currentWidth = currentSize.width;
// Check to see if the applet has been resized since it
// started running. If so, need the deltas to make sure
// the applet is centered in its containing panel.
// The evenX and evenY are because the high and low
// watermarks are calculated from the top, but the rest
// of the lines are calculated from the bottom, which
// can lead to a discrepancy if the window is not an
// even size.
if (!currentSize.equals(initialSize)) {
evenY = (currentHeight - initialSize.height) % 2;
deltaY = (currentHeight - initialSize.height) / 2;
deltaX = (currentWidth - initialSize.width) / 2;
if (deltaY < 0) {
deltaY = 0;
evenY = 0;
}
if (deltaX < 0) {
deltaX = 0;
}
}
// Erase old lines
g.setColor(getBackground());
y = currentHeight - deltaY - 1;
for (int i = a.length; --i >= 0; y -= 2) {
g.drawLine(deltaX + arr[i], y, currentWidth, y);
}
// Draw new lines
g.setColor(Color.black);
y = currentHeight - deltaY - 1;
for (int i = a.length; --i >= 0; y -= 2) {
g.drawLine(deltaX, y, deltaX + arr[i], y);
}
if (h1 >= 0) {
g.setColor(Color.red);
y = deltaY + evenY + h1 * 2 + 1;
g.drawLine(deltaX, y, deltaX + initialSize.width, y);
}
if (h2 >= 0) {
g.setColor(Color.blue);
y = deltaY + evenY + h2 * 2 + 1;
g.drawLine(deltaX, y, deltaX + initialSize.width, y);
}
}
/**
* Update without erasing the background.
*/
@Override
public void update(Graphics g) {
paint(g);
}
/**
* Run the sorting algorithm. This method is
* called by class Thread once the sorting algorithm
* is started.
* @see java.lang.Thread#run
* @see SortItem#mouseUp
*/
@Override
public void run() {
try {
if (algorithm == null) {
algorithm = (SortAlgorithm) Class.forName(algName).newInstance();
algorithm.setParent(this);
}
algorithm.init();
algorithm.sort(arr);
} catch (Exception e) {
}
}
/**
* Stop the applet. Kill any sorting algorithm that
* is still sorting.
*/
@Override
public synchronized void stop() {
if (algorithm != null) {
try {
algorithm.stop();
} catch (IllegalThreadStateException e) {
// ignore this exception
}
kicker = null;
}
}
/**
* For a Thread to actually do the sorting. This routine makes
* sure we do not simultaneously start several sorts if the user
* repeatedly clicks on the sort item. It needs to be
* synchronized with the stop() method because they both
* manipulate the common kicker variable.
*/
private synchronized void startSort() {
if (kicker == null || !kicker.isAlive()) {
kicker = new Thread(this);
kicker.start();
}
}
@Override
public void mouseClicked(MouseEvent e) {
showStatus(getParameter("alg"));
}
@Override
public void mousePressed(MouseEvent e) {
}
/**
* The user clicked in the applet. Start the clock!
*/
@Override
public void mouseReleased(MouseEvent e) {
startSort();
e.consume();
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public String getAppletInfo() {
return "Title: SortDemo \nAuthor: James Gosling 1.17f, 10 Apr 1995 \nA simple applet class to demonstrate a sort algorithm. \nYou can specify a sorting algorithm using the 'alg' attribute. \nWhen you click on the applet, a thread is forked which animates \nthe sorting algorithm.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "alg", "string",
"The name of the algorithm to run. You can choose from the provided algorithms or suppply your own, as long as the classes are runnable as threads and their names end in 'Algorithm.' BubbleSort is the default. Example: Use 'QSort' to run the QSortAlgorithm class." }
};
return info;
}
}

View File

@ -1,39 +0,0 @@
<html>
<head>
<title>The Sorting Algorithm Demo (1.1)</title>
</head>
<body>
<h1>The Sorting Algorithm Demo (1.1)</h1>
<hr>
<table width="340">
<tr>
<th><strong>Bubble Sort</strong></th>
<th><strong>Bidirectional Bubble Sort</strong></th>
<th><strong>Quick Sort</strong></th>
</tr>
<tr>
<th>
<applet code=SortItem.class width=100 height=100><param name="alg" value="BubbleSort">alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."Your browser is completely ignoring the &lt;APPLET&gt; tag!</applet>
</th>
<th>
<applet code=SortItem.class width=100 height=100><param name="alg" value="BidirBubbleSort">alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."Your browser is completely ignoring the &lt;APPLET&gt; tag!</applet>
</th>
<th>
<applet code=SortItem.class width=100 height=100><param name="alg" value="QSort">alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."Your browser is completely ignoring the &lt;APPLET&gt; tag!</applet>
</th>
</tr>
</table>
<hr>
<h2>The Sources</h2>
<a href="SortItem.java">The applet.</a><br>
<a href="SortAlgorithm.java">The "generic" sorting algorithm.</a><br>
<a href="BidirBubbleSortAlgorithm.java">The Bi-directional Bubble Sort algorithm.</a><br>
<a href="BubbleSortAlgorithm.java">The Bubble Sort algorithm.</a><br>
<a href="QSortAlgorithm.java">The Quick Sort algorithm.</a>
</body>
</html>

View File

@ -1,956 +0,0 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
@SuppressWarnings("serial")
public class SpreadSheet extends Applet implements MouseListener, KeyListener {
String title;
Font titleFont;
Color cellColor;
Color inputColor;
int cellWidth = 100;
int cellHeight = 15;
int titleHeight = 15;
int rowLabelWidth = 15;
Font inputFont;
boolean isStopped = false;
boolean fullUpdate = true;
int rows;
int columns;
int currentKey = -1;
int selectedRow = -1;
int selectedColumn = -1;
SpreadSheetInput inputArea;
Cell cells[][];
Cell current = null;
@Override
public synchronized void init() {
String rs;
cellColor = Color.white;
inputColor = new Color(100, 100, 225);
inputFont = new Font("Monospaced", Font.PLAIN, 10);
titleFont = new Font("Monospaced", Font.BOLD, 12);
title = getParameter("title");
if (title == null) {
title = "Spreadsheet";
}
rs = getParameter("rows");
if (rs == null) {
rows = 9;
} else {
rows = Integer.parseInt(rs);
}
rs = getParameter("columns");
if (rs == null) {
columns = 5;
} else {
columns = Integer.parseInt(rs);
}
cells = new Cell[rows][columns];
char l[] = new char[1];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
cells[i][j] = new Cell(this,
Color.lightGray,
Color.black,
cellColor,
cellWidth - 2,
cellHeight - 2);
l[0] = (char) ((int) 'a' + j);
rs = getParameter("" + new String(l) + (i + 1));
if (rs != null) {
cells[i][j].setUnparsedValue(rs);
}
}
}
Dimension d = getSize();
inputArea = new SpreadSheetInput(null, this, d.width - 2, cellHeight - 1,
inputColor, Color.white);
resize(columns * cellWidth + rowLabelWidth,
(rows + 3) * cellHeight + titleHeight);
addMouseListener(this);
addKeyListener(this);
}
public void setCurrentValue(float val) {
if (selectedRow == -1 || selectedColumn == -1) {
return;
}
cells[selectedRow][selectedColumn].setValue(val);
repaint();
}
@Override
public void stop() {
isStopped = true;
}
@Override
public void start() {
isStopped = false;
}
@Override
public void destroy() {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (cells[i][j].type == Cell.URL) {
cells[i][j].updaterThread.run = false;
}
}
}
}
public void setCurrentValue(int type, String val) {
if (selectedRow == -1 || selectedColumn == -1) {
return;
}
cells[selectedRow][selectedColumn].setValue(type, val);
repaint();
}
@Override
public void update(Graphics g) {
if (!fullUpdate) {
int cx, cy;
g.setFont(titleFont);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (cells[i][j].needRedisplay) {
cx = (j * cellWidth) + 2 + rowLabelWidth;
cy = ((i + 1) * cellHeight) + 2 + titleHeight;
cells[i][j].paint(g, cx, cy);
}
}
}
} else {
paint(g);
fullUpdate = false;
}
}
public void recalculate() {
int i, j;
//System.out.println("SpreadSheet.recalculate");
for (i = 0; i < rows; i++) {
for (j = 0; j < columns; j++) {
if (cells[i][j] != null && cells[i][j].type == Cell.FORMULA) {
cells[i][j].setRawValue(evaluateFormula(
cells[i][j].parseRoot));
cells[i][j].needRedisplay = true;
}
}
}
repaint();
}
float evaluateFormula(Node n) {
float val = 0.0f;
//System.out.println("evaluateFormula:");
//n.print(3);
if (n == null) {
//System.out.println("Null node");
return val;
}
switch (n.type) {
case Node.OP:
val = evaluateFormula(n.left);
switch (n.op) {
case '+':
val += evaluateFormula(n.right);
break;
case '*':
val *= evaluateFormula(n.right);
break;
case '-':
val -= evaluateFormula(n.right);
break;
case '/':
val /= evaluateFormula(n.right);
break;
}
break;
case Node.VALUE:
//System.out.println("=>" + n.value);
return n.value;
case Node.CELL:
if (cells[n.row][n.column] == null) {
//System.out.println("NULL at 193");
} else {
//System.out.println("=>" + cells[n.row][n.column].value);
return cells[n.row][n.column].value;
}
}
//System.out.println("=>" + val);
return val;
}
@Override
public synchronized void paint(Graphics g) {
int i, j;
int cx, cy;
char l[] = new char[1];
Dimension d = getSize();
g.setFont(titleFont);
i = g.getFontMetrics().stringWidth(title);
g.drawString((title == null) ? "Spreadsheet" : title,
(d.width - i) / 2, 12);
g.setColor(inputColor);
g.fillRect(0, cellHeight, d.width, cellHeight);
g.setFont(titleFont);
for (i = 0; i < rows + 1; i++) {
cy = (i + 2) * cellHeight;
g.setColor(getBackground());
g.draw3DRect(0, cy, d.width, 2, true);
if (i < rows) {
g.setColor(Color.red);
g.drawString("" + (i + 1), 2, cy + 12);
}
}
g.setColor(Color.red);
cy = (rows + 3) * cellHeight + (cellHeight / 2);
for (i = 0; i < columns; i++) {
cx = i * cellWidth;
g.setColor(getBackground());
g.draw3DRect(cx + rowLabelWidth,
2 * cellHeight, 1, d.height, true);
if (i < columns) {
g.setColor(Color.red);
l[0] = (char) ((int) 'A' + i);
g.drawString(new String(l),
cx + rowLabelWidth + (cellWidth / 2),
cy);
}
}
for (i = 0; i < rows; i++) {
for (j = 0; j < columns; j++) {
cx = (j * cellWidth) + 2 + rowLabelWidth;
cy = ((i + 1) * cellHeight) + 2 + titleHeight;
if (cells[i][j] != null) {
cells[i][j].paint(g, cx, cy);
}
}
}
g.setColor(getBackground());
g.draw3DRect(0, titleHeight,
d.width,
d.height - titleHeight,
false);
inputArea.paint(g, 1, titleHeight + 1);
}
//1.1 event handling
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
Cell cell;
if (y < (titleHeight + cellHeight)) {
selectedRow = -1;
if (y <= titleHeight && current != null) {
current.deselect();
current = null;
}
e.consume();
}
if (x < rowLabelWidth) {
selectedRow = -1;
if (current != null) {
current.deselect();
current = null;
}
e.consume();
}
selectedRow = ((y - cellHeight - titleHeight) / cellHeight);
selectedColumn = (x - rowLabelWidth) / cellWidth;
if (selectedRow > rows
|| selectedColumn >= columns) {
selectedRow = -1;
if (current != null) {
current.deselect();
current = null;
}
} else {
if (selectedRow >= rows) {
selectedRow = -1;
if (current != null) {
current.deselect();
current = null;
}
e.consume();
}
if (selectedRow != -1) {
cell = cells[selectedRow][selectedColumn];
inputArea.setText(cell.getPrintString());
if (current != null) {
current.deselect();
}
current = cell;
current.select();
requestFocus();
fullUpdate = true;
repaint();
}
e.consume();
}
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {
fullUpdate = true;
inputArea.processKey(e);
e.consume();
}
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public String getAppletInfo() {
return "Title: SpreadSheet \nAuthor: Sami Shaio \nA simple spread sheet.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "title", "string",
"The title of the spread sheet. Default is 'Spreadsheet'" },
{ "rows", "int", "The number of rows. Default is 9." },
{ "columns", "int", "The number of columns. Default is 5." }
};
return info;
}
}
class CellUpdater extends Thread {
Cell target;
InputStream dataStream = null;
StreamTokenizer tokenStream;
public volatile boolean run = true;
public CellUpdater(Cell c) {
super("cell updater");
target = c;
}
@Override
public void run() {
try {
dataStream = new URL(target.app.getDocumentBase(),
target.getValueString()).openStream();
tokenStream = new StreamTokenizer(new BufferedReader(
new InputStreamReader(dataStream)));
tokenStream.eolIsSignificant(false);
while (run) {
switch (tokenStream.nextToken()) {
case StreamTokenizer.TT_EOF:
dataStream.close();
return;
default:
break;
case StreamTokenizer.TT_NUMBER:
target.setTransientValue((float) tokenStream.nval);
if (!target.app.isStopped && !target.paused) {
target.app.repaint();
}
break;
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
break;
}
}
} catch (IOException e) {
return;
}
}
}
class Cell {
public static final int VALUE = 0;
public static final int LABEL = 1;
public static final int URL = 2;
public static final int FORMULA = 3;
Node parseRoot;
boolean needRedisplay;
boolean selected = false;
boolean transientValue = false;
public int type = Cell.VALUE;
String valueString = "";
String printString = "v";
float value;
Color bgColor;
Color fgColor;
Color highlightColor;
int width;
int height;
SpreadSheet app;
CellUpdater updaterThread;
boolean paused = false;
public Cell(SpreadSheet app,
Color bgColor,
Color fgColor,
Color highlightColor,
int width,
int height) {
this.app = app;
this.bgColor = bgColor;
this.fgColor = fgColor;
this.highlightColor = highlightColor;
this.width = width;
this.height = height;
needRedisplay = true;
}
public void setRawValue(float f) {
valueString = Float.toString(f);
value = f;
}
public void setValue(float f) {
setRawValue(f);
printString = "v" + valueString;
type = Cell.VALUE;
paused = false;
app.recalculate();
needRedisplay = true;
}
public void setTransientValue(float f) {
transientValue = true;
value = f;
needRedisplay = true;
app.recalculate();
}
public void setUnparsedValue(String s) {
switch (s.charAt(0)) {
case 'v':
setValue(Cell.VALUE, s.substring(1));
break;
case 'f':
setValue(Cell.FORMULA, s.substring(1));
break;
case 'l':
setValue(Cell.LABEL, s.substring(1));
break;
case 'u':
setValue(Cell.URL, s.substring(1));
break;
}
}
/**
* Parse a spreadsheet formula. The syntax is defined as:
*
* formula -> value
* formula -> value op value
* value -> '(' formula ')'
* value -> cell
* value -> <number>
* op -> '+' | '*' | '/' | '-'
* cell -> <letter><number>
*/
public String parseFormula(String formula, Node node) {
String subformula;
String restFormula;
Node left;
Node right;
char op;
if (formula == null) {
return null;
}
subformula = parseValue(formula, node);
//System.out.println("subformula = " + subformula);
if (subformula == null || subformula.length() == 0) {
//System.out.println("Parse succeeded");
return null;
}
if (subformula.equals(formula)) {
//System.out.println("Parse failed");
return formula;
}
// parse an operator and then another value
switch (op = subformula.charAt(0)) {
case 0:
//System.out.println("Parse succeeded");
return null;
case ')':
//System.out.println("Returning subformula=" + subformula);
return subformula;
case '+':
case '*':
case '-':
case '/':
restFormula = subformula.substring(1);
subformula = parseValue(restFormula, right = new Node());
//System.out.println("subformula(2) = " + subformula);
if (subformula == null ? restFormula != null : !subformula.
equals(restFormula)) {
//System.out.println("Parse succeeded");
left = new Node(node);
node.left = left;
node.right = right;
node.op = op;
node.type = Node.OP;
//node.print(3);
return subformula;
} else {
//System.out.println("Parse failed");
return formula;
}
default:
//System.out.println("Parse failed (bad operator): " + subformula);
return formula;
}
}
public String parseValue(String formula, Node node) {
char c = formula.charAt(0);
String subformula;
String restFormula;
float _value;
int row;
int column;
//System.out.println("parseValue: " + formula);
restFormula = formula;
if (c == '(') {
//System.out.println("parseValue(" + formula + ")");
restFormula = formula.substring(1);
subformula = parseFormula(restFormula, node);
//System.out.println("rest=(" + subformula + ")");
if (subformula == null
|| subformula.length() == restFormula.length()) {
//System.out.println("Failed");
return formula;
} else if (!(subformula.charAt(0) == ')')) {
//System.out.println("Failed (missing parentheses)");
return formula;
}
restFormula = subformula;
} else if (c >= '0' && c <= '9') {
int i;
//System.out.println("formula=" + formula);
for (i = 0; i < formula.length(); i++) {
c = formula.charAt(i);
if ((c < '0' || c > '9') && c != '.') {
break;
}
}
try {
_value = Float.valueOf(formula.substring(0, i)).floatValue();
} catch (NumberFormatException e) {
//System.out.println("Failed (number format error)");
return formula;
}
node.type = Node.VALUE;
node.value = _value;
//node.print(3);
restFormula = formula.substring(i);
//System.out.println("value= " + value + " i=" + i +
// " rest = " + restFormula);
return restFormula;
} else if (c >= 'A' && c <= 'Z') {
int i;
column = c - 'A';
restFormula = formula.substring(1);
for (i = 0; i < restFormula.length(); i++) {
c = restFormula.charAt(i);
if (c < '0' || c > '9') {
break;
}
}
row = Float.valueOf(restFormula.substring(0, i)).intValue();
//System.out.println("row = " + row + " column = " + column);
node.row = row - 1;
node.column = column;
node.type = Node.CELL;
//node.print(3);
if (i == restFormula.length()) {
restFormula = null;
} else {
restFormula = restFormula.substring(i);
if (restFormula.charAt(0) == 0) {
return null;
}
}
}
return restFormula;
}
public void setValue(int type, String s) {
paused = false;
if (this.type == Cell.URL) {
updaterThread.run = false;
updaterThread = null;
}
valueString = s;
this.type = type;
needRedisplay = true;
switch (type) {
case Cell.VALUE:
setValue(Float.valueOf(s).floatValue());
break;
case Cell.LABEL:
printString = "l" + valueString;
break;
case Cell.URL:
printString = "u" + valueString;
updaterThread = new CellUpdater(this);
updaterThread.start();
break;
case Cell.FORMULA:
parseFormula(valueString, parseRoot = new Node());
printString = "f" + valueString;
break;
}
app.recalculate();
}
public String getValueString() {
return valueString;
}
public String getPrintString() {
return printString;
}
public void select() {
selected = true;
paused = true;
}
public void deselect() {
selected = false;
paused = false;
needRedisplay = true;
app.repaint();
}
public void paint(Graphics g, int x, int y) {
if (selected) {
g.setColor(highlightColor);
} else {
g.setColor(bgColor);
}
g.fillRect(x, y, width - 1, height);
if (valueString != null) {
switch (type) {
case Cell.VALUE:
case Cell.LABEL:
g.setColor(fgColor);
break;
case Cell.FORMULA:
g.setColor(Color.red);
break;
case Cell.URL:
g.setColor(Color.blue);
break;
}
if (transientValue) {
g.drawString("" + value, x, y + (height / 2) + 5);
} else {
if (valueString.length() > 14) {
g.drawString(valueString.substring(0, 14),
x, y + (height / 2) + 5);
} else {
g.drawString(valueString, x, y + (height / 2) + 5);
}
}
}
needRedisplay = false;
}
}
class Node {
public static final int OP = 0;
public static final int VALUE = 1;
public static final int CELL = 2;
int type;
Node left;
Node right;
int row;
int column;
float value;
char op;
public Node() {
left = null;
right = null;
value = 0;
row = -1;
column = -1;
op = 0;
type = Node.VALUE;
}
public Node(Node n) {
left = n.left;
right = n.right;
value = n.value;
row = n.row;
column = n.column;
op = n.op;
type = n.type;
}
public void indent(int ind) {
for (int i = 0; i < ind; i++) {
System.out.print(" ");
}
}
public void print(int indentLevel) {
char l[] = new char[1];
indent(indentLevel);
System.out.println("NODE type=" + type);
indent(indentLevel);
switch (type) {
case Node.VALUE:
System.out.println(" value=" + value);
break;
case Node.CELL:
l[0] = (char) ((int) 'A' + column);
System.out.println(" cell=" + new String(l) + (row + 1));
break;
case Node.OP:
System.out.println(" op=" + op);
left.print(indentLevel + 3);
right.print(indentLevel + 3);
break;
}
}
}
class InputField {
int maxchars = 50;
int cursorPos = 0;
Applet app;
String sval;
char buffer[];
int nChars;
int width;
int height;
Color bgColor;
Color fgColor;
public InputField(String initValue, Applet app, int width, int height,
Color bgColor, Color fgColor) {
this.width = width;
this.height = height;
this.bgColor = bgColor;
this.fgColor = fgColor;
this.app = app;
buffer = new char[maxchars];
nChars = 0;
if (initValue != null) {
initValue.getChars(0, initValue.length(), this.buffer, 0);
nChars = initValue.length();
}
sval = initValue;
}
public void setText(String val) {
int i;
for (i = 0; i < maxchars; i++) {
buffer[i] = 0;
}
if (val == null) {
sval = "";
} else {
sval = val;
}
nChars = sval.length();
sval.getChars(0, sval.length(), buffer, 0);
}
public String getValue() {
return sval;
}
public void paint(Graphics g, int x, int y) {
g.setColor(bgColor);
g.fillRect(x, y, width, height);
if (sval != null) {
g.setColor(fgColor);
g.drawString(sval, x, y + (height / 2) + 3);
}
}
public void processKey(KeyEvent e) {
char ch = e.getKeyChar();
switch (ch) {
case '\b': // delete
if (nChars > 0) {
nChars--;
sval = new String(buffer, 0, nChars);
}
break;
case '\n': // return
selected();
break;
default:
if (nChars < maxchars && ch >= '0') {
buffer[nChars++] = ch;
sval = new String(buffer, 0, nChars);
}
}
app.repaint();
}
public void keyReleased(KeyEvent e) {
}
public void selected() {
}
}
class SpreadSheetInput
extends InputField {
public SpreadSheetInput(String initValue,
SpreadSheet app,
int width,
int height,
Color bgColor,
Color fgColor) {
super(initValue, app, width, height, bgColor, fgColor);
}
@Override
public void selected() {
float f;
sval = ("".equals(sval)) ? "v" : sval;
switch (sval.charAt(0)) {
case 'v':
String s = sval.substring(1);
try {
int i;
for (i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c < '0' || c > '9') {
break;
}
}
s = s.substring(0, i);
f = Float.valueOf(s).floatValue();
((SpreadSheet) app).setCurrentValue(f);
} catch (NumberFormatException e) {
System.out.println("Not a float: '" + s + "'");
}
break;
case 'l':
((SpreadSheet) app).setCurrentValue(Cell.LABEL,
sval.substring(1));
break;
case 'u':
((SpreadSheet) app).setCurrentValue(Cell.URL, sval.substring(1));
break;
case 'f':
((SpreadSheet) app).setCurrentValue(Cell.FORMULA,
sval.substring(1));
break;
}
}
}

View File

@ -1,25 +0,0 @@
<html>
<head>
<title>SpreadSheet</title>
</head>
<body>
<h1>SpreadSheet</h1>
<hr>
<applet code="SpreadSheet.class" width=320 height=120>
<param name=rows value="4">
<param name=c3 value="fC1+C2">
<param name=c2 value="fA2*B2">
<param name=c1 value="fA1*B1">
<param name=title value="Example">
<param name=b2 value="v1000">
<param name=b1 value="v500">
<param name=columns value="3">
<param name=a2 value="v30">
<param name=a1 value="v10">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="SpreadSheet.java">The source</a>.
</body>
</html>

View File

@ -1,248 +0,0 @@
/*
* Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/** A fairly conventional 3D matrix object that can transform sets of
3D points and perform a variety of manipulations on the transform */
class Matrix3D {
float xx, xy, xz, xo;
float yx, yy, yz, yo;
float zx, zy, zz, zo;
static final double pi = 3.14159265;
/** Create a new unit matrix */
Matrix3D() {
xx = 1.0f;
yy = 1.0f;
zz = 1.0f;
}
/** Scale by f in all dimensions */
void scale(float f) {
xx *= f;
xy *= f;
xz *= f;
xo *= f;
yx *= f;
yy *= f;
yz *= f;
yo *= f;
zx *= f;
zy *= f;
zz *= f;
zo *= f;
}
/** Scale along each axis independently */
void scale(float xf, float yf, float zf) {
xx *= xf;
xy *= xf;
xz *= xf;
xo *= xf;
yx *= yf;
yy *= yf;
yz *= yf;
yo *= yf;
zx *= zf;
zy *= zf;
zz *= zf;
zo *= zf;
}
/** Translate the origin */
void translate(float x, float y, float z) {
xo += x;
yo += y;
zo += z;
}
/** rotate theta degrees about the y axis */
void yrot(double theta) {
theta *= (pi / 180);
double ct = Math.cos(theta);
double st = Math.sin(theta);
float Nxx = (float) (xx * ct + zx * st);
float Nxy = (float) (xy * ct + zy * st);
float Nxz = (float) (xz * ct + zz * st);
float Nxo = (float) (xo * ct + zo * st);
float Nzx = (float) (zx * ct - xx * st);
float Nzy = (float) (zy * ct - xy * st);
float Nzz = (float) (zz * ct - xz * st);
float Nzo = (float) (zo * ct - xo * st);
xo = Nxo;
xx = Nxx;
xy = Nxy;
xz = Nxz;
zo = Nzo;
zx = Nzx;
zy = Nzy;
zz = Nzz;
}
/** rotate theta degrees about the x axis */
void xrot(double theta) {
theta *= (pi / 180);
double ct = Math.cos(theta);
double st = Math.sin(theta);
float Nyx = (float) (yx * ct + zx * st);
float Nyy = (float) (yy * ct + zy * st);
float Nyz = (float) (yz * ct + zz * st);
float Nyo = (float) (yo * ct + zo * st);
float Nzx = (float) (zx * ct - yx * st);
float Nzy = (float) (zy * ct - yy * st);
float Nzz = (float) (zz * ct - yz * st);
float Nzo = (float) (zo * ct - yo * st);
yo = Nyo;
yx = Nyx;
yy = Nyy;
yz = Nyz;
zo = Nzo;
zx = Nzx;
zy = Nzy;
zz = Nzz;
}
/** rotate theta degrees about the z axis */
void zrot(double theta) {
theta *= (pi / 180);
double ct = Math.cos(theta);
double st = Math.sin(theta);
float Nyx = (float) (yx * ct + xx * st);
float Nyy = (float) (yy * ct + xy * st);
float Nyz = (float) (yz * ct + xz * st);
float Nyo = (float) (yo * ct + xo * st);
float Nxx = (float) (xx * ct - yx * st);
float Nxy = (float) (xy * ct - yy * st);
float Nxz = (float) (xz * ct - yz * st);
float Nxo = (float) (xo * ct - yo * st);
yo = Nyo;
yx = Nyx;
yy = Nyy;
yz = Nyz;
xo = Nxo;
xx = Nxx;
xy = Nxy;
xz = Nxz;
}
/** Multiply this matrix by a second: M = M*R */
void mult(Matrix3D rhs) {
float lxx = xx * rhs.xx + yx * rhs.xy + zx * rhs.xz;
float lxy = xy * rhs.xx + yy * rhs.xy + zy * rhs.xz;
float lxz = xz * rhs.xx + yz * rhs.xy + zz * rhs.xz;
float lxo = xo * rhs.xx + yo * rhs.xy + zo * rhs.xz + rhs.xo;
float lyx = xx * rhs.yx + yx * rhs.yy + zx * rhs.yz;
float lyy = xy * rhs.yx + yy * rhs.yy + zy * rhs.yz;
float lyz = xz * rhs.yx + yz * rhs.yy + zz * rhs.yz;
float lyo = xo * rhs.yx + yo * rhs.yy + zo * rhs.yz + rhs.yo;
float lzx = xx * rhs.zx + yx * rhs.zy + zx * rhs.zz;
float lzy = xy * rhs.zx + yy * rhs.zy + zy * rhs.zz;
float lzz = xz * rhs.zx + yz * rhs.zy + zz * rhs.zz;
float lzo = xo * rhs.zx + yo * rhs.zy + zo * rhs.zz + rhs.zo;
xx = lxx;
xy = lxy;
xz = lxz;
xo = lxo;
yx = lyx;
yy = lyy;
yz = lyz;
yo = lyo;
zx = lzx;
zy = lzy;
zz = lzz;
zo = lzo;
}
/** Reinitialize to the unit matrix */
void unit() {
xo = 0;
xx = 1;
xy = 0;
xz = 0;
yo = 0;
yx = 0;
yy = 1;
yz = 0;
zo = 0;
zx = 0;
zy = 0;
zz = 1;
}
/** Transform nvert points from v into tv. v contains the input
coordinates in floating point. Three successive entries in
the array constitute a point. tv ends up holding the transformed
points as integers; three successive entries per point */
void transform(float v[], int tv[], int nvert) {
float lxx = xx, lxy = xy, lxz = xz, lxo = xo;
float lyx = yx, lyy = yy, lyz = yz, lyo = yo;
float lzx = zx, lzy = zy, lzz = zz, lzo = zo;
for (int i = nvert * 3; (i -= 3) >= 0;) {
float x = v[i];
float y = v[i + 1];
float z = v[i + 2];
tv[i] = (int) (x * lxx + y * lxy + z * lxz + lxo);
tv[i + 1] = (int) (x * lyx + y * lyy + z * lyz + lyo);
tv[i + 2] = (int) (x * lzx + y * lzy + z * lzz + lzo);
}
}
@Override
public String toString() {
return ("[" + xo + "," + xx + "," + xy + "," + xz + ";"
+ yo + "," + yx + "," + yy + "," + yz + ";"
+ zo + "," + zx + "," + zy + "," + zz + "]");
}
}

View File

@ -1,545 +0,0 @@
/*
* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.event.*;
import java.io.*;
import java.net.URL;
/* A set of classes to parse, represent and display 3D wireframe models
represented in Wavefront .obj format. */
@SuppressWarnings("serial")
class FileFormatException extends Exception {
public FileFormatException(String s) {
super(s);
}
}
/** The representation of a 3D model */
final class Model3D {
float vert[];
int tvert[];
int nvert, maxvert;
int con[];
int ncon, maxcon;
boolean transformed;
Matrix3D mat;
float xmin, xmax, ymin, ymax, zmin, zmax;
Model3D() {
mat = new Matrix3D();
mat.xrot(20);
mat.yrot(30);
}
/** Create a 3D model by parsing an input stream */
Model3D(InputStream is) throws IOException, FileFormatException {
this();
StreamTokenizer st = new StreamTokenizer(
new BufferedReader(new InputStreamReader(is, "UTF-8")));
st.eolIsSignificant(true);
st.commentChar('#');
scan:
while (true) {
switch (st.nextToken()) {
default:
break scan;
case StreamTokenizer.TT_EOL:
break;
case StreamTokenizer.TT_WORD:
if ("v".equals(st.sval)) {
double x = 0, y = 0, z = 0;
if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
x = st.nval;
if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
y = st.nval;
if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
z = st.nval;
}
}
}
addVert((float) x, (float) y, (float) z);
while (st.ttype != StreamTokenizer.TT_EOL && st.ttype
!= StreamTokenizer.TT_EOF) {
st.nextToken();
}
} else if ("f".equals(st.sval) || "fo".equals(st.sval) || "l".
equals(st.sval)) {
int start = -1;
int prev = -1;
int n = -1;
while (true) {
if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
n = (int) st.nval;
if (prev >= 0) {
add(prev - 1, n - 1);
}
if (start < 0) {
start = n;
}
prev = n;
} else if (st.ttype == '/') {
st.nextToken();
} else {
break;
}
}
if (start >= 0) {
add(start - 1, prev - 1);
}
if (st.ttype != StreamTokenizer.TT_EOL) {
break scan;
}
} else {
while (st.nextToken() != StreamTokenizer.TT_EOL
&& st.ttype != StreamTokenizer.TT_EOF) {
// no-op
}
}
}
}
is.close();
if (st.ttype != StreamTokenizer.TT_EOF) {
throw new FileFormatException(st.toString());
}
}
/** Add a vertex to this model */
int addVert(float x, float y, float z) {
int i = nvert;
if (i >= maxvert) {
if (vert == null) {
maxvert = 100;
vert = new float[maxvert * 3];
} else {
maxvert *= 2;
float nv[] = new float[maxvert * 3];
System.arraycopy(vert, 0, nv, 0, vert.length);
vert = nv;
}
}
i *= 3;
vert[i] = x;
vert[i + 1] = y;
vert[i + 2] = z;
return nvert++;
}
/** Add a line from vertex p1 to vertex p2 */
void add(int p1, int p2) {
int i = ncon;
if (p1 >= nvert || p2 >= nvert) {
return;
}
if (i >= maxcon) {
if (con == null) {
maxcon = 100;
con = new int[maxcon];
} else {
maxcon *= 2;
int nv[] = new int[maxcon];
System.arraycopy(con, 0, nv, 0, con.length);
con = nv;
}
}
if (p1 > p2) {
int t = p1;
p1 = p2;
p2 = t;
}
con[i] = (p1 << 16) | p2;
ncon = i + 1;
}
/** Transform all the points in this model */
void transform() {
if (transformed || nvert <= 0) {
return;
}
if (tvert == null || tvert.length < nvert * 3) {
tvert = new int[nvert * 3];
}
mat.transform(vert, tvert, nvert);
transformed = true;
}
/* Quick Sort implementation
*/
private void quickSort(int a[], int left, int right) {
int leftIndex = left;
int rightIndex = right;
int partionElement;
if (right > left) {
/* Arbitrarily establishing partition element as the midpoint of
* the array.
*/
partionElement = a[(left + right) / 2];
// loop through the array until indices cross
while (leftIndex <= rightIndex) {
/* find the first element that is greater than or equal to
* the partionElement starting from the leftIndex.
*/
while ((leftIndex < right) && (a[leftIndex] < partionElement)) {
++leftIndex;
}
/* find an element that is smaller than or equal to
* the partionElement starting from the rightIndex.
*/
while ((rightIndex > left) && (a[rightIndex] > partionElement)) {
--rightIndex;
}
// if the indexes have not crossed, swap
if (leftIndex <= rightIndex) {
swap(a, leftIndex, rightIndex);
++leftIndex;
--rightIndex;
}
}
/* If the right index has not reached the left side of array
* must now sort the left partition.
*/
if (left < rightIndex) {
quickSort(a, left, rightIndex);
}
/* If the left index has not reached the right side of array
* must now sort the right partition.
*/
if (leftIndex < right) {
quickSort(a, leftIndex, right);
}
}
}
private void swap(int a[], int i, int j) {
int T;
T = a[i];
a[i] = a[j];
a[j] = T;
}
/** eliminate duplicate lines */
void compress() {
int limit = ncon;
int c[] = con;
quickSort(con, 0, ncon - 1);
int d = 0;
int pp1 = -1;
for (int i = 0; i < limit; i++) {
int p1 = c[i];
if (pp1 != p1) {
c[d] = p1;
d++;
}
pp1 = p1;
}
ncon = d;
}
static Color gr[];
/** Paint this model to a graphics context. It uses the matrix associated
with this model to map from model space to screen space.
The next version of the browser should have double buffering,
which will make this *much* nicer */
void paint(Graphics g) {
if (vert == null || nvert <= 0) {
return;
}
transform();
if (gr == null) {
gr = new Color[16];
for (int i = 0; i < 16; i++) {
int grey = (int) (170 * (1 - Math.pow(i / 15.0, 2.3)));
gr[i] = new Color(grey, grey, grey);
}
}
int lg = 0;
int lim = ncon;
int c[] = con;
int v[] = tvert;
if (lim <= 0 || nvert <= 0) {
return;
}
for (int i = 0; i < lim; i++) {
int T = c[i];
int p1 = ((T >> 16) & 0xFFFF) * 3;
int p2 = (T & 0xFFFF) * 3;
int grey = v[p1 + 2] + v[p2 + 2];
if (grey < 0) {
grey = 0;
}
if (grey > 15) {
grey = 15;
}
if (grey != lg) {
lg = grey;
g.setColor(gr[grey]);
}
g.drawLine(v[p1], v[p1 + 1],
v[p2], v[p2 + 1]);
}
}
/** Find the bounding box of this model */
void findBB() {
if (nvert <= 0) {
return;
}
float v[] = vert;
float _xmin = v[0], _xmax = _xmin;
float _ymin = v[1], _ymax = _ymin;
float _zmin = v[2], _zmax = _zmin;
for (int i = nvert * 3; (i -= 3) > 0;) {
float x = v[i];
if (x < _xmin) {
_xmin = x;
}
if (x > _xmax) {
_xmax = x;
}
float y = v[i + 1];
if (y < _ymin) {
_ymin = y;
}
if (y > _ymax) {
_ymax = y;
}
float z = v[i + 2];
if (z < _zmin) {
_zmin = z;
}
if (z > _zmax) {
_zmax = z;
}
}
this.xmax = _xmax;
this.xmin = _xmin;
this.ymax = _ymax;
this.ymin = _ymin;
this.zmax = _zmax;
this.zmin = _zmin;
}
}
/** An applet to put a 3D model into a page */
@SuppressWarnings("serial")
public class ThreeD extends Applet
implements Runnable, MouseListener, MouseMotionListener {
Model3D md;
boolean painted = true;
float xfac;
int prevx, prevy;
float scalefudge = 1;
Matrix3D amat = new Matrix3D(), tmat = new Matrix3D();
String mdname = null;
String message = null;
@Override
public void init() {
mdname = getParameter("model");
try {
scalefudge = Float.valueOf(getParameter("scale")).floatValue();
} catch (Exception ignored) {
// fall back to default scalefudge = 1
}
amat.yrot(20);
amat.xrot(20);
if (mdname == null) {
mdname = "model.obj";
}
resize(getSize().width <= 20 ? 400 : getSize().width,
getSize().height <= 20 ? 400 : getSize().height);
addMouseListener(this);
addMouseMotionListener(this);
}
@Override
public void destroy() {
removeMouseListener(this);
removeMouseMotionListener(this);
}
@Override
public void run() {
InputStream is = null;
try {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
is = getClass().getResourceAsStream(mdname);
Model3D m = new Model3D(is);
md = m;
m.findBB();
m.compress();
float xw = m.xmax - m.xmin;
float yw = m.ymax - m.ymin;
float zw = m.zmax - m.zmin;
if (yw > xw) {
xw = yw;
}
if (zw > xw) {
xw = zw;
}
float f1 = getSize().width / xw;
float f2 = getSize().height / xw;
xfac = 0.7f * (f1 < f2 ? f1 : f2) * scalefudge;
} catch (Exception e) {
md = null;
message = e.toString();
}
try {
if (is != null) {
is.close();
}
} catch (Exception e) {
}
repaint();
}
@Override
public void start() {
if (md == null && message == null) {
new Thread(this).start();
}
}
@Override
public void stop() {
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
prevx = e.getX();
prevy = e.getY();
e.consume();
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
tmat.unit();
float xtheta = (prevy - y) * 360.0f / getSize().width;
float ytheta = (x - prevx) * 360.0f / getSize().height;
tmat.xrot(xtheta);
tmat.yrot(ytheta);
amat.mult(tmat);
if (painted) {
painted = false;
repaint();
}
prevx = x;
prevy = y;
e.consume();
}
@Override
public void mouseMoved(MouseEvent e) {
}
@Override
public void paint(Graphics g) {
if (md != null) {
md.mat.unit();
md.mat.translate(-(md.xmin + md.xmax) / 2,
-(md.ymin + md.ymax) / 2,
-(md.zmin + md.zmax) / 2);
md.mat.mult(amat);
md.mat.scale(xfac, -xfac, 16 * xfac / getSize().width);
md.mat.translate(getSize().width / 2, getSize().height / 2, 8);
md.transformed = false;
md.paint(g);
setPainted();
} else if (message != null) {
g.drawString("Error in model:", 3, 20);
g.drawString(message, 10, 40);
}
}
private synchronized void setPainted() {
painted = true;
notifyAll();
}
@Override
public String getAppletInfo() {
return "Title: ThreeD \nAuthor: James Gosling? \n"
+ "An applet to put a 3D model into a page.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "model", "path string", "The path to the model to be displayed." },
{ "scale", "float", "The scale of the model. Default is 1." }
};
return info;
}
}

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>3D Model: Cube</title>
</head>
<body>
<h1>3D Model: Cube</h1>
<hr>
<applet code=ThreeD.class archive=WireFrame.jar width=100 height=100>
<param name=model value="models/cube.obj">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="ThreeD.java">The source</a>.
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>3D Model: Dinosaur</title>
</head>
<body>
<h1>3D Model: Dinosaur</h1>
<hr>
<applet code=ThreeD.class archive=WireFrame.jar width=300 height=300>
<param name=model value="models/dinasaur.obj">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="ThreeD.java">The source</a>.
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>3D Model: Hughes</title>
</head>
<body>
<h1>3D Model: Hughes</h1>
<hr>
<applet code=ThreeD.class archive=WireFrame.jar width=300 height=300>
<param name=model value="models/hughes_500.obj">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="ThreeD.java">The source</a>.
</body>
</html>

View File

@ -1,16 +0,0 @@
<html>
<head>
<title>3D Model: knoxS</title>
</head>
<body>
<h1>3D Model: knoxS</h1>
<hr>
<applet code=ThreeD.class archive=WireFrame.jar width=300 height=300>
<param name=model value="models/knoxS.obj">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<hr>
<a href="ThreeD.java">The source</a>.
</body>
</html>

View File

@ -1,14 +0,0 @@
v 0 0 0
v 1 0 0
v 1 1 0
v 0 1 0
v 0 0 1
v 1 0 1
v 1 1 1
v 0 1 1
f 1 2 3 4
f 5 6 7 8
l 1 5
l 2 6
l 3 7
l 4 8

File diff suppressed because it is too large Load Diff

View File

@ -1,901 +0,0 @@
# Thu Aug 29 17:05:11 1991
#
#
g
v -193.121536 -44.568363 -0.251513
v -197.573380 -46.895039 -0.256472
v -198.788773 -49.016193 -0.257825
v -148.971069 -47.449108 0.487985
v -157.748093 -48.462933 0.901612
v -175.811340 -47.449108 2.064319
v -193.124741 -44.568363 2.280679
v -197.576004 -46.915585 1.802589
v -198.790024 -49.024815 0.736692
v -148.971756 -48.138371 1.010340
v -157.749634 -50.179447 2.127501
v -175.814957 -50.343334 4.924728
v -193.128799 -48.681034 5.467995
v -197.579208 -49.064030 4.336096
v -198.791382 -49.925770 1.799131
v -148.971741 -48.358227 1.004796
v -157.749634 -51.695354 2.115620
v -175.814941 -53.750546 4.897006
v -193.128754 -52.477642 5.437099
v -197.579193 -52.081844 4.311542
v -198.791382 -51.191311 1.788833
v -148.970978 -48.512630 0.424875
v -157.748047 -52.759968 0.872927
v -175.811249 -56.143414 1.997388
v -193.124695 -55.143978 2.206096
v -197.575897 -54.201244 1.743308
v -198.790009 -52.080090 0.711832
v -148.970215 -48.511135 -0.201412
v -157.746658 -52.749645 -0.211188
v -175.808426 -56.120220 -0.231307
v -193.121536 -55.118137 -0.251513
v -197.573380 -54.180706 -0.256472
v -198.788773 -52.071476 -0.257825
v -175.835815 -44.020111 2.520835
v -192.249237 -44.020111 0.089022
v -149.033737 -40.512054 5.957043
v -157.821075 -40.512054 4.856255
v -175.834793 -40.512054 1.718337
v -190.096756 -40.512054 -0.249265
v -193.319107 -32.981995 -0.252854
v -149.033737 -32.981995 5.965450
v -157.821075 -32.981995 4.858928
v -175.834793 -32.981995 1.718337
v -157.822510 -22.686403 5.986545
v -175.835815 -22.686403 2.520832
v -203.319458 -22.686403 -0.263400
v -149.035294 -22.686403 7.187805
v -149.033951 -13.661487 12.976438
v -157.822800 -13.239704 11.364350
v -175.841217 -12.341414 8.138739
v -218.859848 -9.932562 -0.279986
v -157.820206 -44.109818 4.159561
v -157.795929 -46.143688 2.892030
v -149.015671 -46.054623 4.377612
v -149.033737 -44.092472 5.954969
v -114.731369 -47.455616 1.648514
v -114.808830 -46.061138 7.371684
v -114.840164 -44.098980 9.729299
v -114.840332 -40.518570 9.851958
v -114.840347 -32.988510 9.877554
v -114.842636 -22.692911 11.680110
v -114.833809 -14.981619 16.619209
v -86.866638 -47.462948 4.298918
v -86.945099 -46.068466 10.841274
v -86.976799 -44.106312 13.504797
v -86.978119 -40.525902 14.543481
v -86.979042 -32.995842 15.279140
v -86.981201 -22.700230 16.973080
v -27.674036 -43.568142 21.946110
v -44.549297 -33.003426 19.780952
v -44.550179 -22.707819 20.497684
v -21.460979 -18.288401 21.435612
v -44.437195 -47.470531 9.048497
v -44.514172 -46.076050 14.422836
v -44.546265 -44.113895 17.389896
v 85.055260 -47.467136 9.566951
v 84.978310 -46.072659 14.941110
v 84.946236 -44.110508 17.908043
v 68.021347 -43.564747 22.548162
v 84.943199 -33.000031 20.298161
v 75.746201 -22.704430 21.009447
v 70.970001 -19.101204 21.930876
v 85.067299 -47.467136 0.059286
v -45.041111 -40.533417 18.943781
v 84.944374 -40.796600 19.374630
v 82.226730 -42.588669 18.427174
v -41.828033 -42.589798 18.166464
v 79.673470 -39.247772 19.470383
v -39.277756 -39.248901 19.220474
v 102.918846 -19.467031 21.246489
v 122.860519 -44.293362 8.534363
v 122.756577 -43.026093 13.986779
v 122.713524 -41.242935 17.011076
v 122.711594 -38.231323 18.543358
v 122.710190 -31.145979 19.637127
v 122.709312 -22.913336 20.333622
v 154.601456 -35.084190 17.534193
v 154.600418 -28.227760 18.357895
v 154.669479 -24.790649 19.310398
v 149.794647 -18.465145 19.951303
v 154.749863 -40.412964 7.742351
v 154.646179 -39.298981 13.078783
v 154.603317 -37.731514 16.040014
v 122.866699 -44.293362 3.635928
v 120.642647 -47.466251 0.104404
v 165.723557 -39.503567 7.885768
v 165.619827 -38.426041 13.331938
v 165.576935 -36.909866 16.361908
v 165.575211 -34.349174 17.790897
v 165.574158 -27.696560 18.635632
v 165.644394 -24.514065 19.685810
v 165.632629 -23.205051 19.933445
v 153.361526 -20.990608 20.149113
v 218.698013 -23.197134 17.409588
v 218.859879 -23.206814 0.233417
v 217.906036 -34.818779 0.232852
v 217.897858 -34.818779 7.380709
v 217.795074 -34.083824 12.370145
v 218.003616 -33.049683 15.120919
v 218.221451 -31.303102 16.453737
v 218.704147 -24.170685 17.239691
v 26.770920 -18.608509 21.686554
v 34.043495 -18.608231 21.725981
v 34.098499 -18.608231 -21.703093
v 26.825840 -18.608509 -21.679869
v 218.743103 -24.170685 -16.773199
v 218.258591 -31.303102 -15.987810
v 218.037659 -33.049683 -14.655252
v 217.822861 -34.083824 -11.904680
v 217.914215 -34.818779 -6.915005
v 218.738449 -23.197134 -16.831234
v 153.410522 -20.990608 -19.848755
v 165.680908 -23.205051 -19.612167
v 165.692078 -24.514065 -19.364510
v 165.619278 -27.696560 -18.314417
v 165.618240 -34.349174 -17.469687
v 165.616501 -36.909866 -16.040697
v 165.651978 -38.426041 -13.010636
v 165.742432 -39.503567 -7.564241
v 122.875648 -44.293362 -3.422154
v 154.642868 -37.731514 -15.746773
v 154.678360 -39.298981 -12.785454
v 154.768753 -40.412964 -7.448800
v 149.843933 -18.465145 -19.663754
v 154.717194 -24.790649 -19.017067
v 154.645752 -28.227760 -18.064655
v 154.644730 -35.084190 -17.240952
v 122.760559 -22.913336 -20.120155
v 122.759674 -31.145979 -19.423656
v 122.758270 -38.231323 -18.329887
v 122.756340 -41.242935 -16.797607
v 122.791702 -43.026093 -13.773222
v 122.881859 -44.293362 -8.320590
v 102.972412 -19.467031 -21.056477
v -39.228889 -39.248901 -19.358833
v 79.722641 -39.247772 -19.363771
v -41.781818 -42.589798 -18.310507
v 82.273254 -42.588669 -18.314878
v 84.993301 -40.796600 -19.256279
v -44.992966 -40.533417 -19.094976
v 71.025414 -19.101204 -21.829052
v 75.799278 -22.704430 -20.901999
v 84.994453 -33.000031 -20.179810
v 68.078354 -43.564747 -22.467506
v 84.991455 -44.110508 -17.789692
v 85.015999 -46.072659 -14.822695
v 85.079361 -47.467136 -9.448378
v -44.502033 -44.113895 -17.539997
v -44.477455 -46.076050 -14.572871
v -44.414082 -47.470531 -9.198376
v -21.406540 -18.288401 -21.558340
v -44.498085 -22.707819 -20.647781
v -44.499001 -33.003426 -19.931049
v -27.618309 -43.568142 -22.058607
v -86.937897 -22.700230 -17.226698
v -86.940025 -32.995842 -15.532762
v -86.940956 -40.525902 -14.797100
v -86.942299 -44.106312 -13.758418
v -86.917328 -46.068466 -11.094831
v -86.855408 -47.462948 -4.552318
v -114.791275 -14.981464 -16.945929
v -114.812637 -22.692911 -12.006871
v -114.814926 -32.988510 -10.204315
v -114.814972 -40.518570 -10.178719
v -114.815102 -44.098980 -10.056059
v -114.789734 -46.061138 -7.698379
v -114.726784 -47.455616 -1.975055
v -149.018173 -44.092472 -6.357917
v -149.004089 -46.054623 -4.780525
v -157.788071 -46.143688 -3.314508
v -157.809143 -44.109818 -4.582088
v -175.820068 -12.341250 -8.601345
v -157.793457 -13.239477 -11.786820
v -149.000549 -13.661228 -13.379333
v -149.016586 -22.686403 -7.590753
v -175.828827 -22.686403 -2.983499
v -157.806839 -22.686403 -6.409072
v -175.829819 -32.981995 -2.181006
v -157.808243 -32.981995 -5.281456
v -149.018158 -32.981995 -6.368398
v -175.829819 -40.512054 -2.181006
v -157.808243 -40.512054 -5.278782
v -149.018158 -40.512054 -6.359990
v -192.248352 -44.020111 -0.590104
v -175.828827 -44.020111 -2.983502
v -198.787521 -52.080090 -1.227486
v -197.570847 -54.201244 -2.256252
v -193.118423 -55.143978 -2.709126
v -175.805588 -56.143414 -2.460002
v -157.745285 -52.759968 -1.295303
v -148.969376 -48.512630 -0.827696
v -198.786148 -51.191311 -2.304485
v -197.567612 -52.081844 -4.824486
v -193.114319 -52.477642 -5.940127
v -175.801941 -53.750546 -5.359620
v -157.743759 -51.695354 -2.537997
v -148.968674 -48.358227 -1.407619
v -198.786148 -49.925770 -2.314782
v -197.567566 -49.064030 -4.849041
v -193.114304 -48.681034 -5.971020
v -175.801895 -50.343334 -5.387342
v -157.743698 -50.179447 -2.549878
v -148.968674 -48.138371 -1.413163
v -198.787506 -49.024815 -1.252344
v -197.570755 -46.915585 -2.315533
v -193.118317 -44.568363 -2.783705
v -175.805511 -47.449108 -2.526933
v -157.745270 -48.462933 -1.323988
v -148.969315 -47.449108 -0.890806
v -80.094856 -16.366798 -20.192406
v -80.145653 -16.366798 19.944675
v -95.864258 -15.039927 6.206345
v -107.467216 -15.004230 6.197975
v -107.449020 -15.004153 -6.484835
v -95.844170 -15.039933 -6.482594
v -107.460655 -12.876587 6.197990
v -107.442490 -12.876509 -6.484818
v -95.837608 -12.912290 -6.482576
v -95.857697 -12.912283 6.206361
v -107.426102 -7.562058 -6.484778
v -95.821220 -7.597838 -6.482538
v -95.841347 -7.597833 6.206399
v -107.444267 -7.562137 6.198030
v -111.808311 -7.548680 6.191773
v -111.824669 -12.863129 6.191733
v -111.806503 -12.863051 -6.491072
v -111.790115 -7.548601 -6.491032
v 71.006943 -19.101204 -7.242425
v 70.988472 -19.101204 7.344247
v 34.080170 -18.608231 -7.226748
v 34.061840 -18.608231 7.249640
v -21.350143 -7.427763 -21.558270
v 26.882221 -7.747872 -21.679798
v 34.154896 -7.747593 -21.703022
v 34.136551 -7.747593 -7.226677
v 71.063339 -8.240566 -7.242352
v 71.081810 -8.240566 -21.828981
v 103.028801 -8.606395 -21.056404
v 102.975235 -8.606395 21.246561
v 71.026398 -8.240566 21.930946
v 71.044868 -8.240566 7.344320
v 34.118221 -7.747593 7.249712
v 34.099892 -7.747593 21.726053
v 26.827316 -7.747872 21.686625
v -21.404583 -7.427763 21.435682
v -23.850100 -6.966564 -20.859394
v -23.902718 -6.966564 20.706121
g hull
v -23.885199 -6.966564 6.850965
g
v -23.867649 -6.966564 -7.004236
v -23.533968 -2.682079 -20.858994
g hull
v -23.551517 -2.682079 -7.003835
v -23.569067 -2.682079 6.851367
g
v -23.586586 -2.682079 20.706522
v -74.120796 -6.574910 -20.294436
v -78.092445 -9.487654 -20.191195
v -77.228287 -6.505365 -17.084606
v -76.912163 -2.220882 -17.084206
v -73.804665 -2.290426 -20.294039
v -77.271225 -6.505365 16.840353
v -78.143242 -9.487654 19.945889
v -74.171867 -6.574910 20.058041
v -73.855736 -2.290426 20.058441
v -76.955093 -2.220882 16.840754
v -73.679039 5.593889 20.058668
v -76.778397 5.663433 16.840981
v -76.735466 5.663433 -17.083979
v -73.627968 5.593889 -20.293812
v -56.149837 5.202236 -20.878201
v -56.167385 5.202236 -7.023045
v -56.184937 5.202236 6.832156
v -56.202484 5.202236 20.687315
v -56.003712 5.197935 15.158989
v -23.387844 -2.686375 15.178197
v -73.656967 -2.294722 14.530116
v -73.480301 5.589588 14.530342
v -73.443222 5.589582 -14.765001
v -73.619888 -2.294727 -14.765227
v -23.349226 -2.686380 -15.330184
v -55.965096 5.197929 -15.349392
v -56.083004 8.968954 -7.022938
v -56.100555 8.968954 6.832263
v -56.118073 8.968954 20.687424
v -73.594658 9.360607 20.058777
v -76.694016 9.430149 16.841087
v -76.651085 9.430149 -17.083872
v -73.543587 9.360607 -20.293705
v -56.065456 8.968954 -20.878098
v -66.006950 9.264441 -5.180267
v -58.864384 9.104385 -5.312379
v -58.883072 9.104385 5.108154
v -66.025131 9.264441 4.962180
v -59.995365 18.266634 3.180750
v -64.496681 18.367502 3.088750
v -64.485199 18.367502 -3.303547
v -59.983597 18.266634 -3.386811
v -7.724119 -7.281446 8.517172
v -10.812283 -7.268494 11.267529
v -4.621579 -7.351016 11.657533
v -1.441457 15.301786 6.471271
v -3.377544 15.345182 4.909741
v -4.602257 -7.351017 -11.754386
v -10.793686 -7.268492 -11.383029
v -7.710023 -7.281446 -8.627288
v -3.362122 15.345030 -4.995567
v -1.426647 15.301691 -6.548023
v 11.589803 -7.713856 -8.758033
v 14.679115 -7.726812 -11.518564
v 8.487137 -7.644284 -11.843060
v 5.824824 15.139219 -6.555085
v 7.739266 15.096296 -5.033173
v 8.467769 -7.644286 11.802110
v 14.660228 -7.726815 11.496260
v 11.575425 -7.713856 8.730344
v 7.723810 15.096468 4.981758
v 5.810102 15.139311 6.494761
v 9.661969 15.053129 -0.018312
v -5.251101 15.387262 -0.050158
v 2.211564 15.220198 -7.492658
v 2.199291 15.220198 7.424184
v -8.148654 15.301786 -9.292356
v -4.536936 15.301786 -12.189340
v 2.252211 15.301786 -13.952092
v 8.994812 15.301786 -12.202518
v 12.567273 15.301786 -9.362534
v 16.155155 15.301786 -0.004471
v 12.538436 15.301786 9.325991
v 8.967335 15.301786 12.149354
v 2.229321 15.301786 13.883718
v -4.564579 15.301786 12.105520
v -8.177430 15.301786 9.191602
v -11.673625 15.301786 -0.063898
v -4.564579 25.331264 12.105520
v -8.177430 25.331264 9.191602
v -11.673625 25.331264 -0.063897
v -8.148654 25.331264 -9.292356
v -4.536936 25.331264 -12.189340
v 2.252211 25.331264 -13.952092
v 8.994812 25.331264 -12.202518
v 12.567273 25.331264 -9.362534
v 16.155155 25.331264 -0.004471
v 12.538436 25.331264 9.325991
v 8.967335 25.331264 12.149354
v 2.229321 25.331264 13.883718
v 11.696464 25.331264 4.060451
v 10.309690 25.331264 5.156854
v 7.380241 25.331264 5.910896
v 4.424797 25.331264 5.137356
v 3.015162 25.331264 4.000420
v 1.487361 25.331264 -0.044122
v 3.027532 25.331264 -4.076335
v 4.436466 25.331264 -5.206450
v 7.389619 25.331264 -5.973214
v 10.321282 25.331264 -5.212503
v 11.708874 25.331264 -4.109426
v 13.277449 25.331264 -0.018191
v 10.321282 27.999378 -5.212503
v 11.708874 27.999378 -4.109426
v 13.277449 27.999378 -0.018191
v 11.696464 27.999378 4.060451
v 10.309690 27.999378 5.156854
v 7.380241 27.999378 5.910896
v 4.424797 27.999378 5.137356
v 3.015162 27.999378 4.000420
v 1.487361 27.999378 -0.044122
v 3.027532 27.999378 -4.076335
v 4.436466 27.999378 -5.206450
v 7.389619 27.999378 -5.973214
v 7.370870 56.143414 -0.031196
v 7.376258 27.999371 -1.219594
v 7.962594 27.999371 -1.067451
v 6.785621 27.999371 -1.066240
v 6.503841 27.999371 -0.840218
v 6.195807 27.999371 -0.033775
v 6.501358 27.999371 0.775133
v 6.783297 27.999371 1.002521
v 7.374376 27.999371 1.157228
v 7.960266 27.999371 1.006421
v 8.237617 27.999371 0.787140
v 8.553820 27.999371 -0.028589
v 8.240097 27.999371 -0.846836
v 73.408287 -8.258724 -19.460375
v 100.696426 -8.588238 -18.765371
v 100.648666 -8.588238 18.950254
v 73.358879 -8.258724 19.567587
v 73.374352 -8.258724 7.347268
v 73.392822 -8.258724 -7.239404
v 73.375023 -6.187043 19.567604
v 73.390511 -6.187043 7.347289
v 73.408966 -6.187043 -7.239382
v 73.424431 -6.187043 -19.460354
v 100.712578 -6.516557 -18.765354
v 100.664818 -6.516557 18.950272
v 71.097954 -6.168886 -21.828964
v 103.044952 -6.534715 -21.056387
v 102.991386 -6.534715 21.246578
v 71.042557 -6.168886 21.930964
v 71.061028 -6.168886 7.344340
v 71.079483 -6.168886 -7.242332
v 71.109116 2.369425 21.931049
v 71.127586 2.369425 7.344425
v 71.146042 2.369425 -7.242248
v 71.164513 2.369425 -21.828878
v 103.111481 2.003595 -21.056303
v 103.057915 2.003595 21.246662
v 106.177406 1.943451 -21.049290
v 106.110878 -6.594859 -21.049376
v 106.057304 -6.594859 21.253593
v 106.123833 1.943451 21.253679
# 428 vertices
# 0 texture vertices
# 0 normals
g hull
f 212 206 33 27 21 15 9 3 224 218
f 7 1 2 8
f 2 3 9 8
f 4 5 11 10
f 5 6 12 11
f 6 7 13 12
f 7 8 14 13
f 8 9 15 14
f 10 11 17 16
f 11 12 18 17
f 12 13 19 18
f 13 14 20 19
f 14 15 21 20
f 16 17 23 22
f 17 18 24 23
f 18 19 25 24
f 19 20 26 25
f 20 21 27 26
f 22 23 29 28
f 23 24 30 29
f 24 25 31 30
f 25 26 32 31
f 26 27 33 32
f 223 229 4 10 16 22 28 211 217
f 48 194 193 192 51 50 49
f 7 6 34 35
f 226 1 7 35 204
f 118 117 116 115 114 121 120 119
f 5 4 54 53
f 53 34 6 5
f 52 55 36 37
f 34 52 37 38
f 39 204 35
f 37 36 41 42
f 38 37 42 43
f 39 38 43 40
f 39 35 34 38
f 43 42 44 45
f 40 43 45 46
f 42 41 47 44
f 44 47 48 49
f 45 44 49 50
f 46 45 50 51
f 52 34 53
f 53 54 55 52
f 4 229 187 56
f 54 4 56 57
f 55 54 57 58
f 36 55 58 59
f 41 36 59 60
f 47 41 60 61
f 48 47 61 62
f 194 48 62 181
f 63 56 187 180
f 57 56 63 64
f 58 57 64 65
f 59 58 65 66
f 60 59 66 67
f 61 60 67 68
f 231 62 61 68
f 67 66 84 70
f 68 67 70 71
f 231 68 71 72
f 73 63 180 170
f 64 63 73 74
f 65 64 74 75
f 66 65 75 84
f 74 73 76 77
f 75 78 86 87
f 87 84 75
f 70 84 89
f 71 70 80 81
f 123 122 72 71 81 82
f 83 76 73 170 167
f 69 89 84
f 85 80 88
f 78 85 86
f 86 85 79
f 69 87 86 79
f 79 88 89 69
f 70 89 88 80
f 88 79 85
f 78 75 74 77
f 87 69 84
f 76 83 104 91
f 77 76 91 92
f 78 77 92 93
f 85 78 93 94
f 80 85 94 95
f 81 80 95 96
f 82 81 96 90
f 95 94 97 98
f 96 95 98 99
f 90 96 99 100
f 154 90 100 144
f 101 91 104 140 153 143
f 92 91 101 102
f 93 92 102 103
f 94 93 103 97
f 83 105 104
f 105 140 104
f 102 101 106 107
f 103 102 107 108
f 97 103 108 109
f 98 97 109 110
f 99 98 110 111
f 99 113 100
f 132 144 100 113
f 106 101 143 139
f 133 132 113 112
f 113 99 111 112
f 116 117 106 139 130
f 107 106 117 118
f 108 107 118 119
f 109 108 119 120
f 110 109 120 121
f 114 112 111 110 121
f 131 133 112 114 115
f 135 134 133 131 126
f 136 135 126 127
f 137 136 127 128
f 138 137 128 129
f 139 138 129 130
f 145 132 133 134
f 144 132 145
f 146 145 134 135
f 147 146 135 136
f 141 147 136 137
f 142 141 137 138
f 143 142 138 139
f 140 105 83
f 151 150 147 141
f 152 151 141 142
f 153 152 142 143
f 148 154 144 145
f 149 148 145 146
f 150 149 146 147
f 162 161 154 148
f 163 162 148 149
f 159 163 149 150
f 165 159 150 151
f 166 165 151 152
f 167 166 152 153
f 83 167 153 140
f 160 174 157
f 168 165 166 169
f 159 164 156
f 155 173 163 156
f 156 164 174 155
f 157 174 164 158
f 164 159 158
f 158 159 165
f 156 163 159
f 160 155 174
f 161 162 172 171 125 124
f 173 172 162 163
f 155 160 173
f 168 160 157
f 165 168 157 158
f 170 169 166 167
f 178 177 160 168
f 179 178 168 169
f 180 179 169 170
f 172 175 230 171
f 176 175 172 173
f 177 176 173 160
f 182 181 230 175
f 183 182 175 176
f 184 183 176 177
f 185 184 177 178
f 186 185 178 179
f 187 186 179 180
f 195 194 181 182
f 200 195 182 183
f 203 200 183 184
f 188 203 184 185
f 189 188 185 186
f 229 189 186 187
f 189 190 191 188
f 190 205 191
f 196 46 51 192
f 197 196 192 193
f 195 197 193 194
f 200 199 197 195
f 198 40 46 196
f 199 198 196 197
f 204 39 201 205
f 201 39 40 198
f 202 201 198 199
f 203 202 199 200
f 191 205 201 202
f 188 191 202 203
f 205 190 228 227
f 229 228 190 189
f 116 130 129 128 127 126 131 115
f 227 226 204 205
f 206 207 32 33
f 207 208 31 32
f 208 209 30 31
f 209 210 29 30
f 210 211 28 29
f 212 213 207 206
f 213 214 208 207
f 214 215 209 208
f 215 216 210 209
f 216 217 211 210
f 218 219 213 212
f 219 220 214 213
f 220 221 215 214
f 221 222 216 215
f 222 223 217 216
f 224 225 219 218
f 225 226 220 219
f 226 227 221 220
f 227 228 222 221
f 228 229 223 222
f 3 2 225 224
f 1 226 225 2
g super
f 241 240 243 242
f 266 269 322 321 328 327 255 254 253 252
g hull
f 161 124 250 248
g super
f 422 421 420 419 424 423
g stack
f 313 312 315 314
g hull
f 232 233 62 231
f 233 234 181 62
f 234 235 230 181
f 235 232 231 230
g super
f 236 237 234 233
f 237 238 235 234
g hull
f 238 239 232 235
g super
f 239 236 233 232
f 240 241 238 237
f 241 242 239 238
f 242 243 236 239
f 245 244 247 246
f 244 245 236 243
f 245 246 237 236
f 246 247 240 237
f 247 244 243 240
g hull
f 123 82 249 251
g super
f 262 261 256 255
f 275 274 266 252 171 230
f 252 253 125 171
f 253 254 124 125
f 254 255 250 124
f 255 256 248 250
f 256 257 161 248
f 257 258 154 161
f 258 259 90 154
f 259 260 82 90
f 260 261 249 82
f 261 262 251 249
f 262 263 123 251
f 263 264 122 123
f 264 265 72 122
f 265 267 281 280 231 72
f 280 279 276 275 230 231
f 322 269 268 317 316 323
f 317 268 267 265 264 263 262 332 331 318
f 332 262 255 327 326 333
f 270 271 269 266
f 271 272 268 269
f 272 273 267 268
f 273 282 281 267
f 283 277 276 279
f 278 270 266 274
f 275 276 274
f 280 281 279
f 278 274 276 277
f 283 279 281 282
f 284 285 283 282
f 285 286 277 283
f 286 287 278 277
f 297 296 299 298
f 298 299 289 271
f 289 290 272 271
f 290 292 293 272
f 293 292 295 294
f 293 294 282 273
f 294 295 284 282
f 295 292 291 284
f 296 297 278 287
f 297 298 270 278
f 299 296 287 288
f 300 301 290 289
f 301 302 291 290
f 302 303 284 291
f 303 304 285 284
f 304 305 286 285
f 305 306 287 286
f 306 307 288 287
f 307 300 289 288
f 304 303 311 308 306 305
f 308 309 307 306
f 309 310 302 301 300 307
f 310 311 303 302
g stack
f 312 313 311 310
f 313 314 308 311
f 314 315 309 308
f 315 312 310 309
g radar
f 319 318 339
f 324 323 337
f 329 328 338
f 334 333 336
g super
f 317 318 316
f 322 323 321
f 327 328 326
f 332 333 331
g radar
f 320 316 318 319
f 325 321 323 324
f 330 326 328 329
f 335 331 333 334
f 330 336 326
f 321 338 328
f 326 336 333
f 325 338 321
f 331 339 318
f 335 339 331
f 320 337 316
f 316 337 323
f 340 341 325 324
f 341 342 338 325
f 342 343 329 338
f 343 344 330 329
f 344 345 336 330
f 345 346 334 336
f 346 347 335 334
f 347 348 339 335
f 348 349 319 339
f 349 350 320 319
f 350 351 337 320
f 351 340 324 337
f 352 353 350 349
f 353 354 351 350
f 354 355 340 351
f 355 356 341 340
f 356 357 342 341
f 357 358 343 342
f 358 359 344 343
f 359 360 345 344
f 360 361 346 345
f 361 362 347 346
f 362 363 348 347
f 363 352 349 348
f 364 365 362 361
f 365 366 363 362
f 366 367 352 363
f 367 368 353 352
f 368 369 354 353
f 369 370 355 354
f 370 371 356 355
f 371 372 357 356
f 372 373 358 357
f 373 374 359 358
f 374 375 360 359
f 375 364 361 360
f 376 377 374 373
f 377 378 375 374
f 378 379 364 375
f 379 380 365 364
f 380 381 366 365
f 381 382 367 366
f 382 383 368 367
f 383 384 369 368
f 384 385 370 369
f 385 386 371 370
f 386 387 372 371
f 387 376 373 372
g array
f 388 389 391
f 388 390 389
f 388 400 390
f 388 399 400
f 388 398 399
f 388 397 398
f 388 396 397
f 388 395 396
f 388 394 395
f 388 393 394
f 388 392 393
f 388 391 392
g radar
f 376 387 389 390
f 387 386 391 389
f 386 385 392 391
f 385 384 393 392
f 384 383 394 393
f 383 382 395 394
f 382 381 396 395
f 381 380 397 396
f 380 379 398 397
f 379 378 399 398
f 378 377 400 399
f 377 376 390 400
g super
f 401 402 258 257
f 402 403 259 258
f 403 404 260 259
f 404 405 261 260
f 405 406 256 261
f 406 401 257 256
f 407 408 405 404
f 408 409 406 405
f 409 410 401 406
f 410 411 402 401
f 411 412 403 402
f 412 407 404 403
f 413 414 411 410
f 414 415 412 411
f 415 416 407 412
f 416 417 408 407
f 417 418 409 408
f 418 413 410 409
f 419 420 417 416
f 420 421 418 417
f 421 422 413 418
f 422 423 414 413
f 426 425 428 427
f 424 419 416 415
f 425 426 414 423
f 426 427 415 414
f 427 428 424 415
f 428 425 423 424
l 295 292
l 295 294
l 297 278
l 297 296
l 299 289
l 299 296
g radar
l 365 364
l 366 365
l 367 366
l 368 367
l 369 368
l 370 369
l 371 370
l 372 371
l 373 372
l 374 373
l 375 364
l 375 374
# 438 elements