• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

type mismatch in swing is it??

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1>public class JLabelDemo extends JApplet {
2> public void init() {
3> Container contentPane=getContentPane();
4> ImageIcon ii=new ImageIcon("USA.gif");
5> JLabel j1=new JLabel("USA",ii,JLabel.CENTER);
6>
7> contentPane.add(j1);
8> }
9>}

/**** Doubts*****************/
line 5 doubt: basically the constructor JLabel structure is JLabel(String s,Icon i,int align)

it accepts Icon i ,but in line 5 it is accepting ii which is a ImageIcon class reference how come is it true??

and how come JLabel.CENTER returns a int?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

line 5 doubt: basically the constructor JLabel structure is JLabel(String s,Icon i,int align)

it accepts Icon i ,but in line 5 it is accepting ii which is a ImageIcon class reference how come is it true??[/QB]


ImageIcon is a class that implements the Icon interface. Therefore, ImageIcon IS-A Icon.

and how come JLabel.CENTER returns a int?


JLabel.CENTER (which is actually defined as SwingConstants.CENTER), is a static final int; see here. Static final fields are also referred to as constants, and that's exactly what this is - JLabel.CENTER will be replaced by the compiler by its fixed value, 0.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic