Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Peers in AWT

 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I want to know the usage of peer classes in details.
please help me.


Also explain, why can't we can not instantiate an abstact class?

Thanks in Advance.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets. For more information, please read this.

This post has been moved to a more appropriate forum.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prash Singh wrote:
I want to know the usage of peer classes in details.
please help me.


What do you want to know?

The peers are there but (unless you're porting AWT to a new platform or something) there is no reason to mess with them.



Also explain, why can't we can not instantiate an abstact class?



short, direct answer: Because that's what the JLS says. (ยง8.1.1.1)

more informative answer: An abstract class is a class that has "holes" where some of the implementation is missing. How would it be useful to instantiate something with such holes?
 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir,

I want to know how does a button is displayed on the container?

Does the peer classes have any thing to do with it?

Because someone told me that when we create a button,
Button button = new Button("Click");

an object of ButtonPeer class is created.
and that peer class deals with the native API to get that button from the OS.

and Exaxtly what do we mean by a peer in java?


and about Abstract class...
It's OK that JLS says that.
But why?
What could have been the possible reason that has denied an abstract class such privilege?


Please forgive me, if I am annoying.


Thanks in Advance.

 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prash Singh wrote:and about Abstract class...
It's OK that JLS says that.
But why?
What could have been the possible reason that has denied an abstract class such privilege?

Because as Brian said, an abstract class can contain "holes" - methods without implementation.

Consider the following example:
Now what would happen if you could instantiate MyAbstractClass, then call its doSomethingElse method?
Now you could argue that the second line should cause a compiler error, but that would also disallow the following:
Therefore, only the initialization of an abstract can fail at compile time.

Let's quit the discussion about abstract classes here; Use One Thread Per Question. If you have any remaining questions that are non-Swing / AWT related, please post a new question in Beginning Java or Java in General. This thread should focus on the peer question from now on.
 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Rob,

Thanks for the explanation.

I am clear about it now. and I'll also take care of one thread one question principle.

But what about peer classes?
That question is still a mystery to me.

How does a button in AWT is actually created?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea about that, sorry.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prash Singh wrote:I want to know how does a button is displayed on the container?

Does the peer classes have any thing to do with it?

Because someone told me that when we create a button,
Button button = new Button("Click");

an object of ButtonPeer class is created.
and that peer class deals with the native API to get that button from the OS.


Yes, this is essentially correct. The button peer on windows knows how to use the windows APIs to place a button on the screen. On OSX is uses the OSX APIs to place a button on the screen. On unix-like systems it uses X11 API's to place a button on the screen. This is how AWT peers work, but since you can't really do anything with them it doesn't really matter if you realize they are there or not.

 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Brian Cole,

Thanks for your reply.

Please also tell me that are swings and awt part of SCJP exam?

and what projects (likely) could be created using Swing and event Handling.?
Please list few names, if you can?

Thanks in Advance.....

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!