|
わたべ学習塾 |
|
|
|
|
| Cardioid |
2001.2.16 |
|
|
|
|
|
|
|
/* A basic extension of the java.applet.Applet class */ import java.awt.*; import java.applet.*; public class Applet1 extends Applet implements Runnable { Thread th; int x,y,ang=0; double a=100,r; String col; double rad=(Math.PI)/180; boolean Flag=true; public void init() { // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller symantec.itools.lang.Context.setApplet(this); // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setSize(631,371); add(label1); label1.setBounds(528,108,67,25); //}} //{{REGISTER_LISTENERS SymMouse aSymMouse = new SymMouse(); this.addMouseListener(aSymMouse); //}} } //{{DECLARE_CONTROLS java.awt.Label label1 = new java.awt.Label(); //}} public void start() { if(th==null) { th=new Thread(this); th.start(); } } public void run() { while(true) { ang=ang+1; if (ang>361) { ang=0; } repaint(); try { th.sleep(50); } catch(InterruptedException e) { } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { //g.drawLine(10,200,600,200); //g.drawLine(300,10,300,400); for (int angle=0;angle<361;angle=angle+1) { g.setColor(Color.blue); r=a*(1+Math.cos(rad*angle)); x=(int)(r*Math.cos(rad*angle)); y=(int)(r*Math.sin(rad*angle)); g.drawLine(x+300, -y+200, x+300, -y+200); } label1.setText(""+ang); g.setColor(Color.white); r=a*(1+Math.cos(rad*ang)); x=(int)(r*Math.cos(rad*ang)); y=(int)(r*Math.sin(rad*ang)); g.drawLine(x+300, -y+200, x+300, -y+200); } public void stop() { if(th !=null) { th.stop(); th=null; } } class SymMouse extends java.awt.event.MouseAdapter { public void mouseClicked(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == Applet1.this) Applet1_MouseClicked(event); } } void Applet1_MouseClicked(java.awt.event.MouseEvent event) { // to do: code goes here. if (Flag==false) { th.resume(); Flag=true; } else if (Flag==true) { th.suspend(); Flag=false; } } }
|
|
|
|
|