Solved

getting the icon back to the header

Posted on 2006-11-19
4
234 Views
Last Modified: 2011-09-20
hi.
i want to put an icon in the header(like  the fox icon in the FF browser etc.) instead of the Java icon.
i tried something out,but for now, i only managed to remove the icon at all... :-S
my code looks like that (not all of it, just the parts needed here...)

public class BootStrap
{      static String ImageIconFolder;
      static ImageIcon tPointerLogo;
      public BootStrap(String timageIconFolder,ImageIcon pointerLogo){
            ImageIconFolder=timageIconFolder;
            tPointerLogo=pointerLogo;
      }
    public static void main(String args[])
    {      String ImageName="\\PointerLogo.jpg";
          String ImageFolder="C:\\Temp";
          String ImageIconFolder=ImageFolder.concat(ImageName);
        tPointerLogo = new ImageIcon(ImageIconFolder);

        new LoopSMS("Loop SMS    Ver. 1.01");
       // LoopSMS.setIconImage(PointerLogo.getImage());
    }
}

...      //constructor
    public LoopSMS(String frameTitle)
    {
        super(frameTitle);
           //initialise components
        init();
           //construct GUI
        construct();
          //Display GUI
        display();
    }

  private void construct()
    {
        ImageIcon PointerLogo = new ImageIcon();
        PointerLogo=BootStrap.tPointerLogo;

      //  JFrame MainFrame = new JFrame("Loop SMS Ver. 1.01");
      this.setIconImage(PointerLogo.getImage());
    //    MainFrame.setLocationRelativeTo( null );
       this.getContentPane().add(this.MainFramePanel);
       // MainFrame.add(MainFramePanel);
        MainFramePanel.add(DLPanel);
    ....}

how do i fix that?
0
Comment
Question by:yabelson
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Pass the icon in the ctor

new LoopSMS("Loop SMS    Ver. 1.01", tPointerLogo);
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Then in construct you can do

setIconImage(tPointerLogo);

(after you've assigned the icon passed in the ctor to an instance variable)
0
 
LVL 10

Accepted Solution

by:
ADSLMark earned 50 total points
Comment Utility
Different solution:

    public static void main(String args[])
    {  
        String ImageName="\\PointerLogo.jpg";
        String ImageFolder="C:\\Temp";
        String ImageIconFolder=ImageFolder.concat(ImageName);
        tPointerLogo = new ImageIcon(ImageIconFolder);

        LoopSMS ls = new LoopSMS("Loop SMS    Ver. 1.01");
        ls.setIconImage(tPointerLogo.getImage());
    }

Btw, a lot of rubbish in your code, try to keep your code clean and simple.
I think you are missing the idea of static vs non-static. If you have a class Student and you want an instance of that class you do:

Student instanceStudent = new Student();

Now if you want to call a method on such object you do:

instanceStudent.methodname();

This will call the object and all the class-attributes are set for this specific student. While if you do:

Student.attribute;

then you can only do so, if the attribute is static (since Student is not an instance/object but a class name).
So small example:

class Student
{
  final static String school = "university college";
  public int id;
  private int pid;

  public Student(int id)
  {
    this.id = id;
    this.pid = id*2;
  }

  public int getPid()
  {
    return pid;
  }
}

This class has one constructor (namely Student(int id)) and a method getId() which returns the id of the student. There are three attributes, one static (value) and one non-static (id). Id is public, but pid is private.

So lets look at the follow example code:
Student s1 = new Student(10);
System.out.println(Student.school); //outputs "university college"
System.out.println(Student.id);       //not possible, variable is non-static
System.out.println(s1.id);               //outputs 10
System.out.println(s1.getPid());      //outputs 20
System.out.println(s1.pid);             //not possible, variable is private

I'm not sure if I explained this well enough for you to understand, but there is a lot of redundancy in your code.

Good luck.
Mark
0
 
LVL 1

Author Comment

by:yabelson
Comment Utility
ok 10x,i got the point.
i'll try and make this better.
i've got another question, but it will go in another Q. :-)
(got lots of points to spread around LOL)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array6 challenfge 6 62
return in catch statement 1 39
Core Java. What output will be and why ? 6 57
backtracking recursion  code 19 39
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now