Question

I need help with my java code i am having a hard time compiling it //...

I need help with my java code i am having a hard time compiling it

// Cristian Benitez

import java.awt.Color;

import java.awt.Graphics;

import java.util.ArrayList;

import javax.swing.JPanel;

Face class

public class FaceDraw{

int width;

int height;

int x;

int y;

String smileStatus; //default constructor

public FaceDraw(){

}

// Getters and Setters for width,height,x,y

public int getWidth(){

return width;

}

public void setWidth(int width){

this.width=width;

}

public int getHeight(){

return height;

}

public void setHeight(int height){

this.height=height;

}

public int getX(){

return x;

}

public void setX(int x){

this.x=x;

}

public int getY(){

return y;

}

public void setY(int y){

this.y=y;

}

public String getSmileStatus(){

return smileStatus;

}

public void setSmileStatus(String smileStatus){

this.smileStatus=smileStatus;

}

// to my string method

public String toString(){

return super.toString();

}

}

FacePanel class

public class FacePanel extends JPanel{

private static final long serialVersionUID = 1L;

ArrayList<Face>faces;

public FacePanel (ArrayList<Face>faces){

this.faces=faces;

}

@Override

protected void paintComponent(Graphics graph) {

//Super paint component

graph.setColor(Color.BLUE);

// For each Dimension in the Arraylist

for(int i=0;i<faces.size();i++)

{

String smileStatus=faces.get(i).getSmileStatus();

if(smileStatus!=null)

{

if(smileStatus=="Smile")

graph.drawArc(faces.get(i).getX(), faces.get(i).getY(), faces.get(i).getWidth(), faces.get(i).getHeight(), 0, -180);

else

graph.drawArc(faces.get(i).getX(), faces.get(i).getY(), faces.get(i).getWidth(), faces.get(i).getHeight(), 0, 180);

System.out.println(smileStatus);

}

}

}

FaceFrame class

public class FaceFrame extends JFrame{

private static final long serialVersionUID = 1L;

public static ArrayList<Face> facelist = new ArrayList<Face>();

public FaceFrame(String title) {

new JFrame(title);

setBackground(Color.WHITE);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

setSize(1500, 700);

add(new FacePanel(facelist));

}

public static void addToList(Face face)

{

facelist.add(face);

}

private static void main(String args[])

{

//First Face

Face face1 = new Face();

//Lip dimensions

face1.setX(180);

face1.setY(350);

face1.setWidth(150);

face1.setHeight(20);

face1.setSmileStatus("Smile");

// face dimensions

Face face2 = new Face();

face2.setX(100);

face2.setY(100);

face2.setWidth(300);

face2.setHeight(400);

//Left Eye

Face face3 = new Face();

face3.setX(195);

face3.setY(210);

face3.setWidth(20);

face3.setHeight(20);

//Right eye

Face face4 = new Face();

face4.setX(295);

face4.setY(210);

face4.setWidth(20);

face4.setHeight(20);

//Second Face

Face face5 = new Face();

//Lip dimensions

face5.setX(580);

face5.setY(350);

face5.setWidth(150);

face5.setHeight(40);

face5.setSmileStatus("Frown");

// face dimensions

Face face6 = new Face();

face6.setX(500);

face6.setY(100);

face6.setWidth(300);

face6.setHeight(400);

//Left Eye

Face face7 = new Face();

face7.setX(595);

face7.setY(210);

face7.setWidth(20);

face7.setHeight(20);


//Right eye

Face face8 = new Face();

face8.setX(695);

face8.setY(210);

face8.setWidth(20);

face8.setHeight(20);

//Third Face

Face face9 = new Face();

//Lip dimensions

face9.setX(980);

face9.setY(350);

face9.setWidth(150);

face9.setHeight(0);

face9.setSmileStatus("Neutral");

// face dimensions

Face face10 = new Face();

face10.setX(900);

face10.setY(100);

face10.setWidth(300);

face10.setHeight(400);


//Left Eye

Face face11 = new Face();

face11.setX(995);

face11.setY(210);

face11.setWidth(20);

face11.setHeight(20);


//Right eye

Face face12 = new Face();

face12.setX(1095);

face12.setY(210);

face12.setWidth(20);

face12.setHeight(20);

//Adding all the face objects to list

addToList(face1);

addToList(face2);

addToList(face3);

addToList(face4);

addToList(face5);

addToList(face6);

addToList(face7);

addToList(face8);

addToList(face9);

addToList(face10);

addToList(face11);

addToList(face12);

new FaceFrame("Draw Face Example");

//drawing face


}


}

}

}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
copy this code into a new file and save as FaceFrame.java
Compile and execute it
*/
import java.awt.Color;

import java.awt.Graphics;

import java.util.ArrayList;

import javax.swing.JPanel;

import javax.swing.*;

//FaceFrame class

/*

You have to import import javax.swing.*; in FaceFrame.java

And You have implemented FaceDraw class and called Face()

and main function should be public else it gives main method not found

I just changed FaceDraw with Face

and it have compiled correctly

You have posted that it is not compiling now it is compiling correctly

*/

//Face class

class Face

{

int width;

int height;

int x;

int y;

String smileStatus; //default constructor

public Face()

{

}

// Getters and Setters for width,height,x,y

public int getWidth()

{

return width;

}

public void setWidth(int width)

{

this.width=width;

}

public int getHeight()

{

return height;

}

public void setHeight(int height)

{

this.height=height;

}

public int getX()

{

return x;

}

public void setX(int x)

{

this.x=x;

}

public int getY()

{

return y;

}

public void setY(int y)

{

this.y=y;

}

public String getSmileStatus()

{

return smileStatus;

}

public void setSmileStatus(String smileStatus)

{

this.smileStatus=smileStatus;

}

// to my string method

public String toString()

{

return super.toString();

}

}

//FacePanel class

class FacePanel extends JPanel

{

private static final long serialVersionUID = 1L;

ArrayList<Face>faces;

public FacePanel (ArrayList<Face>faces)

{

this.faces=faces;

}

@Override

protected void paintComponent(Graphics graph)

{

//Super paint component

graph.setColor(Color.BLUE);

// For each Dimension in the Arraylist

for(int i=0;i<faces.size();i++)

{

String smileStatus=faces.get(i).getSmileStatus();

if(smileStatus!=null)

{

if(smileStatus=="Smile")

graph.drawArc(faces.get(i).getX(), faces.get(i).getY(), faces.get(i).getWidth(), faces.get(i).getHeight(), 0, -180);

else

graph.drawArc(faces.get(i).getX(), faces.get(i).getY(), faces.get(i).getWidth(), faces.get(i).getHeight(), 0, 180);

System.out.println(smileStatus);

}

}

}

}

public class FaceFrame extends JFrame

{

private static final long serialVersionUID = 1L;

public static ArrayList<Face> facelist = new ArrayList<Face>();

public FaceFrame(String title)

{

new JFrame(title);

setBackground(Color.WHITE);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

setSize(1500, 700);

add(new FacePanel(facelist));

}

public static void addToList(Face face)

{

facelist.add(face);

}

public static void main(String args[])

{

//First Face

Face face1 = new Face();

//Lip dimensions

face1.setX(180);

face1.setY(350);

face1.setWidth(150);

face1.setHeight(20);

face1.setSmileStatus("Smile");

// face dimensions

Face face2 = new Face();

face2.setX(100);

face2.setY(100);

face2.setWidth(300);

face2.setHeight(400);

//Left Eye

Face face3 = new Face();

face3.setX(195);

face3.setY(210);

face3.setWidth(20);

face3.setHeight(20);

//Right eye

Face face4 = new Face();

face4.setX(295);

face4.setY(210);

face4.setWidth(20);

face4.setHeight(20);

//Second Face

Face face5 = new Face();

//Lip dimensions

face5.setX(580);

face5.setY(350);

face5.setWidth(150);

face5.setHeight(40);

face5.setSmileStatus("Frown");

// face dimensions

Face face6 = new Face();

face6.setX(500);

face6.setY(100);

face6.setWidth(300);

face6.setHeight(400);

//Left Eye

Face face7 = new Face();

face7.setX(595);

face7.setY(210);

face7.setWidth(20);

face7.setHeight(20);

//Right eye

Face face8 = new Face();

face8.setX(695);

face8.setY(210);

face8.setWidth(20);

face8.setHeight(20);

//Third Face

Face face9 = new Face();

//Lip dimensions

face9.setX(980);

face9.setY(350);

face9.setWidth(150);

face9.setHeight(0);

face9.setSmileStatus("Neutral");

// face dimensions

Face face10 = new Face();

face10.setX(900);

face10.setY(100);

face10.setWidth(300);

face10.setHeight(400);

//Left Eye

Face face11 = new Face();

face11.setX(995);

face11.setY(210);

face11.setWidth(20);

face11.setHeight(20);

//Right eye

Face face12 = new Face();

face12.setX(1095);

face12.setY(210);

face12.setWidth(20);

face12.setHeight(20);

//Adding all the face objects to list

addToList(face1);

addToList(face2);

addToList(face3);

addToList(face4);

addToList(face5);

addToList(face6);

addToList(face7);

addToList(face8);

addToList(face9);

addToList(face10);

addToList(face11);

addToList(face12);

new FaceFrame("Draw Face Example");

//drawing face

}

}

Add a comment
Know the answer?
Add Answer to:
I need help with my java code i am having a hard time compiling it //...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have to create a java graphics program which will draw 10 rectangles and 10 ellipses...

    I have to create a java graphics program which will draw 10 rectangles and 10 ellipses on the screen. These shapes are to be stored in an arrayList. I have to do this using 6 different class files. I am not sure whether I successfully created an ellipse in the Oval Class & also need help completing the print Class. I need someone to check whether my Oval Class is correct (it successfully creates an ellipse with x, y, width,...

  • In Java please! Problem You will be using the point class discussed in class to create...

    In Java please! Problem You will be using the point class discussed in class to create a Rectangle class. You also need to have a driver class that tests your rectangle. Requirements You must implement the 3 classes in the class diagram below and use the same naming and data types. Following is a description of what each method does. Point Rectangle RectangleDriver - x: int - top Left: Point + main(args: String[) - y: int - width: int +...

  • (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */...

    (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */ import java.awt.Graphics; public abstract class Animal { private int x; // x position private int y; // y position private String ID; // animal ID /** default constructor * Sets ID to empty String */ public Animal( ) { ID = ""; } /** Constructor * @param rID Animal ID * @param rX x position * @param rY y position */ public Animal( String...

  • package rectangle; public class Rectangle {    private int height;    private int width;    public...

    package rectangle; public class Rectangle {    private int height;    private int width;    public Rectangle(int aHeight, int aWidth) {    super();    height = aHeight;    width = aWidth;    }    public int getHeight() {    return height;    }    public int getWidth() {    return width;    }    public void setHeight(int aHeight) {    height = aHeight;    }    public void setWidth(int aWidth) {    width = aWidth;    }    public int...

  • I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a...

    I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a void method named howToColor(). void howToColor(); } GeometricObject class: public class GeometricObject { } Sqaure class: public class Square extends GeometricObject implements Colorable{ //side variable of Square double side;    //Implementing howToColor() @Override public void howToColor() { System.out.println("Color all four sides."); }    //setter and getter methods for Square public void setSide(double side) { this.side = side; }    public double getSide() { return...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • It's been too long since I have done any Java programming. Can anyone help me with...

    It's been too long since I have done any Java programming. Can anyone help me with this one? Thank you 6.5 Write the declaration for a class named C that declares: (1) a private int instance variable named mX; (2) a private int class variable named mY initialized to 0; (3) a private int class constant named A which is equivalent to 100; (4) a public int class constant named B which is equivalent to 200; (5) public accessor and...

  • java language please. thank you T-Mobile 9:00 AM For this assignment, create a Java class named...

    java language please. thank you T-Mobile 9:00 AM For this assignment, create a Java class named "MyRectangle3d" Your class must have the following attributes or variables · x (the x coordinate of the rectangle, an integer) * y (the y coordinate of the rectangle, an integer) * length (the length of the rectangle, an integer) * width (the width of the rectangle, an integer) * height (the height of the rectangle, an integer) * color( the color of the rectangle,...

  • Hey guys I am having trouble getting my table to work with a java GUI if...

    Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...

  • Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks...

    Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks if two Rectangle objects have the same dimensions Write a Java program to test the equals method public class Rectangle2 K private int width, length; public Rectangle2(int w, int 1) { setWidth(w); setLength(1); System.out.println("Inside parameterized!!!"); } public void setWidth(int w) { width = w;} public void setLength(int i) { length = 1;} int getWidth() { return width; } int getLength() { return length; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT