Question

In: Computer Science

Need to read a PPM image using a 3D array and display it in a swing Jpanel.

Need to read a PPM image using a 3D array and display it in a swing Jpanel. 

Solutions

Expert Solution

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;

public class HangmanPanel extends JPanel {
    private JLabel imageLabel;
    private ImageIcon[] images;
    private JButton nextImage;
    private int imageNumber;


    public HangmanPanel() {

        nextImage = new JButton("Next Image");
        nextImage.setEnabled(true);
        nextImage.setToolTipText("Press for next image.");
        nextImage.addActionListener(new ButtonListener());

        images = new ImageIcon[8];
        // Populating the array
        {
            images[0] = new ImageIcon("hangman0.png");
            images[1] = new ImageIcon("hangman1.png");
            images[2] = new ImageIcon("hangman2.png");
            images[3] = new ImageIcon("hangman3.png");
            images[4] = new ImageIcon("hangman4.png");
            images[5] = new ImageIcon("hangman5.png");
            images[6] = new ImageIcon("hangman6.png");
            images[7] = new ImageIcon("hangman7.png");
        }

        setBackground(Color.white);

        add(nextImage);
        int count = 0;
        while (images.length > count)
        imageLabel = new JLabel (images[imageNumber]);
        count++;
        imageNumber++;
        add (imageLabel);
    }


    public void paint(Graphics page) {
        super.paint(page);


    }
    private class ButtonListener implements ActionListener{
        public void actionPerformed(ActionEvent event) {
            imageNumber++;
            }

        }
    }

Related Solutions

Design an algorithm that will read an array of 200 characters and display to the screen...
Design an algorithm that will read an array of 200 characters and display to the screen a count of the occurrences of each of the five vowels (a, e, i, o, u) in the array. Your string is: The quick brown fox jumped over the lazy dog That is the question for my pseudo code question, I don't know if I have this correct can i have someone look this over and finish this and explain what i needed to...
Explain the trade-offs, particularly for throughput (performance), involved in preparing an image, video, or 3D image...
Explain the trade-offs, particularly for throughput (performance), involved in preparing an image, video, or 3D image processing task for parallel processing ?
Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.
Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.Input:    6    2 3 4 11 22 320    where:First line represents the number of elements in the array.Second line represents the elements in the array.Output:    2 3 4 11 22Explanation: Element of the array 320 is the only one in the array which is a multiple of 5, so it is removed from the array.Assumptions:Array can be of size...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like...
Pandas exercises: 1. Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. 2. Write a python program using Pandas to convert a Panda module Series to Python list and print it's type. (Hint: use ds.tolist() to convert the pandas series ds to a list) 3. Create a pandas dataframe called **my_df** with index as integer numbers between 0 to 10, first column (titled "rnd_int") as 10 integer random numbers between...
In the MATLAB environment, display an image of a breast mammogram from the MAMMO database. Apply...
In the MATLAB environment, display an image of a breast mammogram from the MAMMO database. Apply gray-level scaling, histogram equalization, and an LOG enhancement mask for image enhancement as given below. Compare the enhanced images to original image qualitatively. LOG enhancement mask to be convolved with the image: - 1 -1 -1 - 1 9 - 1 -1 -1 -1 MAMMO database: http://peipa.essex.ac.uk/pix/mias/
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar,...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar, and a Menu bar FOR THE QUESTION BELOW: PLEASE HELP PROGRAMMING LANGUAGE IS PYTHON Write a simple quiz game that has a list of ten questions and a list of answers to those questions. The game should give the player four randomly selected questions to answer. It should ask the questions one-by-one, and tell the player whether they got the question right or wrong....
In phage display using a phagemid vector derived from M13 filamentous phage, you need to transfect...
In phage display using a phagemid vector derived from M13 filamentous phage, you need to transfect a helper phage to propagate the phagemid vector. Explain why ?
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and then find the index of the largest element in the array. You are to write two functions, printArray() and getIndexLargest(), which are called from the main function. printArray() outputs integers to std::cout with a space in between numbers and a newline at the end. getIndexLargest () returns the index of the largest element in the array. Recall that indexes start at 0. If there...
1. Read 20 integers into an array. Next, use the unique algorithm to reduce the array...
1. Read 20 integers into an array. Next, use the unique algorithm to reduce the array to the unique values entered by the user. Use the copy algorithm to display the unique values. 2. Modify the Exercise 1 above to use the unique_copy algorith. The unique values should be inserted into a vector that's initially empty. Use a back_inserter to enable the vector to grow as new items are added. Use the copy algorithm to display the unique values.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT