Solved

getting the icon back to the header

Posted on 2006-11-19
4
236 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
ID: 17974130
Pass the icon in the ctor

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

Expert Comment

by:CEHJ
ID: 17974133
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
ID: 17974235
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
ID: 17974462
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

919 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

16 Experts available now in Live!

Get 1:1 Help Now