Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++

JAVA


PHP
SQL
Assignments

FindTheSpam


FindTheSpam.java

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;

public class FindTheSpam extends JApplet {
  boolean isStandalone = false;
  JButton thespam = new JButton();
  JPanel jPanel2 = new JPanel();
  BorderLayout borderLayout2 = new BorderLayout();
  JLabel jLabel2 = new JLabel();
  JRadioButton mooseButton = new JRadioButton();
  JRadioButton spamButton = new JRadioButton();
  ButtonGroup buttonGroup1 = new ButtonGroup();
  JButton spam2 = new JButton();
  Box box1;
  JLabel jLabel1 = new JLabel();
  JTextArea jTextArea1 = new JTextArea();

  public void init() {
      box1 = Box.createVerticalBox();
      this.setSize(new Dimension(350,400));
  
      String imageFileName = "spam.jpg";
      URL imageURL = getClass().getResource(imageFileName);
      Toolkit tk = Toolkit.getDefaultToolkit();
      Image img = null;
      try {
        img = tk.createImage((java.awt.image.ImageProducer) 
               imageURL.getContent());
      }
      catch (java.io.IOException ex) {
          System.out.println(ex);
      }
      thespam.setIcon(new ImageIcon(img));
      thespam.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          thespam_actionPerformed(e);
        }
      });
      spam2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(ActionEvent e) {
          spam2_actionPerformed(e);
        }
      });
  
      jPanel2.setLayout(borderLayout2);
      jLabel2.setText("Text Only version:  Which one is Spam?");
      mooseButton.setText("Moose");
      spamButton.setText("Spam");
      spam2.setText("Check my Answer");
      jLabel1.setText("Find the Spam");
      jTextArea1.setWrapStyleWord(true);
      jTextArea1.setEditable(false);
      jTextArea1.setText("Directions:Somewhere in the picture below is spam\n");
      jTextArea1.append("When you find it, click on it");
      this.getContentPane().add(thespam, BorderLayout.CENTER);
      this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
      jPanel2.add(jLabel2, BorderLayout.NORTH);
      jPanel2.add(spamButton, BorderLayout.CENTER);
      jPanel2.add(spam2, BorderLayout.EAST);
      jPanel2.add(mooseButton, BorderLayout.WEST);
      this.getContentPane().add(box1, BorderLayout.NORTH);
      box1.add(jLabel1);
      box1.add(jTextArea1, null);
      buttonGroup1.add(spamButton);
      buttonGroup1.add(mooseButton);
  }
  
  public String getAppletInfo() {
    return "I'm all about spam";
  }
  void thespam_actionPerformed(ActionEvent e) {
      jTextArea1.setText("You are Correct!\n"
                 +"Try again, or try the text version");
  }
  void spam2_actionPerformed(ActionEvent e) {
        if(spamButton.isSelected())
            jTextArea1.setText("You are Correct!\n"
                 +"Try again, or try the graphical version");
        else
            jTextArea1.setText("You are Very Wrong!!!!\n"
                 +"Try again, or try the graphical version");
  }
}