Click here to Skip to main content
15,741,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So, I have a program project in mind where the user enters some specifications, java stores the input as variable and by using an if else statement displays the result accordingly. The program is about finding your anime girl. I need some tips on how to make this more polished and have more specifications. Also can someone pls tell how to set an image as background. This is a Java GUI project. Editor is BlueJ(not eclipse because my school is teaching us in BlueJ for some reason.).
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class AnimeGirlGenerator extends JFrame {
    private JLabel hairLabel, eyeLabel, skinLabel, resultLabel;
    private JTextField hairField, eyeField, skinField;
    private JButton generateButton;
    private JPanel inputPanel, resultPanel;
    private String hairColor, eyeColor, skinTone;
    private JLabel imageLabel;
    private ImageIcon image;

    public AnimeGirlGenerator() {
        setTitle("Anime Girl Generator");
        setLayout(new GridLayout(2, 1));

        // Input panel
        inputPanel = new JPanel();
        inputPanel.setLayout(new GridLayout(4, 2));

        hairLabel = new JLabel("Hair Color: ");

        hairField = new JTextField();

        eyeLabel = new JLabel("Eye Color: ");

        eyeField = new JTextField();

        skinLabel = new JLabel("Skin Tone: ");

        skinField = new JTextField();

        generateButton = new JButton("Generate");
        generateButton.addActionListener(new ButtonListener());


        // Result panel
        resultPanel = new JPanel();
        resultPanel.setLayout(new FlowLayout());

        resultLabel = new JLabel("Enter specifications above and press 'Generate'");

        imageLabel = new JLabel();



    private class ButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            hairColor = hairField.getText();
            eyeColor = eyeField.getText();
            skinTone = skinField.getText();

            if (hairColor.equals("black") && eyeColor.equals("brown") && skinTone.equals("light")) {
                image = new ImageIcon("blackHairBrownEyesLightSkin.jpg");
            } else if (hairColor.equals("brown") && eyeColor.equals("green") && skinTone.equals("medium")) {
                image = new ImageIcon("brownHairGreenEyesMediumSkin.jpg");
            } else {
                resultLabel.setText("No matching anime girl found.");

    public static void main(String[] args) {
        new AnimeGirlGenerator();

What I have tried:

I tried to add an image preview of how the program looks right now for you guys but couldn't figure it out.
Updated 15-Jan-23 1:41am

1 solution

See Java Swing How to - Add Background image to JPanel[^]. As to how to make the program more polished, that is really not a question that can be answered simply in a Quick Answers forum.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900