The code is as follows
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;/* * the main interface panel of the */public class game MainPanel extends JPanel { private static final long serialversionuid = 1l; private MyButton startButton; private MyButton exitButton; private jlabel helplabel; &nbSp; 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 ("Enter the game"); exitbutton = new mybutton ("Exit game"); 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); &nbSp; this.add (Helplabel3,borderlayout.south); this.add (Centerlabel,borderlayout.center); image = toolkit.getdefaulttoolkit (). GetImage ("imgs/ Main interface 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; } }
650) this.width=650; "style=" border-bottom:0px;border-left:0px;border-top:0px;border-right:0px; id= "aimg_1165" class= "Zoom" src= "http://img.662p.com/java/forum/201410/18/004937lpkouqxxocdyhgzq.jpg" width= "/>"
650) this.width=650; "style=" border-bottom:0px;border-left:0px;border-top:0px;border-right:0px; id= "aimg_1166" class= "Zoom" src= "http://img.662p.com/java/forum/201410/18/004945eovn5torjn94vrnj.jpg" width= "/>"
Detailed Description: http://java.662p.com/thread-3188-1-1.html
Java Submarine War game source project