import java.awt.*; import java.awt.event.*; import java.applet.*; abstract public class DisperseGUI extends PhysicsApplet{ int N2; double[] fi, ficos, fisin; FourierTransform FT; double[] fzero; double t; CurveDisplay Waveform; TitleBanner Legend; // mouse modes static final int NormalMode = 0; static final int DrawWaveMode = 1; // button codes static final int FinishDrawingCode = 1; static final int StartCode = 2; static final int StopCode = 3; static final int ResetCode = 4; static final int ResetAllCode = 40; static final int ScrollbarCode = 5; // scrollbar PhysicsScrollbar StepBar; BoldLabel StepLabel; double tstep; DisperseGUI(){ super("Wave Equation with Dispersion", 299, 100, 2, 40); N2 = (Nx+1)/2; fi = new double[Nx+1]; ficos = new double[N2+1]; fisin = new double[N2+1]; fzero = new double[Nx+1]; FT = new FourierTransform(Nx+1); for (int i = 0; i <= Nx ; i++){ fi[i] = 0.0; } for (int i = 0; i <= N2 ; i++){ ficos[i] = 0.0; fisin[i] = 0.0; } t = 0; } void resetArrays(){ for (int i = 0; i <= N2 ; i++){ FT.fcos[i] = ficos[i]; FT.fsin[i] = fisin[i]; } FT.InverseTransform(); t = 0; refreshPicture(); } void resetAll(){ for (int i = 0; i <= Nx ; i++){ fi[i] = 0.0; fzero[i] = 0.0; } for (int i = 0; i <= N2 ; i++){ ficos[i] = 0.0; fisin[i] = 0.0; } t = 0; refreshPicture(); } void buildPicture(){ inputWave(); for (int i = 0; i < Nx ; i++){ FT.f[i] = fi[i]; } FT.Transform(); for (int i = 0; i <= N2 ; i++){ ficos[i] = FT.fcos[i]; fisin[i] = FT.fsin[i]; } Waveform = new CurveDisplay(150, 75, FT.f, fzero, 1.5, 1.0, Color.blue, Color.black,DrawWaveMode); Picture.add(Waveform,"Center"); Legend = new TitleBanner(" ",16); Picture.add(Legend,"South"); } void refreshPicture(){ Waveform.refresh(); Legend.write(" "+t); } void buildControls(){ Controls.setLayout(new GridLayout(0,5, 10, 10)); ModeButton B1 = new ModeButton("Draw f", DrawWaveMode); Controls.add(B1); CommandButton B2 = new CommandButton("Finish drawing", FinishDrawingCode); Controls.add(B2); CommandButton B3 = new CommandButton("Solve", StartCode); Controls.add(B3); CommandButton B4 = new CommandButton("Stop", StopCode); Controls.add(B4); CommandButton B4a = new CommandButton(" Reset to t= 0 ", ResetCode); Controls.add(B4a); BoldLabel B5 = new BoldLabel(" Time Step: "); Controls.add(B5); StepBar = new PhysicsScrollbar(0.3, 0.1, 3.0,ScrollbarCode); Controls.add(StepBar); StepLabel = new BoldLabel(" 0.3"); Controls.add(StepLabel); tstep = 0.3; CommandButton B8 = new CommandButton("Reset All", ResetAllCode); Controls.add(B8); } void doAction(int Code){ switch(Code){ case FinishDrawingCode: FT.Transform(); for (int i = 0; i <= N2 ; i++){ ficos[i] = FT.fcos[i]; fisin[i] = FT.fsin[i]; } refreshPicture(); break; case StartCode: startThread(); break; case StopCode: stopThread(); break; case ResetCode: resetArrays(); break; case ResetAllCode: resetAll(); break; case ScrollbarCode: tstep = StepBar.getReading(); StepLabel.setText(" "+tstep); break; default: break; } } Color findColor(double A, int S){ return Color.black; } void writeFieldValue(double Val, int mode){} void writeVectorValue(double Vx, double Vy, int mode){} void setArrays(int i, int j, int mode){} abstract void inputWave(); }