Solved

How to draw image on top most Layer?

Posted on 2004-03-22
13
612 Views
Last Modified: 2012-08-14
my java file is @ http://www.geocities.com/giasens/files/JavaBingo.zip

i have created CardLayout,
inside a "card", i hav many inner BorderLayout(s)
now, i just realise i couldnt drawImage on my top most layer...

can any one HELP me?? thanks.. ..

btw, can anyone suggest me where to learn paint() ??
i couldnt get what's repaint() about...

thanks again.
0
Comment
Question by:SaiSeng
[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
  • 6
  • 5
  • 2
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10649191
Why not just add an Image in an ImageIcon in a JLabel?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 10649203
0
 

Author Comment

by:SaiSeng
ID: 10649214
btw, the following image shows what i want to paint on
http://www.geocities.com/giasens/files/myBox.JPG

thanks
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 86

Expert Comment

by:CEHJ
ID: 10649254
Yes. where it's marked 'box' should be a JLabel with your image in it, as shown in the above example
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10649279
Hi SaiSeng,

Your links seems not good : "This page is not available. " or "Sorry, the page you requested was not found. "

>> i just realise i couldnt drawImage on my top most layer...
  public void paint(Graphics g)
  {
     g.drawImage(img,0,0,null); // Image img already loaded
  }

0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10649325
>> Your links seems not good
In fact your links are good if we first visit your home page : http://www.geocities.com/giasens/

0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10649339
Replace:
      public void paint(Graphics g)
      {
             g.drawImage(box, 80, 80, this);
      }

By:
      public void paint(Graphics g)
      {
                      g.drawImage(box, 80, 80, this);
                      super.paint(g); // for lightweight child components
      }
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10649359
>>public void paint(Graphics g)

Actually that is not the way to do things if using Swing. See here for how to:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20927185.html
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10649377
By:
     public void paint(Graphics g)
     {
            g.drawImage(box, 20, 140, this);  // 20,140 as in myBox.jpg
            super.paint(g); // for lightweight child components
     }
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10649409
You can wait until the image is loaded:

   public void init()
   {
        box = getImage(getCodeBase(), "box.jpg");
        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(box, 0);
        try{
        tracker.waitForAll();
        }catch(Exception e){e.printStackTrace();}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10649461
Using an ImageIcon will get you out of all the little gotchas caused by Java loading its images aynchronously, apart from saving you having to rewrite your JPanel as a JPanel subclass
0
 

Author Comment

by:SaiSeng
ID: 10657782
paint doesnt help... but Jlabel...
thanks anyway ;)
now i'm trying to addMouseListener on the icon ;)

/*
 * ImageIcon icon = new ImageIcon("box.jpg");
 * JLabel label = new JLabel(icon);
 */
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10658105
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JAVA API design with micro service cloud in mind 1 106
hashmap order 17 58
jsp CRUD operations with and without prepared statement also hibernatge 1 46
Java List 4 71
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…
Suggested Courses

740 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