Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you acomplish this assignment I need to add pictures to the assignment? A

ID: 3593109 • Letter: H

Question

How do you acomplish this assignment I need to add pictures to the assignment?

Assignment Face CSIS-1410 Learning Objectives: Paint images on a JPanel Dynamically update the images Continue your practice of event handling Use check boxes Practice composition Description: Create a gui application that provides the following functionality: . It has a control panel on the left side The control panel consists of a label, 3 check boxes that correspond to three features (eyes, nose, and mouth), " and a submit button Prevent the label, check-boxes, and button from touching the sides, the top or each other " The distance between the buttons should feel natural. They should not be spread out over the whole control panel " All the features, whose check boxes are selected, change when the submit button is clicked "The update of the eyes, nose, and mouth should not be random. Instead, they should rotate though all the available images (at least 3 images each) "If none of the check boxes is selected the face itself changes This can be as simple as changing the color of the face or it could involve more substantial changes (different hair, different ages, etc.) It has a face on the right side, that changes depending on the check box selection The updated eyes, nose, and mouth need to be displayed appropriately on the face Make sure that all the image files are part of the project and that they are accessed by using the resources of the class. (If you use absolute paths from your computer I won't be able to run it) Avoid methods that are unnecessarily long. Instead use private methods to structure your code and to improve maintainability. Hint: refactor early and often . . Look at Assignment Face.mp4 to see a running version of the finished assignment Your solution might look different because no images are provided. This is your opportunity to be creative and to have fun. Turning in: Make sure each of the source code files includes a block comment with your name and assignment number on top Create a runnable jar file that includes all the source code files and submit it via Canvas

Explanation / Answer

//Face.java

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.EventQueue;

import java.awt.Graphics;

import java.awt.GridLayout;

import java.awt.Image;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.SwingConstants;

import javax.swing.border.EmptyBorder;

public class Face extends JFrame {

private ArrayList<Image> faces = new ArrayList<Image>();

private ArrayList<Image> eyes = new ArrayList<Image>();

private ArrayList<Image> noses = new ArrayList<Image>();

private ArrayList<Image> mouths = new ArrayList<Image>();

private int numFace = 0;

private int numEye = 0;

private int numNose = 0;

private int numMouth = 0;

private JPanel contentPane;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

Face frame = new Face();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public Face() {

for (int i = 1; i < 4; i++) {

faces.add(new ImageIcon(getClass().getResource("images/face" + String.valueOf(i) + ".png")).getImage());

eyes.add(new ImageIcon(getClass().getResource("images/eyes" + String.valueOf(i) + ".png")).getImage());

noses.add(new ImageIcon(getClass().getResource("images/nose" + String.valueOf(i) + ".png")).getImage());

mouths.add(new ImageIcon(getClass().getResource("images/mouth" + String.valueOf(i) + ".png")).getImage());

}

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 570, 422);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

contentPane.setLayout(new BorderLayout(0, 0));

setContentPane(contentPane);

JPanel sidePanel = new JPanel();

contentPane.add(sidePanel, BorderLayout.WEST);

sidePanel.setLayout(new GridLayout(10, 1, 0, 0));

JLabel label1 = new JLabel("You Choose...");

sidePanel.add(label1);

label1.setHorizontalAlignment(SwingConstants.CENTER);

final JCheckBox eyeCheckBox = new JCheckBox("Eyes");

sidePanel.add(eyeCheckBox);

final JCheckBox noseCheckBox = new JCheckBox("Nose");

sidePanel.add(noseCheckBox);

final JCheckBox mouthCheckBox = new JCheckBox("Mouth");

sidePanel.add(mouthCheckBox);

JButton submitBtn = new JButton("Submit");

submitBtn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (eyeCheckBox.isSelected()) {

if (numEye != 2)

numEye++;

else {

numEye = 0;

}

}

if (noseCheckBox.isSelected()) {

if (numNose != 2) {

numNose++;

} else {

numNose = 0;

}

}

if (mouthCheckBox.isSelected()) {

if (numMouth != 2) {

numMouth++;

} else {

numMouth = 0;

}

}

if (!(mouthCheckBox.isSelected()) && !(noseCheckBox.isSelected()) && !(eyeCheckBox.isSelected())) {

if (numFace != 2) {

numFace++;

} else {

numFace = 0;

}

}

}

});

sidePanel.add(submitBtn);

JPanel mainPanel = new JPanel();

mainPanel.setBackground(Color.BLUE);

contentPane.add(mainPanel, BorderLayout.CENTER);

mainPanel.setLayout(new GridLayout(0, 1, 0, 0));

getContentPane().add(new FaceDraw(), BorderLayout.CENTER);

}

protected class FaceDraw extends JPanel {

@Override

public void paint(Graphics g) {

super.paint(g);

g.drawImage(faces.get(numFace), 50, 5, 400, 400, null);

g.drawImage(eyes.get(numEye), 165, 25, 170, 170, null);

g.drawImage(noses.get(numNose), 190, 150, 100, 100, null);

g.drawImage(mouths.get(numMouth), 150, 180, 200, 200, null);

repaint(); // updates continuously

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote