• Post Reply Bookmark Topic Watch Topic
  • New Topic

type mismatch in swing is it??  RSS feed

 
pras
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • 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?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!