2013年9月28日星期六

java package access problems concerning

 This post last edited by the mxlmhgzw on 2013-09-28 01:01:40
I am a novice java are learning java, encountered the following code book
import java.awt.Graphics;
import java.applet.Applet;

public class FriendlyDataTest extends Applet {

private FriendlyData d;

public void init(){
d = new FriendlyData();

}

public void paint(Graphics g){

g.drawString("After instantiation: ",25,25);
g.drawString(d.toString(), 40, 40);



d.x = 77;
d.s = new String("Good bye");
g.drawString("After changing values: ", 25, 55);
g.drawString(d.toString(), 40, 70);



}

}

class FriendlyData{
 int x;
 String s;
 
 public FriendlyData(){
 x = 0;
 s = new String("Hello");
 
 }
 
 public String toString(){
 return "x: "+x+"    s: "+s;
 }
}


the results given in the book are : The first one shows x: 0 s: Hello
second display x: 77 s: Good bye

personal look at the code also think it should be the result, but the result of this code is run out Show All
x: 77 s: Good bye

someone can answer my doubts do next
Thank you ~ ~ ~
------ Solution -------------------------------- ------------
paint method should be called twice , RBI log into the console you look
------ Solution -------- ------------------------------------
run a bit

------ For reference only ----- ----------------------------------

seeking specific method I use eclipse
------ For reference only -------------------------------------- -

seeking specific method I use eclipse  

paint line method Riga
System.out.println ("paint")
------ For reference only ------------------------ ---------------
to x, s added another run getter and setter methods .

------ For reference only ----- ----------------------------------
 on the applet unfamiliar . . Temporarily unable to explain . .
------ For reference only -------------------------------------- -

seeking specific method I use eclipse          
  
paint line method Riga   
System.out.println ("paint")  
confirmed the next is called twice
Why is this so
------ For reference only ------------------------------ ---------


The idea of this code is to achieve out of the friend access
you do not know now changed back principle ......
------ For reference only ------------------- --------------------
 you Hang me !
------ For reference only -------------------------------------- -
never engaged applet, why wasting energy on this . .
------ For reference only -------------------------------------- -

seeking specific method I use eclipse                
    
paint line method Riga     
System.out.println ("paint")          
confirmed the next is called twice   
Why is it so  

generally created when the form is called a paint, you use the drawing api Shiyou call once, twice.

nothing to get to the bottom of this , after all, are the people designing the framework , as long as know what is going on the trip .

The private FriendlyData d; paint method as a variable into the body in just fine


------ For reference only ---------------------------------- -----

seeking specific method I use eclipse                      
      
paint line method Riga       
System.out.println ("paint")                
confirmed the next is called twice     
Why is it so          
  
generally created when the form is called a paint, you use the drawing api Shiyou call once, twice.   
  
nothing to get to the bottom of this , after all, are the people designing the framework , as long as know what is going on the trip .   
  
The private FriendlyData d; paint method as a variable into the body in just fine   
  
 
understand thank guidance mainly do not know how to use them afraid of making mistakes after
------ For reference only ---------- -----------------------------

learning endless Haha

没有评论:

发表评论