/*FDTD1_1.java*/
/*<APPLET CODE="FDTD1_1.class" WIDTH="1024" HEIGHT="700">
</APPLET>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
public class FDTD1_1 extends Applet implements Runnable,ActionListener
{
Thread thread=null;
Graphics g;
private Graphics display;
private Image image;
Button n11=new Button("Start");
Button n12=new Button("Stop");
int W=500;
int H=500;
int n,k,kc;
int T,MAX=501;
double ex[]=new double[MAX];
double hy[]=new double[MAX];
double pulse,spread;
double t0;
int NSTEPS=1;
int mode=0;
double PI=3.14159;
public void init()
{
Canvas can=new Canvas();
can.setBounds(10,10,W+1,H+1);
add(can);
setLayout(null);
g=can.getGraphics();
can.setBackground(Color.white);
image=createImage(W+1,H+1);
display=image.getGraphics();
display.setColor(Color.white);
display.fillRect(0,0,W+1,H+1);
display.setColor(Color.black);
n11.setBounds(W,H/2+10,100,30);
n11.setBackground(Color.yellow);
n12.setBounds(W,H/2+50,100,30);
n12.setBackground(Color.yellow);
this.add(n11);
this.add(n12);
n11.addActionListener(this);
n12.addActionListener(this);
initialstate(ex,hy);
thread=null;
mode=0;
/*Initialize*/
kc=MAX/2; /*Center of the prolem space*/
t0=40.0; /*Center of the incident pulse*/
spread=12; /*Width of the incident pule*/
T=0;
NSTEPS=1;
n=0;
}
public void actionPerformed(ActionEvent e)
{
Object o=e.getSource();
if(o==n11)
{
mode=0;
thread.start();
}
else
{
thread.stop();
//thread=new Thread();
//thread.start();
mode=1;
}
}
public void run()
{
while(thread!=null)
{
try
{
Thread.sleep(1);
}catch(InterruptedException exc)
{
}
fdtd1_1(ex,hy);
drawWave(ex,100,100);
drawWave(hy,300,100);
}
}
public void initialstate(double Ex[],double Hy[])
{
for(k=0;k<MAX;k++)
{
Ex[k]=0.;
Hy[k]=0.;
}
}
/****************************************************************************/
public void fdtd1_1(double Ex[],double Hy[])
{
for(n=1;n<=NSTEPS;n++)
{
T=T+1; // T keeps track of the total number of times the main loop is excuted
/*Main FDTD loop*/
/*Caculate the Ex field*/
for(k=1;k<MAX;k++)
{
Ex[k]=Ex[k]+.5*(Hy[k-1]-Hy[k]);
}
/*Put a Gaussian pulse in the middle*/
pulse=Math.exp(-.5*Math.pow((t0-T)/spread,2.0));
Ex[kc]=pulse;
for(k=0;k<MAX-1;k++)
{
Hy[k]=Hy[k]+ .5*(Ex[k]-Ex[k+1]);
}
/*End of FDTD loop*/
}
}
/****************************************************************************/
public void drawWave(double a[],int x,int Amplitude)
{
display.setColor(Color.white);
display.fillRect(0,0,W+1,H+1);
display.setColor(Color.black);
for(k=1;k<MAX;k++)
{
display.drawLine(k-1,x-(int)(Amplitude*a[k-1]),k,x-(int)(Amplitude*a[k]));
}
g.drawImage(image,0,0,this);
}
public void start()
{
if(thread==null)
{
thread=new Thread(this);
//thread.start();
}
}
/****************************************************************************/
public void stop()
{
thread=null;
}
}
/*<APPLET CODE="FDTD1_1.class" WIDTH="1024" HEIGHT="700">
</APPLET>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
public class FDTD1_1 extends Applet implements Runnable,ActionListener
{
Thread thread=null;
Graphics g;
private Graphics display;
private Image image;
Button n11=new Button("Start");
Button n12=new Button("Stop");
int W=500;
int H=500;
int n,k,kc;
int T,MAX=501;
double ex[]=new double[MAX];
double hy[]=new double[MAX];
double pulse,spread;
double t0;
int NSTEPS=1;
int mode=0;
double PI=3.14159;
public void init()
{
Canvas can=new Canvas();
can.setBounds(10,10,W+1,H+1);
add(can);
setLayout(null);
g=can.getGraphics();
can.setBackground(Color.white);
image=createImage(W+1,H+1);
display=image.getGraphics();
display.setColor(Color.white);
display.fillRect(0,0,W+1,H+1);
display.setColor(Color.black);
n11.setBounds(W,H/2+10,100,30);
n11.setBackground(Color.yellow);
n12.setBounds(W,H/2+50,100,30);
n12.setBackground(Color.yellow);
this.add(n11);
this.add(n12);
n11.addActionListener(this);
n12.addActionListener(this);
initialstate(ex,hy);
thread=null;
mode=0;
/*Initialize*/
kc=MAX/2; /*Center of the prolem space*/
t0=40.0; /*Center of the incident pulse*/
spread=12; /*Width of the incident pule*/
T=0;
NSTEPS=1;
n=0;
}
public void actionPerformed(ActionEvent e)
{
Object o=e.getSource();
if(o==n11)
{
mode=0;
thread.start();
}
else
{
thread.stop();
//thread=new Thread();
//thread.start();
mode=1;
}
}
public void run()
{
while(thread!=null)
{
try
{
Thread.sleep(1);
}catch(InterruptedException exc)
{
}
fdtd1_1(ex,hy);
drawWave(ex,100,100);
drawWave(hy,300,100);
}
}
public void initialstate(double Ex[],double Hy[])
{
for(k=0;k<MAX;k++)
{
Ex[k]=0.;
Hy[k]=0.;
}
}
/****************************************************************************/
public void fdtd1_1(double Ex[],double Hy[])
{
for(n=1;n<=NSTEPS;n++)
{
T=T+1; // T keeps track of the total number of times the main loop is excuted
/*Main FDTD loop*/
/*Caculate the Ex field*/
for(k=1;k<MAX;k++)
{
Ex[k]=Ex[k]+.5*(Hy[k-1]-Hy[k]);
}
/*Put a Gaussian pulse in the middle*/
pulse=Math.exp(-.5*Math.pow((t0-T)/spread,2.0));
Ex[kc]=pulse;
for(k=0;k<MAX-1;k++)
{
Hy[k]=Hy[k]+ .5*(Ex[k]-Ex[k+1]);
}
/*End of FDTD loop*/
}
}
/****************************************************************************/
public void drawWave(double a[],int x,int Amplitude)
{
display.setColor(Color.white);
display.fillRect(0,0,W+1,H+1);
display.setColor(Color.black);
for(k=1;k<MAX;k++)
{
display.drawLine(k-1,x-(int)(Amplitude*a[k-1]),k,x-(int)(Amplitude*a[k]));
}
g.drawImage(image,0,0,this);
}
public void start()
{
if(thread==null)
{
thread=new Thread(this);
//thread.start();
}
}
/****************************************************************************/
public void stop()
{
thread=null;
}
}