Solved

getting the icon back to the header

Posted on 2006-11-19
4
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to determine if a string is a valid SHA value 7 57
Which non-HTML GUI front end to use with Java? 3 67
junit initializtion error 2 22
Java regex 5 22
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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 …
Suggested Courses

751 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