Hi I wanted to ask a quick question. I have two classes. And within my main class i am able to pass in variable to three variables EyeColorR to EyeColorB and able to send them the my Eye Class under the consturctor class Eye. the catch is I need to also display it under JFrame as an actual image and the only way to apply the color is through a paint class under graphics2d. And how do i then call the variable i have set under getColor class in my eye class to the paint class under my Eye class.
Sorry if it sounds a bit confusing but thats the best i can explain.
Main idea: i want to transfer the variables of getColor to the public void paint(Graphics g)and set it to the color of iris in
g2.setPaint();
g2.fill(leftIris); and
g2.setPaint();
g2.fill(rightIris);
Eye class:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.util.*;
public class Eyes extends JComponent
{
int red;
int green;
int blue;
public Color getColor(){
Color eyeColor = new Color(red, green, blue);
return eyeColor;
}
public Eyes(int r, int g, int b){
red = r;
green = g;
blue = b;
}
Shape leftEye = new Ellipse2D.Float(150, 160, 50, 50);
Shape leftIris = new Ellipse2D.Float(160, 170, 35, 35);
Shape leftPupil = new Ellipse2D.Float(170, 180, 15, 15);
Shape rightEye = new Ellipse2D.Float(290, 160, 50, 50);
Shape rightIris = new Ellipse2D.Float(300, 170, 35, 35);
Shape rightPupil = new Ellipse2D.Float(310, 180, 15, 15);
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D)g;
Color color1 = new Color(eyes.getColor);
g2.setPaint(Color.WHITE);
g2.fill(leftEye);
g2.setPaint();
g2.fill(leftIris);
g2.setPaint(Color.BLACK);
g2.fill(leftPupil);
g2.setPaint(Color.WHITE);
g2.fill(rightEye);
g2.setPaint(eyes.getColor);
g2.fill(rightIris);
g2.setPaint(Color.BLACK);
g2.fill(rightPupil);
}
}
Main Class
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
public class TestFace
{
public static void main(String args[]) {
JFrame frame = new JFrame();
frame.setSize(550,550);
frame.setTitle("How do you like my Face?");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println("Hi, and welcome to the Face Generator 3000!");
System.out.println("With this program you can edit either the eyes, face size or color, and the lips size or color.");
Scanner input = new Scanner(System.in);
System.out.println("What would you like to edit today?");
String choice = input.next();
if (choice.equalsIgnoreCase("eyes")){
System.out.println("Editing the eyes lets you edit only one feature and thats the color!");
System.out.println("What color eyes would you like?");
System.out.println("(Input method is in RGB letting you customize it fully)"+"\n"+"(Blue: red is 135, green is 206, blue is 250)");
System.out.println("red: a");
int EyeColorR = input.nextInt();
System.out.println("green: ");
int EyeColorG = input.nextInt();
System.out.println("blue: ");
int EyeColorB = input.nextInt();
Eyes eyes = new Eyes(EyeColorR, EyeColorG, EyeColorB);
frame.add(eyes);
}
//Eyes Component = new Eyes();
frame.setVisible(true);
}
}