你的三葉玫瑰線程序我?guī)湍愀耐炅?,你看看吧?/p>
創(chuàng)新互聯(lián)長(zhǎng)期為千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為嘉興企業(yè)提供專業(yè)的網(wǎng)站制作、網(wǎng)站建設(shè),嘉興網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
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,"請(qǐng)選擇你喜歡的顏色",color);
if?(color==null)?color=Color.lightGray;
mjp.setForeground(color);
mjp.repaint();?
}
});
setSize(450,?550);//設(shè)置窗口大小
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置一個(gè)默認(rèn)的關(guān)閉操作,點(diǎn)擊按鈕時(shí),退出程序。
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)?{}
}
}
運(yùn)行結(jié)果:
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類型的數(shù)據(jù),分組一下0x|FF|0000FF,0x是代表顏色整 數(shù)的標(biāo)記,ff是表示透明度,0000FF表示顏色,注意:這里0xFF0000FF必須是8個(gè)的顏色表示,不接受0000FF這種6個(gè)的顏色表示。
setTextColor(Color.rgb(255, 255, 255));
setTextColor(Color.parseColor("#FFFFFF"));
//還有就是使用資源文件進(jìn)行設(shè)置
setTextColor(this.getResources().getColor(R.color.blue));
//通過獲得資源文件進(jìn)行設(shè)置。根據(jù)不同的情況R.color.blue也可以是R.string.blue或者
//另外還可以使用系統(tǒng)自帶的顏色類
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