欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java实现潜艇大战游戏源码

程序员文章站 2022-03-10 17:05:26
代码如下package com.util;import java.awt.borderlayout;import java.awt.color;import java.awt.dimension;im...

代码如下

package com.util;

import java.awt.borderlayout;

import java.awt.color;

import java.awt.dimension;

import java.awt.graphics;

import java.awt.graphics2d;

import java.awt.gridlayout;

import java.awt.image;

import java.awt.toolkit;

import java.awt.event.actionevent;

import java.awt.event.actionlistener;

import java.util.observable;

import javax.swing.jlabel;

import javax.swing.jpanel;

/*

* 进图游戏的主界面面板

*/

public class mainpanel extends jpanel

{

private static final long serialversionuid = 1l;

private mybutton startbutton;

private mybutton exitbutton;

private jlabel helplabel;

private jlabel helplabel1;

private jlabel helplabel2;

private jlabel helplabel3;

private image image;

private jlabel centerlabel;

private boolean isstart;

private boolean isexit;

private observable obs;

public mainpanel(observable ob)

{

obs = ob;

startbutton = new mybutton("进入游戏");

exitbutton = new mybutton("退出游戏");

helplabel = new jlabel();

helplabel1 = new jlabel();

helplabel2 = new jlabel();

helplabel3 = new jlabel();

centerlabel = new jlabel();

this.setlayout(new borderlayout());

this.helplabel.setpreferredsize(new dimension(645,291));

this.helplabel1.setpreferredsize(new dimension(180,80));

this.helplabel2.setpreferredsize(new dimension(215,80));

this.helplabel3.setpreferredsize(new dimension(645,80));

this.centerlabel.setpreferredsize(new dimension(460,80));

centerlabel.setlayout(new gridlayout(2,1));

centerlabel.add(this.startbutton);

centerlabel.add(this.exitbutton);

this.centerlabel.setbackground(new color(255,255,0));

this.add(helplabel,borderlayout.north);

this.add(helplabel1,borderlayout.east);

this.add(helplabel2,borderlayout.west);

this.add(helplabel3,borderlayout.south);

this.add(centerlabel,borderlayout.center);

image = toolkit.getdefaulttoolkit().getimage("imgs/主界面112.png");

// image = new imageicon(image).getimage();

this.startbutton.addactionlistener(

new actionlistener()

{

public void actionperformed(actionevent e)

{

boolean flag = true;

mainpanel.this.setisstart(flag);

mainpanel.this.obs.notifyobservers(mainpanel.this);

}

}

);

this.exitbutton.addactionlistener(

new actionlistener()

{

public void actionperformed(actionevent e)

{

mainpanel.this.setexit(true);

}

}

);

}

public void paint(graphics g)

{

super.paint(g);

graphics2d g2 = (graphics2d) g;

g2.drawimage(image,0,0, this.getwidth(), this.getheight(),this);

super.paintcomponents(g);

}

public boolean getisstart()

{

return this.isstart;

}

public void setisstart(boolean isstart)

{

this.isstart = isstart;

}

public boolean isexit() {

return isexit;

}

public void setexit(boolean isexit) {

this.isexit = isexit;

}

}

效果图

java实现潜艇大战游戏源码

java实现潜艇大战游戏源码

以上就是java实现潜艇大战游戏源码的详细内容,更多关于java潜艇大战游戏的资料请关注其它相关文章!