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
| public class ExempleGradient2 {
public static Color[] COLORS = {Color.YELLOW,Color.MAGENTA,Color.CYAN};
public static float[] FRACTIONS = {0,.5f,1f};
public static void main(String[] args) {
JFrame frame = new JFrame("Démo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel() {
protected void paintComponent(java.awt.Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int width = getWidth();
int height = getHeight();
g2d.setPaint(new LinearGradientPaint(new Point(0,0), new Point(width,0), FRACTIONS, COLORS));
g.fillRect(0, 0, width, height);
}
};
frame.add(panel);
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
} |
Partager