Di bawah ini yaitu referensi jadwal untuk menciptakan gradient color pada java. mungkin banyak kawan-kawan yang belum dapat menciptakan jadwal ini kali ini aku akan posting code jadwal java yang sangat sederhana ini.
import javax.swing.*;
import java.awt.*;
public class GradientColor{
public static void main(String[] args) {
GradientColor gd = new GradientColor();
}
public GradientColor(){
JFrame frame = new JFrame("Drawing with a Gradient Color");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MyComponent());
frame.setSize(400,400);
frame.setVisible(true);
}
public class MyComponent extends JComponent {
public void paint (Graphics g) {
super.paint (g);
Graphics2D g2;
g2 = (Graphics2D) g;
GradientPaint Acyclic;
GradientPaint Cyclic;
Cyclic = new GradientPaint (160F, 20F, Color.red,
260F, 90F, Color.green, true);
Acyclic = new GradientPaint (160F, 120F, Color.red,
260F, 190F, Color.green);
g2.setPaint (Cyclic);
g2.fillRect (10, 10, 400, 100);
g2.setPaint (Acyclic);
g2.fillRect (10, 120, 400, 100);
g2.setColor (Color.black);
g2.drawString ("Cyclic", 420, 70);
g2.drawString ("Acyclic", 420, 180);
}
}
}
import javax.swing.*;
import java.awt.*;
public class GradientColor{
public static void main(String[] args) {
GradientColor gd = new GradientColor();
}
public GradientColor(){
JFrame frame = new JFrame("Drawing with a Gradient Color");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MyComponent());
frame.setSize(400,400);
frame.setVisible(true);
}
public class MyComponent extends JComponent {
public void paint (Graphics g) {
super.paint (g);
Graphics2D g2;
g2 = (Graphics2D) g;
GradientPaint Acyclic;
GradientPaint Cyclic;
Cyclic = new GradientPaint (160F, 20F, Color.red,
260F, 90F, Color.green, true);
Acyclic = new GradientPaint (160F, 120F, Color.red,
260F, 190F, Color.green);
g2.setPaint (Cyclic);
g2.fillRect (10, 10, 400, 100);
g2.setPaint (Acyclic);
g2.fillRect (10, 120, 400, 100);
g2.setColor (Color.black);
g2.drawString ("Cyclic", 420, 70);
g2.drawString ("Acyclic", 420, 180);
}
}
}