java-如何在一个类中创建方法,在另一个类中操作变量?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-如何在一个类中创建方法,在另一个类中操作变量?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1997字,纯文字阅读大概需要3分钟。
内容图文
![java-如何在一个类中创建方法,在另一个类中操作变量?](/upload/InfoBanner/zyjiaocheng/678/43888ade378a474586e7cb6a768055ff.jpg)
用Java开发一个简单的井字游戏.
我有一个名为GameHelpers的类.此类应包含有用的游戏方法.游戏发生在另一个班级.
GameHelpers中的一种方法是ResetGame().该方法应该将所有9个按钮(井字游戏板上)的文本设置为空白,再次将它们设置为启用,然后将变量设置为1.
这是它的代码:
public class GameHelpers {
public void resetGame(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
buttons[i][j].setEnabled(true);
buttons[i][j].setText("");
count = 1;
}
}
}
}
button []是游戏主类TicTacToe中的JButtons数组.
该方法以前在游戏的主要类别TicTacToe中使用.但是现在它在不同的类中,它无法到达TicTacToe类中的按钮并对其进行操作.
我在TicTacToe中创建了get和set方法,但是如何从GameHelpers中激活它们呢?
如何使GameHelpers中的方法起作用?
解决方法:
您可以参考Java to EXE – Why, When, When Not and How
Drawbacks
Disk footprint. Java bytecode has been designed for compactness, so it has a much higher level than a typical CPU instruction set.
Expect that an executable produced by an AOT compiler will be 2-4
times larger than the original jar file.Dynamic applications. Classes that the application loads dynamically at runtime may be unavailable to the application
developer. These can be third-party plug-ins, dynamic proxies and
other classes generated at runtime and so on. So the runtime system
has to include a Java bytecode interpreter and/or a JIT compiler.Moreover, in the general case only classes that are loaded by either
system or application classloader may be precompiled to native code.
So applications that use custom classloaders extensively may only be
partially precompiled.Hardware-specific optimizations. A JIT compiler has a potential advantage over AOT compilers in that it can select code generation
patterns according to the actual hardware on which the application is
executing. For instance, it may use Intel MMX/SSE/SSE2 extensions to
speedup floating point calculations. An AOT compiler must either
produce code for the lowest common denominator or apply versioning to
the most CPU-intensive methods, which results in further code size
increase.
内容总结
以上是互联网集市为您收集整理的java-如何在一个类中创建方法,在另一个类中操作变量?全部内容,希望文章能够帮你解决java-如何在一个类中创建方法,在另一个类中操作变量?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。