?? heart.java.bak
字號(hào):
import java.awt.*;
import java.awt.event.*;
public class Heart extends Frame
implements WindowListener,ComponentListener,ItemListener
{
int width1=600,height1=400; //窗口尺寸
Color color = Color.blue; //畫線的顏色
CheckboxGroup cg1 ;
Checkbox cb1,cb2,cb3;
public Heart()
{
setTitle("Rose");
setSize(width1,height1);
setBackground(Color.white);
setLayout(new FlowLayout());
addWindowListener(this);
addComponentListener(this);
cg1 = new CheckboxGroup();
cb1 = new Checkbox("blue",cg1,true);
cb2 = new Checkbox("red",cg1,false);
cb3 = new Checkbox("green",cg1,false);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
add(cb1);
add(cb2);
add(cb3);
}
public void paint(Graphics g)
{
int x0,y0; //原點(diǎn)坐標(biāo)
x0 = width1 /2;
y0 = height1 /2;
g.setColor(color);
g.drawLine(x0,0,x0,height1);
g.drawLine(0,y0,width1,y0);
int i,j=40,x,y;
double pi=3.14,angle,r;
while (j<200)
{
for (i=0;i<1023;i++)
{
angle = i*pi/512;
r = j*(1-Math.cos(angle));
x =(int) Math.round(r*Math.cos(angle)*2);
y =(int) Math.round(r*Math.sin(angle));
g.fillOval(x0+x,y0+y,1,1); //畫圓點(diǎn)
}
j = j + 20;
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void componentResized(ComponentEvent e) //改變窗口大小時(shí)
{
width1 = getWidth(); //取得窗口的大小
height1 = getHeight();
}
public void itemStateChanged(ItemEvent e)
{ //選中單選按鈕時(shí)
if (e.getSource()==cb1) //判斷產(chǎn)生事件對(duì)象e的組件是誰(shuí)
color = Color.blue;
if (cb2.getState()) //判斷單選按鈕cb2的狀態(tài)
color = Color.red;
if (cg1.getSelectedCheckbox()==cb3) //判斷復(fù)選框組cg1選中的是誰(shuí)
color = Color.green;
repaint(); //重畫
}
public static void main(String arg[])
{ //創(chuàng)建并顯示Frame對(duì)象,F(xiàn)rame作為畫布
new Heart().setVisible(true);
}
public void componentMoved(ComponentEvent e) { }
public void componentHidden(ComponentEvent e) { }
public void componentShown(ComponentEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -