import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class RoseJFrame extends JFrame implements ActionListener {
private RoseCanvas canvas;
public RoseJFrame() {
super("四叶玫瑰线");
Dimension dim = getToolkit().getScreenSize();
this.setBounds(dim.width/4, dim.height/4, dim.width/2, dim.height/2);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jpanel = new JPanel();
this.getContentPane().add(jpanel, "North");
JButton button_color = new JButton("选择颜色");
jpanel.add(button_color);
button_color.addActionListener(this);
this.canvas = new RoseCanvas(Color.red);
this.getContentPane().add(this.canvas, "Center");
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
Color c = JColorChooser.showDialog(this, "选择颜色", Color.blue);
this.canvas.setColor(c);
this.canvas.repaint();
}
public static void main(String args[])
{
new RoseJFrame();
}
class RoseCanvas extends Canvas {
private Color color;
public RoseCanvas(Color color) {
this.setColor(color);
}
public void setColor(Color color) {
this.color = color;
}
public void paint(Graphics g) {
int x0 = this.getWidth() / 2;
int y0 = this.getHeight() / 2;
g.setColor(this.color);
g.drawLine(x0, 0, x0, y0 * 2);
g.drawLine(0, y0, x0*2, y0);
for (int j = 40; j < 100; j += 20)
for (int i = 0; i < 1024; i++) {
double angle = i*Math.PI/512;
double radius = j*Math.sin(8*angle);
int x = (int)Math.round(radius * Math.cos(angle) * 2);
int y = (int)Math.round(radius * Math.sin(angle));
g.fillOval(x0 + x, y0 + y*2, 2, 2);
}
}
}
}
最近下载更多
Cold_sangs LV3
2022年6月6日
本宝宝 LV2
2021年6月22日
xyt15262528405 LV1
2020年6月26日
18206810704 LV4
2019年6月4日
garay_ LV1
2019年5月28日
张记松 LV2
2018年8月6日
WindMan LV2
2018年6月22日
sideroad LV2
2018年6月14日
GakkiMarryMe LV9
2018年5月12日
libinn LV1
2017年11月28日
最近浏览更多
gongke LV2
2022年10月12日
Cold_sangs LV3
2022年6月6日
546512316546 LV3
2022年5月30日
liys1234 LV9
2022年4月22日
kkk2020
2022年2月13日
暂无贡献等级
撒野请你吃狗粮 LV2
2021年7月1日
本宝宝 LV2
2021年6月22日
梦痕 LV1
2021年6月21日
z384795536 LV1
2021年5月10日
xiajingbaobao
2021年4月12日
暂无贡献等级

