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;/* * Map Game Main interface panel */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 ("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); 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 (actio Nevent 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; The public void Setisstart (Boolean isstart) {this.isstart = Isstart; } public boolean isexit () {return isexit; } public void Setexit (Boolean isexit) { This.isexit = Isexit; } }
Detailed Description:Http://java.662p.com/thread-3188-1-1.html
Java Submarine War game source project