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 ?
Write a program in Java Swing that can Display all the name list then will generate...
Write a program in Java Swing that can Display all the name list then will generate and display the longest name out of a list of names. Thank you...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Python Describe the procedure for setting up the display of an image in a window.
Python Describe the procedure for setting up the display of an image in a window.
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
Write a java script function that accepts integer array as input, and display a new array...
Write a java script function that accepts integer array as input, and display a new array by performing fol lowing modifications, • The values in odd index positions must be incremented by 1 • The values in even index positions must be decremented by 1. • Assume the array index starts from 0. Input 1: arr = [1,2,3,4] Output 1: arr = [0,3,2,5 it done html and javascript and plz do it in simple way
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...
Using any existing 2D or 3D graphics library ( such as Java 2D, Java 3D or...
Using any existing 2D or 3D graphics library ( such as Java 2D, Java 3D or OpenGL ) draw a scene featuring various elements. You are to choose from one of the following categories: Any man-made landscape ( using Java 2D, or Java 3D, or OpenGL) Promoting a cause (Using Java 3D or OpenGL ) 3. Any visual landscape element of your choice (Using OpenGL with Java or Python ) You are free to create whatever you choose but it...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT