PictureExplorer.java - import java.awt import...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.image.*; import javax.swing.border.*; /** * Displays a picture and lets you explore the picture by displaying the row, column, red, * green, and blue values of the pixel at the cursor when you click a mouse button or * press and hold a mouse button while moving the cursor. It also lets you zoom in or * out. You can also type in a row and column value to see the color at that location. * * Originally created for the Jython Environment for Students (JES). * Modified to work with DrJava by Barbara Ericson * Also modified to show row and columns by Barbara Ericson * * @author Keith McDermottt, [email protected] * @author Barb Ericson [email protected] */ public class PictureExplorer implements MouseMotionListener, ActionListener, MouseListener { // current indicies /** row index */ private int rowIndex = 0; /** column index */ private int colIndex = 0; // main GUI /** window to hold GUI */ private JFrame pictureFrame; /** window that allows the user to scroll to see a large picture */ private JScrollPane scrollPane; // GUI components /** column label */ private JLabel colLabel; /** column previous button */ private JButton colPrevButton; /** row previous button */ private JButton rowPrevButton; /** column next button */ private JButton colNextButton; /** row next button */ private JButton rowNextButton; /** row label */ private JLabel rowLabel; /** text field to show column index */ private JTextField colValue; /** text field to show row index */ private JTextField rowValue; /** red value label */ private JLabel rValue; /** green value label */ private JLabel gValue; /** blue value label */ private JLabel bValue; /** color swatch label */ private JLabel colorLabel;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
/** panel to show the color swatch */ private JPanel colorPanel; // menu components /** menu bar */ private JMenuBar menuBar; /** zoom menu */ private JMenu zoomMenu; /** 25% zoom level */ private JMenuItem twentyFive; /** 50% zoom level */ private JMenuItem fifty; /** 75% zoom level */ private JMenuItem seventyFive; /** 100% zoom level */ private JMenuItem hundred; /** 150% zoom level */ private JMenuItem hundredFifty; /** 200% zoom level */ private JMenuItem twoHundred; /** 500% zoom level */ private JMenuItem fiveHundred; /** The picture being explored */ private DigitalPicture picture; /** The image icon used to display the picture */ private ImageIcon scrollImageIcon; /** The image display */ private ImageDisplay imageDisplay; /** the zoom factor (amount to zoom) */ private double zoomFactor; /** the number system to use, 0 means starting at 0, 1 means starting at 1 */ private int numberBase=0; /** * Public constructor * @param picture the picture to explore */ public PictureExplorer(DigitalPicture picture) { // set the fields this.picture=picture; zoomFactor=1; // create the window and set things up createWindow(); } /** * Changes the number system to start at one */ public void changeToBaseOne() { numberBase=1; } /** * Set the title of the frame *@param title the title to use in the JFrame */
Image of page 2
public void setTitle(String title) { pictureFrame.setTitle(title); } /** * Method to create and initialize the picture frame */ private void createAndInitPictureFrame() { pictureFrame = new JFrame(); // create the JFrame pictureFrame.setResizable(true); // allow the user to resize it pictureFrame.getContentPane().setLayout(new BorderLayout()); // use border
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern