我的问题是这样的:
1.class Robot
{
Camera eyes;
void takePhotograph()
{
eyes =new Camera();
eyes.noOfPhotos++;
}
}
Camera的定义方式还有一样是:Camera eyes=new Camera();
这俩种定义有什么不同?上面的写法将eyes声明为Robot的域变量,这样的话,就可以在Robot类中使用eyes,一般声明一个Robot变量的时间,将要初始化eyes,但不分配内存,eyes可以在需要的时间,分配内存
而且在Robot中,你可以一直使用eyes,一般的我们用Swing控件,加入一个Componets的时间一般这样做,假如你这样声明Robot的域变量Camera eyes=new Camera();,我们声明Robot变量的时间,就需要给eyes分配内存了,而假如你将Camera eyes=new Camera();放在局部变量中,eyes的访问域就受到局限了
2.同一个类的一个方法调用另一个方法,调用者和被调用者是否有前后顺序??
谢谢!!没有啊,只要你在方法中调用另一个方法的时间,另一个方法存在就可以了
1.class Robot
{
Camera eyes;
void takePhotograph()
{
eyes =new Camera();
eyes.noOfPhotos++;
}
}
Camera的定义方式还有一样是:Camera eyes=new Camera();
这俩种定义有什么不同?上面的写法将eyes声明为Robot的域变量,这样的话,就可以在Robot类中使用eyes,一般声明一个Robot变量的时间,将要初始化eyes,但不分配内存,eyes可以在需要的时间,分配内存
而且在Robot中,你可以一直使用eyes,一般的我们用Swing控件,加入一个Componets的时间一般这样做,假如你这样声明Robot的域变量Camera eyes=new Camera();,我们声明Robot变量的时间,就需要给eyes分配内存了,而假如你将Camera eyes=new Camera();放在局部变量中,eyes的访问域就受到局限了
2.同一个类的一个方法调用另一个方法,调用者和被调用者是否有前后顺序??
谢谢!!没有啊,只要你在方法中调用另一个方法的时间,另一个方法存在就可以了
解决方案 »
- SOCKET程序服务端加客户端如何在本机运行 用eclipse
- java文件无法编译成class文件
- 老鼠走迷宫算法
- 程序的运算时间发咋读是不是只程序的运算次数?
- 我现在做一个BBS,做到主题页面,单行和双行颜色不要相同,也就是说,邻行颜色不能相同,怎么做?前辈们给思路
- java
- 关于数据库表设计的问题
- 请教java中的import java.*,引用类的位置在jdk的哪个目录里面?
- 各位JBuilder剑侠客,请问如何加载Jbuilder Tool page,就象swing page一样,显示一些工具……
- Java如何使用带抽象类参数的draw方法
- 我的jb怎么不能编译程序
- 执行出错:Runtime.getRuntime().exec("copy c:\\3001.txt c:\\3002.txt");高分请教了!
{
// Variables for objects that are created.
// in the class constructor
// Label that to hold the title and an image.
private JLabel jl;
// Variable for the text area.
private JTextArea ta;
// Label that to hold the image of a diver and fish.
private JLabel diver;
// Class constructor that provides instruction on
// how the Welcome object is built.
public Welcome()
{ // Opens constructor
// Sets the layout by instantiating a
// BorderLayout container in the
// setLayout method.
setLayout(new BorderLayout());
// Sets the background color for this Welcome
// panel object.
setBackground(Color.white);
// The dive flag image is created by making an
// instance of a JLabel on which an image ojbect
// is initialized, calling the ImageIcon class
// constructor.
jl = new JLabel("Java(TM) Technology Dive Log",
new ImageIcon("images/diveflag.gif"), JLabel.CENTER);
// Sets the font face and size for title.
jl.setFont(new Font("Times-Roman", Font.BOLD, 17));
// Initialize a text area object that contains the text.
// String concatenation is used to limit line length,
// and \n creates new lines for a paragraph space.
ta = new JTextArea("This application uses a" +
" typical Graphical User Interface (GUI), featuring AWT layout "+
"managers and Project Swing components, such as buttons, borders," +
" text areas, menus, and more." +
"\n\nIn addition, the dive log's functionality uses AWT event handlers" +
", methods to manipulate data, Java I/O" +
" to save user input to files, and " +
"special classes to include HTML pages with live links.");
// Sets the font face and size for the text in the
// text area. Line wrap is also set for the text
// area, and the text area cannot be edited.
ta.setFont(new Font("SansSerif", Font.PLAIN, 14));
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
// The following method creates a titled border
// around the entire text area, using the BorderFactory
// class.
ta.setBorder(BorderFactory.createTitledBorder(
" Welcome to the Java Technology Dive Log "));
// Creates an image object on the label object
diver = new JLabel("",
new ImageIcon("images/diver.jpg"), JLabel.CENTER);
// Each of the objects jl, ta, and diver are
// added to the layout with the add method.
// The objects are postioned with the constraints:
// NORTH, CENTER, and SOUTH.
// Note that no objects have been added to East
// or West.
add(jl, BorderLayout.NORTH);
add(ta, BorderLayout.CENTER);
add(diver, BorderLayout.SOUTH);
}// Closes Welcome constructor }// Closes class Welcome