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 ?
Using pandas Read in the movies.csv into a dataframe named movies, display the first 5 rows...
Using pandas Read in the movies.csv into a dataframe named movies, display the first 5 rows and answer * Use the filter method to select the column names that contain the exact string facebook [ ] * Use the count method to find the number of non-missing values for each column. [ ] * Display the count of missing values for each column
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 C, write a program that initializes a 3D array (the exact size doesn't matter) that...
In C, write a program that initializes a 3D array (the exact size doesn't matter) that contain what ever arbitrary integers and print out the array including the elements and use different functions so that the main only contains variables and function calls.
The goal is to Create an array of struct “employee” Fill the array with information read...
The goal is to Create an array of struct “employee” Fill the array with information read from standard input using C++ style I/O Shuffle the array Select 5 employees from the shuffled array Sort the shuffled array of employees by the alphabetical order of their last Name Print this array using C++ style I/O Random Number Seeding We will make use of the random_shuffle() function from the standard algorithm library. You can use srand() function provided in with a seed...
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/
[7] How many MB of video memory is required to display an image with a resolution...
[7] How many MB of video memory is required to display an image with a resolution of 1,920 x 1,080 pixels and 65,536 colors (2^16colors)? However, 1 [MB] = 1,000 [kB] and 1 [kB] = 1,000 (B). [8] What is the amount of video memory required to display an image with a resolution of 1,600 x 1,200 pixels and 65,536 colors (2^16 colors)? However, 1 [MB]= 1,000 [kB], 1 (kB] = 1,000 (B). [9] Minimum required for video distribution at...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT