|
わたべ学習塾 |
|
|
|
|
| 正葉曲線 |
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,n=4;
double a=150,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);
choice1.addItem("1");
choice1.addItem("2");
choice1.addItem("3");
choice1.addItem("4");
choice1.addItem("5");
choice1.addItem("6");
choice1.addItem("7");
choice1.addItem("8");
choice1.addItem("9");
choice1.addItem("10");
try {
choice1.select(3);
}
catch (IllegalArgumentException e) { }
add(choice1);
choice1.setBounds(528,156,85,25);
choice2.addItem("10");
choice2.addItem("20");
choice2.addItem("30");
choice2.addItem("40");
choice2.addItem("50");
choice2.addItem("100");
choice2.addItem("150");
choice2.addItem("200");
choice2.addItem("250");
choice2.addItem("300");
choice2.addItem("350");
choice2.addItem("400");
try {
choice2.select(1);
}
catch (IllegalArgumentException e) { }
add(choice2);
choice2.setBounds(528,204,85,25);
//}}
//{{REGISTER_LISTENERS
SymMouse aSymMouse = new SymMouse();
this.addMouseListener(aSymMouse);
SymItem lSymItem = new SymItem();
choice1.addItemListener(lSymItem);
choice2.addItemListener(lSymItem);
//}}
}
//{{DECLARE_CONTROLS
java.awt.Label label1 = new java.awt.Label();
java.awt.Choice choice1 = new java.awt.Choice();
java.awt.Choice choice2 = new java.awt.Choice();
//}}
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)
{
for (double angle=0;angle<361;angle=angle+0.5)
{
g.setColor(Color.blue);
r=a*Math.sin(n*(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*Math.sin(n*(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);
//g.setColor(Color.black);
//g.drawLine(10,200,600,200);
//g.drawLine(300,10,300,400);
}
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;
}
}
class SymItem implements java.awt.event.ItemListener
{
public void itemStateChanged(java.awt.event.ItemEvent event)
{
Object object = event.getSource();
if (object == choice1)
choice1_ItemStateChanged(event);
else if (object == choice2)
choice2_ItemStateChanged(event);
}
}
void choice1_ItemStateChanged(java.awt.event.ItemEvent event)
{
// to do: code goes here.
String st=choice1.getSelectedItem();
n=Integer.parseInt(st);
Graphics g=getGraphics();
g.clearRect(0,0,getSize().width,getSize().height);
}
void choice2_ItemStateChanged(java.awt.event.ItemEvent event)
{
// to do: code goes here.
String st=choice2.getSelectedItem();
a=Double.valueOf(st).byteValue();
Graphics g=getGraphics();
g.clearRect(0,0,getSize().width,getSize().height);
} }
|
|
|
|
|