import javax.swing.*; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import java.awt.image.*; public class PaintTest extends JPanel { BasicStroke bs; Line2D line1, line2; GradientPaint gp; TexturePaint tp; public static void main(String[] args) { JFrame f = new JFrame("PaintTest"); f.setContentPane(new PaintTest()); f.setSize(300, 300); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public PaintTest() { bs = new BasicStroke(20, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); line1 = new Line2D.Double(10, 10, 180, 180); line2 = new Line2D.Double(110, 40, 20, 250); gp = new GradientPaint( 20, 20, Color.blue, 170, 170, Color.red); //Create a texture paint that uses a blue image with red dots. //The size of the image is 10x10 pixels. BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); Graphics2D big = (Graphics2D)bi.getGraphics(); big.setColor(Color.blue); big.fillRect(0, 0, 10, 10); big.setColor(Color.red); big.fillOval(0, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 10, 10); tp = new TexturePaint(bi, r); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setStroke(bs); g2.setPaint(tp); g2.draw(line2); g2.setPaint(gp); g2.draw(line1); } }