Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:41:45+00:00 2026-06-13T06:41:45+00:00

So I was making Java, and made a nice little program. Here’s the code:

  • 0

So I was making Java, and made a nice little program. Here’s the code:

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class aa extends JFrame{
    private JButton jb;
    private JTextField jt0;
    private JTextField jt1;
    private JTextField jt2;
    int jti1;
    int jti2;

    public aa(){
        jb = new JButton(">> FIGHT <<");
        jt0 = new JTextField("", 25);
        jt1 = new JTextField("", 25);
        jt2 = new JTextField("<< BATTLE VICTOR >>", 35);    
        jt0.setText("");
        jt2.setEditable(false);

        jb.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(jt0.getText().length() > jt1.getText().length())
                    jt2.setText((jt0.getText() + " << IS VICTORIUS OVER >> " + jt1.getText()));
                else if(jt1.getText().length() > jt0.getText().length())
                    jt2.setText((jt1.getText() + " << IS VICTORIUS OVER >> " + jt0.getText()));
                else if(jt1.getText().length() == jt0.getText().length())
                    jt2.setText((jt1.getText() + " << TIED >> " + jt0.getText()));
            };
        }
        );

        add(jt0, BorderLayout.NORTH);
        add(jt1, BorderLayout.NORTH);
        add(jt2, BorderLayout.NORTH);
        add(jb, BorderLayout.CENTER);
    }
}

And here is the running script:

import java.awt.FlowLayout;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class a{
    public static void main(String[] args){
        aa b = new aa();

        b.setLayout(new FlowLayout());
        b.setTitle("BattleWords");
        b.setSize(420, 150);
        b.setVisible(true);
        b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

}

I have so far tried the whole setIconImage() crap and it did not work. I want to add in a png or gif or ico image. Where should I place it? Where does the code go and how can it look like?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:41:46+00:00Added an answer on June 13, 2026 at 6:41 am

    You do in fact use JFrame.setIconImage(). Here is an example of code which could appear in the constructor of your JFrame or even better in an initComponents method:

    try {
        Image image = ImageIO.read(aa.class.getResource("/TestImage.png"));
        setIconImage(image);
    } (IOException e) {
       // handle exception
    }
    

    The image TestImage.png would be located in the root folder where your class files are located. This

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a GUI of Stack using Java. Here is my code private
I'm making a Java program that accesses a website, which depends on handing out
I'm making a Java program that can solve the roots using the quadratic equation
Im am making an Java SWT program that is required to run on both
So in class we are making a Java program. We are trying to use
In a program (Java) I'm making I need to check for a specific pin
I'm sure I'm making a rookie mistake with java(this is actually my first program).
I made a simple java program that sends bytes to the parallel port, which
I made a Java program that runs on a computer with two RS-232 ports.
I'm a beginner with Java, and I've been making test code to apply some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.