1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;
import java.awt.EventQueue;
import java.awt.geom.Point2D;
import javax.swing.JPanel;
import javax.swing.JFrame;
/**
* Created by IntelliJ IDEA.
* User: bebe
* Date: 16-mars-2007
*/
public class LinearGradientPainterTesting extends JPanel {
Point2D start = new Point2D.Float(0, 0);
float[] dist = {0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f};
Color[] colors = {Color.YELLOW, Color.ORANGE, Color.RED, Color.MAGENTA, Color.BLUE, Color.BLACK};
LinearGradientPaint paint = null;
protected void paintComponent(Graphics g) {
Graphics2D g2d;
if (g instanceof Graphics2D) {
g2d = (Graphics2D) g;
} else {
System.out.println("Error");
return;
}
paint = new LinearGradientPaint(start, new Point2D.Float(0, getHeight()), dist, colors);
g2d.setPaint(paint);
g2d.fillRect(0, 0, getWidth(), getHeight());
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame myFrame = new JFrame("Linear Gradient Painter");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.add(new LinearGradientPainterTesting());
myFrame.setSize(640, 480);
myFrame.setVisible(true);
}
});
}
} |
Partager