• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAVA architecture

 
rexjonathan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friend,
I am asking you to some basic JAVA architecture qustion
The question is ,
I am designing an applet ,where i want to display an message in applet say �hello� ,so i use Graphics class to display the string ,the code is
Line1:Graphics g=getGraphics();
Line2:g.drawString(�hello�,10,10);
Or
Public void paint(Graphics g)
{
g.drawString(�hello�,10,10);
}
my question is-�how it is possible without creating instance of Graphics class to call a method drawString() ,people say that the reference to the Graphics class is produced if it�s true please explain me how the refrence is passed and how it is working�
rex

 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"rexjonathan",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applet is a sub-class of component (actually several layers deep). Component implements the getGraphics() method. By default in an Applet, if you do not specifically name a different component then you are asking for the Applet's graphics.
Graphics g=getGraphics(); //getGraphics returns a Graphics object so you did create one. Now g holds the Applets graphics object.
 
rexjonathan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear cindy
thk you very much for your reply,but my question is how it's possible calling a method of class without creating new object to the particular class
------------------
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You DID create an instance of the Graphics class. It is just hidden from you. When you fire up your Applet from your HTML, the Graphic object for the Applet is created for you. That is why the getGraphics() method is able to load up the "g" variable.
 
rexjonathan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cindy thank'sssss a lot once again ,
how it is possible to create a instance for ABSTRACT CLASS Graphics,
and another question for you cindy
look the interfaces provided by the JAVA Archietecure like HttpServletRequest,ActionListener and etc,my qustion is which place(class)the interface methods are implemented in JAVA Archietecure ,for example in RMI interfaces are implemented by interfaceImpl classes ,in the same way where the methods of HttpServletRequest,ActionListener intfaces are implemented,
rex
 
Grant Crofton
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't create an instance of an abstract class yourself.
The Graphics class is like this because getting a graphics context is very platform and OS-dependant, and is done by the JVM in code you cannot see.
You never actaually create one in the code you posted - like Cindy said, when you say g=getGraphics(), some code in the Component class creates a Graphics object and returns it to you. And when you use paint( Graphics g ), one is passed to you as a parameter of the method - again, it's created deep in the murky depths of the JVM where you cannot see it.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of the KNOWN implementations of the interfaces are listed in the API.
http://java.sun.com/j2se/1.3/docs/api/index.html
For example ActionListener is implemented by the following classes:
AWTEventMulticaster, DropTarget.DropTargetAutoScroller, List.AccessibleAWTList, ToolTipManager.insideTimerAction, ToolTipManager.outsideTimerAction, ToolTipManager.stillInsideTimerAction, DefaultCellEditor.EditorDelegate, JComboBox, FormView, DefaultTreeCellEditor, BasicOptionPaneUI.ButtonActionListener, BasicScrollBarUI.ScrollListener, BasicSplitPaneUI.KeyboardUpLeftHandler, BasicSplitPaneUI.KeyboardDownRightHandler, BasicSplitPaneUI.KeyboardHomeHandler, BasicSplitPaneUI.KeyboardEndHandler, BasicSplitPaneUI.KeyboardResizeToggleHandler, BasicTreeUI.ComponentHandler, BasicSliderUI.ScrollListener
And from:
http://java.sun.com/products/servlet/2.3/javadoc/index.html
The only known implementation of httpServletRequest is:
HttpServletRequestWrapper

However there are a zillion classes that folks like you and I have made that also implement these interfaces. Obviously the API, along with you and I, does not know about those.

 
rexjonathan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear cindy
thk you very much your care about me ,if you hava a enough time visit me at www.rexe.atfreeweb.com
send your feedback to rexjonathan@rexsmail.com
thks
rex
fixed the URL by adding "http://"
[This message has been edited by Frank Carver (edited February 21, 2001).]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the link that you provided does not exist. Can you try again?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've fixed the URL in Rex's post, so it should work now. For future reference, you need to put the "http://" on a domain name if you use the HTML < a > tag. If you use a UBB URL tag, you can do without it.
And that sure is a "busy" front page
 
rexjonathan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai guy's thanks a lot for sharing your precious time with me,thankyou verymuch
------------------
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, your site went crazy flashing at me (today I am in Netscape) all I could see was you COOL ReX dog and the News applet kept loading and getting killed and loading and getting killed over and over.
I'll try tomorrow from IE.
BTW: Please re-register as Rex Lastname. (It's much more professional). Thanks.
 
rexjonathan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cindy try it in IE ,i am just now modifying the webpage,send me a details about the mistakes i made in my homepage
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic