java设计报告
❶ java程序设计实验报告 继承与多态
package MyShape;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Circle c = new Circle(2,4,3);
c.printItMyWay();
}
}
abstract class Shape{
public abstract float getCir();
public abstract float getArea();
}
class Point extends Shape implements Printable{
public int x;
public int y;
public Point(int x, int y){
this.x= x;
this.y=y;
}
public Point (){
}
@Override
public float getCir() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getArea() {
// TODO Auto-generated method stub
return 0;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public void printItMyWay() {
System.out.println(" Point ("+x+","+y+")");
System.out.println(" Point Area:"+this.getArea());
System.out.println(" Point Circle:"+this.getCir());
}
}
class Circle extends Point implements Printable{
public float r ;
public Circle(){
}
public Circle(float r,int x, int y ){
if(r>0){
this.r =r;
this.x =x;
this.y=y;
}
}
public float getR() {
return r;
}
public void setR(float r) {
this.r = r;
}
@Override
public float getArea() {
return (float) (r*r*3.14/2);
}
@Override
public float getCir() {
return (float) (3.14*r*2);
}
@Override
public void printItMyWay() {
System.out.println(" Circle ("+x+","+y+")");
System.out.println(" Circle R:"+r);
System.out.println(" Circle Area:"+this.getArea());
System.out.println(" Circle Circle:"+this.getCir());
}
}
interface Printable {
public void printItMyWay();
}
❷ java 计算器课程设计报告
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;//导包
class MyClass extends JFrame
//创建一个MyClass类继承JFrame框架的窗口类,
//也就是说JFrame里有的功能MyClass都能实现
{
JLabel a1=new JLabel("第一个数");
//创建一个显示“第一个数”的标签
JLabel a2=new JLabel("第二个数");
JLabel a3=new JLabel("运算结果");
JTextField b1=new JTextField(5);
//创建一个文本框、默认长度为5,用来输入运算数字,当然也可以默认为空
JTextField b2=new JTextField(5);
JTextField b3=new JTextField(5);
//创建一个用于显示运算结果的标签,也可以创建一个标签来显示
JButton a=new JButton("加");
//创建一个用于加法计算的按钮,点击时进行加法运算
JButton b=new JButton("减");
JButton c=new JButton("乘");
JButton d=new JButton("除");
JPanel jp1=new JPanel();//创建一个面板,用来放控件
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
MyClass()//构造函数,用来初始化的
{
setLayout(new GridLayout(3,1));//添加一个四行四列的布局管理器
jp1.setLayout(new FlowLayout());//设置JP1面板为流式布局管理器
jp1.setLayout(new FlowLayout());
//将a1,b1,a2,b2四个控件添加到jp1面板中
jp1.add(a1);
jp1.add(b1);
jp1.add(a2);
jp1.add(b2);
jp1.add(a3);
//将a,b,c,d四个控件添加到jp2面板中
jp2.add(a);
jp2.add(b);
jp2.add(c);
jp2.add(d);
jp3.add(a3);
jp3.add(b3);
//将jp1,jp2,jp3三个面板添加到窗口中
add(jp1);
add(jp3);
add(jp2);
Object e;
a.addActionListener(new ActionListener()
//创建一个匿名的事件监听器
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
//获取第一个输入数,并将其由String型转换成double型
double y=Double.valueOf(b2.getText().toString());
//获取第二个输入数,并将其由String型转换成double型
b3.setText(""+(x+y));
//将运算结果在b3这个文本框中显示
}
});
b.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
double y=Double.valueOf(b2.getText().toString());
b3.setText(""+(x-y));
}
});
c.addActionListener(new ActionListener()//创建一个匿名的事件监听器
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
double y=Double.valueOf(b2.getText().toString());
b3.setText(""+(x*y));
}
});
d.addActionListener(new ActionListener()//创建一个匿名的事件监听器
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
double y=Double.valueOf(b2.getText().toString());
//因为0不能做除数,所以在这里需要进行判断
if(y==0)
{
b3.setText("错误");
}
else
{
b3.setText(""+(x/y));
}
}
});
//下面的是设置窗口的属性
this.setTitle("计算器");//设置窗口的标题
//this.setSize(400,400);//设置窗口的大小,也可以改成this.pack()
this.pack();
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);//设置关闭属性
this.setVisible(true);//设置窗口的可见性
}
public static void main(String[] args)//主函数
{
new MyClass();
}
}
❸ 有关java开发游戏毕业设计的开题报告
首先介绍了手机游戏开发的背景、目的、意义和手机游戏开发的国内外现状等,接着介绍了手机游戏的特征、类型,以及手机游戏开发的基本原则等。
此外,还详细介绍了手机游戏的开发语言Java和开发平台J2ME,讲述了如何搭建J2ME平台,为读者了解手机游戏开发和设计打下了一定的基础,同时也讲述了有关Eclipse和MIDP应用程序的一些知识。
接着在本文中介绍了手机游戏程序的结构、思想以及相关技术,主要是介绍了几个主要的类:Canvas类和Graphics类,还有介绍了程序中的绘图技术、混淆器的使用、模拟器的调试等。
最后本文介绍了手机游戏程序的代码编写和程序结构等,让读者对本文的手机游戏程序有了一个概括性的了解。
关键词:J2ME,Java,Ecilpse,手机游戏,MIDP ABSTRACT
This article introces something about mobile telephone game.For example, the background and the objective and the meaning of it,and the developing status in in-country and out-country.And then introces the character and the style of telephone game and the basic principle of telephone game exploitation.
And then this article introces Java language and J2ME flat of telephone game exploitation, also narrate how to build J2ME flat. That would be propitious to reader to make a design.And this article also introces something about Eclipse and MIDP application in addition.
In succession,this article introces the configuration and idea and correlation technique of telephone games development.Mainly comes down to Canvas and Graphics,and plot technic in games,and how to use Obfuscator and how to debug simulator.
Finally,this article explains the code of telephone games and the program structure,readers will be understands the phone games in this article.
Keyword:J2ME,Java,Eclipse,telephone game,MIDP
目 录
1.绪 言 5
1.1 手机游戏研究的背景 5
1.2 手机游戏研究的目的和意义 5
1.3 手机游戏的国内外现状 6
1.4 手机游戏概述 7
1.4.1 手机游戏特征 7
1.4.2 手机游戏的类型 8
1.4.3 手机游戏设计的基本原则 8
2.开发环境及相关技术的介绍 10
2.1 JAVA语言特点 10
2.2 J2ME概述 10
2.3 J2ME体系结构 11
2.4 关于ECLIPSE 13
2.5 J2ME开发环境的搭建 13
2.6 MIDP应用程序 14
2.7 JAVA APPLICATION MANAGER 14
3.程序结构、思想和相关技术 15
3.1 本程序需解决的有关技术问题 15
3.2 程序流程图 15
3.3 绘图与MIDP2.0新增的GAMECANVAS包 16
3.3.1 Canvas类 17
3.3.2 Graphics类 17
3.3.3 PNG格式 17
3.3.4 有关绘图的一些技术 18
3.4 内存使用最佳化 18
3.5 混淆器(OBFUSCATOR)的使用 19
3.6 模拟器的调试 19
4.程序分析和编写手机代码 20
4.1 进入游戏前的选择 20
4.2 主游戏逻辑及其涉及到的若干类 20
4.2.1 程序的菜单选项 20
4.2.2 游戏的设定 21
4.2.3 游戏的界面绘制 24
4.2.4 游戏中板的出现和小人位置的检测 25
6.总结与展望 26
7.致 谢 27
参考文献 28