TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|

- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class RoseJFrame extends JFrame implements
- ComponentListener,ItemListener
- {
- private JComboBox combobox_color;
- public RoseJFrame()
- {
- super("四叶玫瑰线");
- this.setSize(600,400);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLayout(new FlowLayout());
-
- Object data[]={Color.red,Color.green,Color.blue};
- combobox_color=new JComboBox(data);
- combobox_color.addItemListener(this);
- this.add(combobox_color);
-
- this.addComponentListener(this);
- this.setVisible(true);
- }
-
- public void paint(Graphics g)
- {
- int x0,y0;
- x0=this.getWidth()/2;
- y0=this.getHeight()/2;
- g.setColor((Color)combobox_color.getSelectedItem());
- g.drawLine(x0,0,x0,y0*2);
- g.drawLine(0,y0,x0*2,y0);
- int j=40;
- while(j<200)
- {
- for(int i=0;i<1023;i++)
- {
- double angle=i*Math.PI/512;
- double radius=j*Math.sin(2*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,1,1);
- }
- j+=20;
- }
- }
-
- public void itemStateChanged(ItemEvent e)
- {
- repaint();
- }
-
- public void componentResized(ComponentEvent e)
- {
- repaint();
- }
- public void componentMoved(ComponentEvent e){ }
- public void componentHidden(ComponentEvent e){ }
- public void componentShown(ComponentEvent e){ }
- public static void main(String arg[])
- {
- new RoseJFrame();
- }
- }
复制代码
源码下载:http://file.javaxxz.com/2014/11/10/235700156.zip |
|