Solved

getting the icon back to the header

Posted on 2006-11-19
4
245 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

626 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