Java Submarine War game source project

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.