Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting the icon back to the header

Posted on 2006-11-19
4
Medium Priority
?
250 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 150 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

963 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