import java...

Linki


» Dzieci to nie książeczki do kolorowania. Nie da się wypełnić ich naszymi ulubionymi kolorami.
»
One of the most important secondary characters is Bart’s TV hero, Krusty the Clown (voiced by Castellaneta), who is featured in a number of episodes, beginning with...
»
574 Thinking in Java www...
»
To import text data from the command line or in an M-file, you must use one of the MATLAB import functions...
»
biblioteki depozytowe, księgozbiory oddane na przechowanie albo do użytkowania z zachowaniem prawa własności deponenta i na uzgodnionych warunkach...
»
Po jakichś pięciu minutach zapadałem zwykle w rodzaj półsnu, po czym roztaczałem przed sobą taką wizję: Oto w moim ciele wyraża się doskonałość Boga...
»
Jeżeli generator losowości umieścimy na poziomie najniższym, mię...
»
Porzucasz drogę, która obiecuje Pewne zwycięstwo, oddając się w ręce Niebezpiecznego ryzyka i tracąc Pewność działania...
»
wait SLIP 30if $errlvl != 0 goto prompt_error# Get and Set your IP address from the server...
»
Poskromicielka dzikich zwyczajów plemienia, Która czyni człowieka człowiekowi bratem I koczownicze namioty zamienia W nieruchome, spokojne chaty...
»
Równie dobrze źródłem smrodu mogła być starucha, odganiająca od kozich trupów muchy...

Dzieci to nie książeczki do kolorowania. Nie da się wypełnić ich naszymi ulubionymi kolorami.

awt.*;
import java.text.NumberFormat;

public class AnimationFrame
extends ApplicationFrame {
private Label mStatusLabel;
private NumberFormat mFormat;

public AnimationFrame(AnimationComponent ac) {
super("AnimationFrame v1.0");
setLayout(new BorderLayout());
add(ac, BorderLayout.CENTER);
add(mStatusLabel = new Label(), BorderLayout.SOUTH);
// Create a number formatter.
mFormat = NumberFormat.getInstance();
mFormat.setMaximumFractionDigits(1);
// Listen for the frame rate changes.
ac.setRateListener(this);
// Kick off the animation.
Thread t = new Thread(ac);
t.start();
}

public void rateChanged(double frameRate) {
mStatusLabel.setText(mFormat.format(frameRate) + " fps");
}
}


14.2.3 Animated Shapes
Let's take this animation framework out for a test drive. The following class, Bouncer, uses the framework to animate a curvy shape made from a series of cubic curves. Each of the endpoints and control points of the curves moves around the window, bouncing off the edges. The rendered shape is constantly changing as the endpoints and control points of its segments move around the window.
Figure 15.30 shows a snapshot of this example in action.
The options are as follows:
Anti
This checkbox controls whether antialiasing is used to render the shape.
Trans
When checked, this option causes the entire shape to rotate slowly.

page 258
Java 2D Graphics
Gradient
When this option is checked, the shape is filled with a color gradient. Otherwise, the shape is filled with a solid color.
Outline
This option controls whether the outline of the shape is stroked.
Dotted
If the Outline option is checked, this checkbox determines whether the outline is a solid or a dashed line.
Axes
If this checkbox is checked, coordinate axes will be drawn. The axes are useful in observing the effects of the Trans option.
Clip
When this option is checked, all rendering is clipped to a text shape.
Bouncer follows the conventions for an AnimationComponent subclass: it updates its state in timeStep() and renders itself in paint(). Notice, however, that a lot of the rendering depends on boolean member variables. Bouncer's main() method wires checkboxes to these boolean variables, so you can adjust what Bouncer renders and how it's rendered as it's running.
The curvy shape is stored as an array of floating point coordinates called mPoints. Each of these coordinates has a corresponding delta value, stored in mDeltas. For each new frame, timeStep() adds the deltas to the coordinates. If any coordinates are at the edges of the component, the delta value is negated so that the point appears to bounce off the edges of the component.
The paint() method, at its core, is very simple. It creates the curvy shape, using the createShape() method, then fills it. It uses a handful of helper methods to accomplish all the other neat features, like turning on antialiasing or using a gradient paint. Here's the code for Bouncer: import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.util.Random;

public class Bouncer
extends AnimationComponent {
public static void main(String[] args) {
final Bouncer bouncer = new Bouncer();
Frame f = new AnimationFrame(bouncer);
f.setFont(new Font("Serif", Font.PLAIN, 12));

Panel controls = new Panel();
controls.add(bouncer.createCheckbox("Anti.", Bouncer.ANTIALIASING));
controls.add(bouncer.createCheckbox("Trans.", Bouncer.TRANSFORM));
controls.add(bouncer.createCheckbox("Gradient", Bouncer.GRADIENT));
controls.add(bouncer.createCheckbox("Outline", Bouncer.OUTLINE));

page 259
Java 2D Graphics
controls.add(bouncer.createCheckbox("Dotted", Bouncer.DOTTED));
controls.add(bouncer.createCheckbox("Axes", Bouncer.AXES));
controls.add(bouncer.createCheckbox("Clip", Bouncer.CLIP));
f.add(controls, BorderLayout.NORTH);

f.setVisible(true);
}

// Tweakable variables
private boolean mAntialiasing, mGradient, mOutline;
private boolean mTransform, mDotted, mAxes, mClip;
// ...and the constants that represent them. See setSwitch().
public static final int ANTIALIASING = 0;
public static final int GRADIENT = 1;
public static final int OUTLINE = 2;
public static final int TRANSFORM = 3;
public static final int DOTTED = 4;
public static final int AXES = 5;
public static final int CLIP = 6;

private float[] mPoints;
private float[] mDeltas;
private float mTheta;
private int mN;

Powered by MyScript