import java.awt.*;
import java.awt.geom.GeneralPath;
import javax.swing.*;
public class CurvingPath extends JPanel {
GeneralPath path;
public CurvingPath() {
initPath();
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.blue);
g2.draw(path);
}
private void initPath() {
int[] coords = {
150, 150, 230, 75, 200, 275, 350, 350
};
path = new GeneralPath();
path.moveTo(coords[2], coords[3]);
path.lineTo(coords[0], coords[1]);
path.curveTo(80.4f, 215.2f, 80.4f, 215.2f,
coords[4], coords[5]);
path.lineTo(coords[6], coords[7]);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new CurvingPath());
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}