import java.applet.Applet; import java.awt.*; import java.awt.image.*; public class StarterApplet extends Applet { final int SPACE = 0; final int FREQ = 1; int mode; Button loadbutton, transbutton, modeb; TextField newfile; Scratchpad scratch; Palette palette; Panel buttons, fileloader; FFT fft = new FFT(); public void init() { mode = 0; scratch = new Scratchpad(); String palettefilename = getParameter("palette"); palette = new Palette(scratch, getCodeBase() + palettefilename); buttons = new Panel(); fileloader = new Panel(); newfile = new TextField(getParameter("image")); loadbutton = new Button ("load!"); transbutton = new Button ("->Freq"); modeb = new Button ("pen"); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); this.setLayout(gridbag); this.setBackground(new Color(0x0f0f0f)); this.setForeground(Color.white); scratch.setBackground(Color.black); scratch.setForeground(Color.white); buttons.setLayout(gridbag); buttons.setBackground(Color.black); buttons.setForeground(Color.white); fileloader.setLayout(gridbag); fileloader.setBackground(Color.black); fileloader.setForeground(Color.white); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints (transbutton, c); gridbag.setConstraints (modeb, c); buttons.add(transbutton); buttons.add(modeb); c.gridheight = 1; c.gridwidth = 1; gridbag.setConstraints(buttons, c); c.insets = new Insets(0,0,0,2); // c.gridy = 1; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.BOTH; c.gridwidth = 1; gridbag.setConstraints (palette, c); c.insets = new Insets(0,0,0,2); c.gridx = GridBagConstraints.RELATIVE; c.weightx = 1; c.weighty = 1; c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; c.ipadx = 1; c.ipady = 1; gridbag.setConstraints (scratch, c); //c.gridy = 2; c.weighty = 0; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 2; gridbag.setConstraints(newfile, c); c.gridwidth = 1; c.weightx = 0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; gridbag.setConstraints (loadbutton, c); fileloader.add(newfile); fileloader.add(loadbutton); c.fill = GridBagConstraints.HORIZONTAL; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(fileloader, c); add(palette); add(scratch); add(buttons); add(fileloader); } public boolean action (Event evt, Object arg){ double[] FFTdata; if (evt.target == modeb) { if (scratch.paintmode == 1) { modeb.setLabel("pen"); scratch.paintmode = 0; } else { scratch.paintmode = 1; modeb.setLabel("type"); } } if (evt.target == transbutton) { int dim = scratch.offimage.getHeight(this); int[] pixelspace = new int[dim * dim]; if (mode == FREQ) { mode = SPACE; System.out.println("Converting to Spatial Representation"); pixelspace = fft.reverse2dFFT(redonly(Image2Pixels(scratch.offimage), dim)); transbutton.setLabel("->Freq"); } else { mode = FREQ; System.out.println("Need to buld frequency domain images."); pixelspace = fft.forward2dFFT(redonly(Image2Pixels(scratch.offimage), dim), dim, dim); transbutton.setLabel("->Space"); } System.out.println("Finished transform."); scratch.offgraphics.drawImage( createImage(new MemoryImageSource(dim, dim, pixelspace, 0, dim)), 0, 0, this); scratch.repaint(); } if (arg.equals("load!") || (evt.target instanceof TextField)) { System.out.println("Loading file: "+newfile.getText()); scratch.loadImage(getCodeBase(), newfile.getText()); fft = new FFT(); mode = SPACE; transbutton.setLabel("->Freq"); } return true; } public float[] redonly(int[] pixels, int w) { float[] sp = new float[w*w]; for (int i=0; i