import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class DrawDemo extends JPanel{ /*public void paintComponent(Graphics g) { super.paintComponent(g); //g = this.getGraphics(); g.setColor(Color.BLUE); g.drawString("HELLO", 100, 100); g.fill3DRect(50, 100, 100, 100, true); }*/ public void paintComponent(Graphics g) { double x0,y0,x1,y1,x2,y2,scale; x0 = 100;y0 = 80; scale = 30.0; g.setColor(Color.BLUE); for(x1=-3.1415926d;x1<=3.1415926d;x1+=0.01d) { y1 = Math.sin(x1)+Math.cos(x1); x2 = x0+x1*scale; y2 = y0+y1*scale; System.out.println(""+x2+"-"+y2); g.fillOval((int)x2,(int)y2,3,3); } } public static void main(String[] args) { JFrame f = new JFrame(); f.setSize(500,500); f.setTitle("Draw Demo"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.add(new DrawDemo()); f.setVisible(true); } }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)