你的三叶玫瑰线程序我帮你改完了,你看看吧。
创新互联长期为千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为嘉兴企业提供专业的网站制作、网站建设,嘉兴网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
public class GraExp4 extends JFrame{
Container J;
JButton btn=new JButton("选择颜色");
Color color=new Color(200,200,200);
JPanel jp=new JPanel();
MyJPanel mjp=new MyJPanel();
public GraExp4()
{
super("三叶玫瑰线");
J=getContentPane();
jp.setBackground(Color.WHITE);
jp.add(btn);
J.add(jp,BorderLayout.NORTH);
J.add(mjp,BorderLayout.CENTER);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
color=JColorChooser.showDialog(null,"请选择你喜欢的颜色",color);
if (color==null) color=Color.lightGray;
mjp.setForeground(color);
mjp.repaint();
}
});
setSize(450, 550);//设置窗口大小
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置一个默认的关闭操作,点击按钮时,退出程序。
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args)
{
GraExp4 ge=new GraExp4();
}
class MyJPanel extends JPanel implements ComponentListener{
int roses=3;
MyJPanel(){
this.setBackground(Color.WHITE);
}
@Override
public void paint(Graphics g){
super.paint(g);
int x0, y0;
x0 = this.getWidth() / 2;
y0 = this.getHeight() / 2;
g.setColor(Color.RED);
g.drawLine(x0, 0, x0, y0 * 2);
g.drawLine(0, y0, x0 * 2, y0);
ListInteger listx=new ArrayListInteger();
ListInteger listy=new ArrayListInteger();
g.setColor(color);
for(int j=0;j200;j+=20)
for (int i = 0; i 1024; i++) {
double angle = i * Math.PI / 512;
double radius = j*Math.sin(roses * angle);
int x = (int) Math.round(radius * Math.cos(angle));
int y = (int) Math.round(radius * Math.sin(angle));
listx.add(x0+x);
listy.add(y0+y);
}
for (int i = 0; i listx.size()-1; i++) {
g.drawLine(listx.get(i),listy.get(i), listx.get(i+1), listy.get(i+1));
}
}
@Override
public void componentHidden(ComponentEvent arg0) {}
@Override
public void componentMoved(ComponentEvent arg0) {}
@Override
public void componentResized(ComponentEvent arg0) {
repaint();
}
@Override
public void componentShown(ComponentEvent arg0) {}
}
}
运行结果:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test4 {
public test4() {
final JFrame f = new JFrame();
f.setBounds(500, 200, 200, 200);
JButton jb = new JButton("颜色选择");
f.add(jb, BorderLayout.NORTH);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent cc) {
Color ch = JColorChooser.showDialog(f, "颜色选择器",
f.getBackground());
if (ch != null) {
f.getContentPane().setBackground(ch);
f.getContentPane().repaint();
}
}
});
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args) {
new test4();
}
}
setTextColor(0xFF0000FF);
//0xFF0000FF是int类型的数据,分组一下0x|FF|0000FF,0x是代表颜色整 数的标记,ff是表示透明度,0000FF表示颜色,注意:这里0xFF0000FF必须是8个的颜色表示,不接受0000FF这种6个的颜色表示。
setTextColor(Color.rgb(255, 255, 255));
setTextColor(Color.parseColor("#FFFFFF"));
//还有就是使用资源文件进行设置
setTextColor(this.getResources().getColor(R.color.blue));
//通过获得资源文件进行设置。根据不同的情况R.color.blue也可以是R.string.blue或者
//另外还可以使用系统自带的颜色类
setTextColor(android.graphics.Color.BLUE);
package swimg;
import java awt BorderLayout;
import java awt Color;
import java awt Container;
import javax swing BorderFactory;
import javax swing JColorChooser;
import javax swing JComponent;
import javax swing JFrame;
import javax swing JLabel;
import javax swing JPanel;
public class ColorChooserDemo extends JPanel{
protected JColorChooser tcc;
protected JLabel banner;
public ColorChooserDemo(){
super(new BorderLayout());
JPanel bannerPanel=new JPanel(new BorderLayout());
bannerPanel setBorder(BorderFactory createTitledBorder( chooser Text color ));
tcc=new JColorChooser(Color red);
add(bannerPanel BorderLayout CENTER);
add(tcc BorderLayout PAGE_END);
}
public static void main(String[] args) {
JFrame frame=new JFrame( 选择颜色 );
frame setBounds( );
frame setDefaultCloseOperation(JFrame EXIT_ON_CLOSE);
frame setVisible(true);
JComponent newContentPane=new ColorChooserDemo();
newContentPane setOpaque(true);
frame setContentPane(newContentPane);
frame pack();
}
}
lishixinzhi/Article/program/Java/hx/201311/26378