Minesweeper-Java Common (Network Backup)

xiaoxiao2021-03-06  38

Choose from

Nicholas_lin's blog

Oh, I was busy with the exam, I haven't been blog for a long time. Today, I posted a mine procedure I did, raise the popularity, ^ _ ^ because I didn't think about it when I just wrote this program, so I found very little, sorry. Let's talk about the main use: mainframe: main program imagefactory: image management LevelInfo: Level setting Level: Level record Minegrid: Plaid * Dialog: A variety of dialog: AboutDialog: AboutDialog: About dialog box, imitate Windows system Do AWT: LEDNUMBER: Format the digital to the LCD Font Image Source Code: // File Mainframe.java :Package Nicholas.game.Mine;

Import java.awt. *; import java.awt.event. *; import java.io. *;

Import javax.swing. *;

Import nicholas.awt.lednumber; import nicholas.swing.aboutdialog;

public class MainFrame extends JFrame implements ActionListener {// UI components private JLabel mineLabel; private JLabel timeLabel; private JLabel statusButton; private JPanel gridPanel; private JPanel statusPanel; private Dimension gpd; private Dimension spd; private MineGrid grid [] []; private boolean mode [] []; private final int margin = 7; private final int titleh = 52; private int xBound; private int yBound; private int mineCount; private int showCount; // the amount of grids opened private int leftCount; // the amount of mines not labeled private int timepassed; private boolean firstClick; private boolean markCheck; // Menu Components private JMenuItem startItem; private JMenuItem exitItem; private JMenuItem logItem; private JMenuItem aboutItem; private JRadioButtonMenuItem levelItem []; private JCheckBoxMenuItem markCheckItem; // Game Informations Private LevelInfo Levelinfo; Private Int Currentlevel; Private Level Log []; Private Lednumber LED; Private GridMouseAdapter gma; private StatusMouseAdapter sma; private TimeThread timeThread; public MainFrame () {super ( "demining"); // default currentLevel = 0; levelInfo = LevelInfo.DEFAULT_LEVEL [currentLevel]; log = new LevelLog [3]; for (int i = 0; i <3; i ) log [i] = new levelog (); // read from file readlog (); led = new lednumber (); gma = new gridMouseadapter (); SMA = new statusmouseadapter (); / / setup menus setMenuBar (); setStatusPanel (); resetPane (); addWindowListener (new WindowAdapter () {public void windowClosing (WindowEvent e) {writeLog (); System.exit (0);}}); setIconImage (ImageFactory.getInstance () .getimageicon (16) .GetImage ());

setResizable (false);} // execution application public static void main (String args []) {MainFrame application = new MainFrame (); try {UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ());} catch (Exception e) {} } // file operation private void readLog () {try {File logFile = new File ( "mine.log"); if (! logFile.exists ()) return; ObjectInputStream ois = new ObjectInputStream (new FileInputStream (logFile)); For (int I = 0; i <3; i ) {log [i] = (levelog) ois.readObject ();} markcheck = ois.readBoolean (); currentlevel = ois.Readint (); if (currentlevel == 3) {LevelInfo = (LevelInfo) Ois.ReadObject ();} else {levelinfo = levelinfo.default_level [Currentlevel];} catch (Exception E) {System.Ost.Println ("Read Fail" }} Private void writelog ()} private void = new file ("mine.log"); ObjectOutputStream OOS = New fileoutputStream (new fileoutputstream (logfile)); for (int i = 0; i <3; i ) ) {OOS.WriteObject (log [i]);} OOS. WriteBoolean (Markcheck); OOS.WriteInt (Currentlevel); if (currentlevel == 3) {Oos.WriteObject (LevelInfo);} Oos.close ();} catch (Exception E) {System.Ost.Println ("Write Fail ");}} / * * add status label to status panel * / private void setStatusPanel () {JPanel temp; statusPanel = new JPanel (new BorderLayout ()); mineLabel = new JLabel (); mineLabel.setBorder (BorderFactory.createLoweredBevelBorder ()); Temp = new jPanel (New FlowLayout (1, 4, 4)); Temp.Add (mineLabel); Temp.SetBackground; statuspanel.add (Temp, BorderLayout.west); timelabel = new Jlabel ();

timeLabel.setBorder (BorderFactory.createLoweredBevelBorder ()); temp = new JPanel (new FlowLayout (1,4,4)); temp.add (timeLabel); temp.setBackground (Color.LIGHT_GRAY); statusPanel.add (temp, BorderLayout .EAST); statusButton = new JLabel (); statusButton.setBorder (BorderFactory.createRaisedBevelBorder ()); statusButton.addMouseListener (sma); temp = new JPanel (new FlowLayout (1,0,4)); temp.setBackground (Color .LIGHT_GRAY); temp.add (statusButton); statusPanel.add (temp, BorderLayout.CENTER); statusPanel.setSize (10,37); statusPanel.setBorder (BorderFactory.createLoweredBevelBorder ()); spd = statusPanel.getSize (); } private void resetStatusPanel () {mineLabel.setIcon (new ImageIcon (led.getLedImage (leftCount, 3))); timeLabel.setIcon (new ImageIcon (led.getLedImage (timepassed, 3))); statusButton.setIcon (ImageFactory.getInstance (). GetImageicon (17));

private void setGridPanel () {xBound = levelInfo.getXBound (); yBound = levelInfo.getYBound (); mineCount = levelInfo.getMineCount (); MineGrid.xBound = this.xBound; MineGrid.yBound = this.yBound; grid = new MineGrid [xbound]; mode = new boolean [xbound] [ybound]; gridpanel = new jPanel (); gridpanel.setBackground (color.gray); // initialize grid Panel GridPanel.setLayout (null); for (int X = 0; x

}}} / * * Set up menu bar * / private void setmenubar () {jmenubar menubar = new jmenubar (); MenuBar.CreatelineBorder (color.White, 2)); JMenu GameMenu = New Jmenu ("Game (G) "); jMenu helpmenu = new jmenu (" Help (H) "); GameMenu.SetmNemonic ('g'); HelpMenu.SetmNemonic ('h'); startItem = new jmenuitem (" Opening (N) ") Startitem.setAccelerator (KeyStroke.gtKeystroke (KeyEvent.vk_f2,0)); LogItem = New Jmenuitem ("Make Leisure Heroes (T) ..."); MarkCheckItem = New JCHECKBOXMENUITEM ("Mark (?) (M)") EXITITEM = New Jmenuitem ("Exit (X)"); AboutItem = New JMenuItem ("About mine (A) ..."); startitem.setmnemonic ('n'); exitItem.setmnemonic ('x'); AboutItem .setMnemonic ( 'A'); aboutItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_F1,0)); logItem.setMnemonic ( 'T'); markCheckItem.setMnemonic ( 'M'); markCheckItem.setSelected (markCheck); gameMenu .add (startItem); Gamem enu.addSeparator (); // radio group levelItem = new JRadioButtonMenuItem [4]; ButtonGroup levelGroup = new ButtonGroup (); levelItem [0] = new JRadioButtonMenuItem ( "primary (B)"); levelItem [1] = new JRadioButtonMenuItem ( "Intermediate (I)"); LevelItem [2] = New JradiobuttonMenuItem ("Advanced (E)"); LevelItem [3] = New JradiobuttonMenuItem ("Custom (C) ..."); LevelItem [0] .setmnemonic ('B'); LevelItem [1] .SETMNEMONIC ('I'); LevelItem [2] .SETMNEMONIC ('E');

LevelItem [3] .SETMNEMONIC ('c'); for (int i = 0; i <4; i ) {levelgroup.add (levelitem [i]); LevelItem [i] .addactionListener (this); gamemenu.add ( levelItem [i]);} levelItem [currentLevel] .setSelected (true); gameMenu.addSeparator (); gameMenu.add (markCheckItem); gameMenu.addSeparator (); gameMenu.add (logItem); gameMenu.addSeparator (); gameMenu .add (exitItem); helpMenu.add (aboutItem); startItem.addActionListener (this); markCheckItem.addActionListener (this); logItem.addActionListener (this); exitItem.addActionListener (this); aboutItem.addActionListener (this); menuBar. Add (GameMenu); menubar.add (helpmenu); setjmenubar;} private void showaboutdialog () {string readme = ""; file file = new file ("readme.txt"); if (file.exists () ) {Try {BufferedReader INPUT = New FileReader (fileReader (file); StringBuffer bu Ffer = new stringbuffer (); string text; while ((text = INPUT.READLINE ())! = null) Buffer.Append (Text "/ n"); input.close (); readme = buffer.toString (); } catch (IOException ioException) {}} AboutDialog dialog = new AboutDialog (this, "demining", readme, ImageFactory.getInstance () getImageicon (14), ImageFactory.getInstance () getImageicon (16)..); dialog = null; } public void actionPerformed (ActionEvent ae) {if (ae.getSource () == startItem) {restartGame ();} else if (ae.getSource () == markCheckItem) {markCheck = markCheckItem.isSelected ();} else if (ae.getsource () ==

Logitem) {// show heros logdialog dialog = new logdialog (this, log); dialog = null;} else if (ae.getsource () == exitItem) {WriteLog (); system.exit (0);} else (ae.getsource () == AboutItem) {ShowaboutDialog ();} else {// radio buttonTONS INTX; for (x = 0; x <3; x ) {g (ae.getsource () == levelitem [x ]) Break;} if (x <3) {if (currentlevel! = x) {currentlevel = x; LevelInfo = Levelinfo.default_level [currentlevel]; resetpane ();}} else {levelinfo newlevel = CustomDialog.getuserlevel (this, LevelInfo; if (newle! = null) {currentlevel = x; LevelInfo = Newlevel; ResetPane ();}}} // Radio Buttons} / * * 1.setup Grid Panel * 2.Restart Game * / Private Void ResetPane ) {Container container = getContentPane (); container.setLayout (null); container.removeAll (); container.setBackground (Color.LIGHT_GRAY); setGridPanel (); JPanel tempPanel = new JPanel (new BorderLayout ()); tempPanel.setBounds (Margin, Margin, GPD.Width, SPD.HEIGHT); Temppnel.add (StatusPanel, BorderLayout.Center); Container.Add (NULL); Temppnel = New JPanel (New BorderLayout ()); Temppnel.setBounds (Margin, Margin * 2 SPD.HEight, gpd.width, gpd.height); tempPanel.add (gridPanel, BorderLayout.CENTER); tempPanel.setBorder (BorderFactory.createLoweredBevelBorder ()); container.add (tempPanel, null); int X = (int) (Toolkit.getDefaultToolkit () .GetScreensize (). getWidth () - (GPD.Width 3 * margin-1)) / 2; INT Y = (int) ("Toolkit.GetDefault (). GetScreensize (). GetHeight () - (GPD. Height SPD.Height 4 * Margin Titleh) / 2;

SetLocation (x, y); setsize (gpd.width 3 * margin-1, gpd.height spd.height 4 * margin titleh); show (); restartgame ();} private void restartgame ()} private void restartGame ()} = 0; timeThread = null; firstClick = true; resetGridPanel (); resetStatusPanel ();} // Method labelMine private void labelMine (MineGrid g) {if (markCheck) {// being labeled then to marked if (g.isLabeled ( )) {G.setMarked (True); g.setstatus (minegrid.normal); g.seticon (ImageFactory.GetInstance (). GetImageicon (13)); LeftCount ;} else {// normal but marked the normaliff g.ismed ()) {g.setMarked (false); g.seticon (imagefactory.getInstance (). getImageicon (9));} else {// normal and not marked killed dam (ImageFactory.GetInstance) ); g.setstatus (minegrid.labeled); leftcount--;}}} else {// being labelediff (g.slabeled ()) {g.seticon (). GetImageicon (9)); g.setstatus (minegrid.Normal); Leftcount ;} ELS e {// not being labeled g.seticon (imagefactory.getinstance (). getImageicon (10)); g.setstatus (minegrid.labeled); leftcount--;} // Upgrade MineLabel MINELABEL.SETICON (NEW Imageicon (LED .getiMage (LeftCount, 3)));

// when Grid [i] been clicked (CL indeicate the botton). Private void ClickGrid (int x, int y, int cl) {int count = 0; int Lcount = 0; // Change Status to Clicked Grid [x] [y] .SetStatus; // mine is clicked if (Mode [x] [y]) {grid [x] [y] .seticon (). getImageicon (12)); endGame (0); return;} // not mine // count mines and labeled grid grid [x] [y] for (INT i = grid [x] [y] .xlow; i <= grid [x] [y ] .xhigh; i ) {for (int J = grid [x] [y] .ylow; j <= grid [x] [y] .yhigh; j ) {IF (MODE [i] [j]) count ; IF (grid [i] [j] .slabeled ()) LCOUNT ;}} // end // click by Left button if (cl == 1) {grid [x] [y] .seticon (ImageFactory.GetInstance) ); showcount ; if (showcount == xbound * ybound - minecount) {endgame (1); return;}} // no mine around if ((CL == 1 && count == 0) || CL == 2 && count == lcount) {for (int i = grid [x] [y] .XLOW; i <= grid [x] [y] .xhigh; i ) {for (int J = grid [x] [Y ] .ylow; j <= grid [x] [y] .yhigh; j ) {if (i == X && J == Y) Continue; Else IF (Grid [i] [J] .iNormal ()) ClickGrid (i, j, 1);}}}}

// execute on winning or losing private void endGame (int status) {// stop counting time timeThread = null; // win if (status == 1) {statusButton.setIcon (. ImageFactory.getInstance () getImageicon (19)) For (int x = 0; x

true; if (mouseDown) {statusButton.setBorder (BorderFactory.createLoweredBevelBorder ()); icon = statusButton.getIcon (); statusButton.setIcon (ImageFactory.getInstance () getImageicon (18).);}} public void mousePressed (MouseEvent me ) {mouseDown = true; statusButton.setBorder (BorderFactory.createLoweredBevelBorder ()); icon = statusButton.getIcon (); statusButton.setIcon (ImageFactory.getInstance () getImageicon (18));.} public void mouseReleased (MouseEvent me) { mouseDown = false; statusButton.setIcon (icon); statusButton.setBorder (BorderFactory.createRaisedBevelBorder ()); if (mouseIn) restartGame ();} public void mouseExited (MouseEvent me) {mouseIn = false; if (mouseDown) {statusButton. setIcon (icon); statusButton.setBorder (BorderFactory.createRaisedBevelBorder ());}}} private class GridMouseAdapter extends MouseAdapter {private MineGrid current; private boolean leftDown; private boolean rightDown; private boolean middle; public GridMouseAdapter () {super ();} public void mousePressed (MouseEvent me) {current = (MineGrid) me.getSource (); // as soon as right button down, label happen // when not released, wait for next event if (Me.GetButton () == 3) {Rightdown = true; if (! current.isclicked () &&! leftdown) labelmine (current);} else if (me.getbutton () == 2) {RightDown = true; leftDown = true; middle = true;} else {// click and double click not happen until release button leftDown = true; if (current.isNormal ()) statusButton.setIcon (ImageFactory.getInstance () getImageicon (18).); Pressgrid (CURRENT);} IF (Rightdown &&

leftDown) {// double pressAround (current);}} public void mouseEntered (MouseEvent me) {current = (MineGrid) me.getSource (); if (leftDown && rightDown) {pressAround (current);} else if (leftDown) {pressGrid ()}}}} public void mousereleased (mouseevent me) {if (current.isnormal ()) statusButton.Seticon (). getImageicon (17)); int x = current.getxpos (); int y = Current.getypos (); if (leftdown) {leftdown = false; if (firstclick) {Timethread (); timethread.start (); firstclick = false; // changeMine if (Mode [x] [y]) {INT I, J; Do {i = (int)); j = (int));} while (Mode [i] [j]); Mode [x] [y] = false; Mode [i] [j] = true;}}} (RightDown) {ReleaseAround (current); RightDown = false; if (middle) {middle = false;}. Isclicked ()) ClickGrid (x, y, 2);} else {if (Current.i) sNormal ()) clickGrid (x, y, 1);}} else {rightDown = false;}} public void mouseExited (MouseEvent me) {current = (MineGrid) me.getSource (); if (leftDown && rightDown) {releaseAround (current } Else if (leftdown) {releasegrid (current);}}

Private Void PressGrid (Minegrid g) {if (! g.isnormal ()) Return; g.seticon (imagefactory.getInstance (). getImageicon (0));} Private void ReleaseGrid (Minegrid g) {if (! ()); g.setInstance (). getImageicon (9));} private void pressaround (minegrid g) {int x = g.GETXPOS (); int y = g.GetyPos (); for INT i = Grid [x] [y] .xlow; i <= grid [x] [y] .xhigh; i ) {for (int J = grid [x] [y] .ylow; j <= grid [x ] [y] .yhigh; j ) {PressGrid (Grid [i] [j]);}}} private void releasearound (minegrid g) {int x = g.getxpos (); int y = g.getypos (); For (int i = grid [x] [y] .xlow; i <= grid [x] [y] .xhigh; i ) {for (int J = grid [x] [y] .ylow; j <= grid [x] [y] high; j ) {releasegrid (Grid [i] [j]);}}}} // class time the Timethread to count time private class Timethread Extends thread {public timeRETHREAD () {} public void Run ) {Final Thread CurrentThread = thread.currentthread (); while (TimePassed <1000 && currentthread == Timethread) {// Change Timel Abel swingutilities.invokelater (// inner class runnable new runnable () {public void run () {Timelabel.seticon (NEW ImageICON (TimePassed, 3)));}}); try}}); try {thread.sleep (999 );} catch (InterruptedException i) {System.err.println ( "sleep interrupted");} timepassed ;}} // end of method run} // end of class TimeThread} // file MineGrid.javapackage nicholas.game. Import java.aw. *;

Import javax.swing. *;

public class MineGrid extends JLabel {public static final int CLICKED = 0; public static final int LABELED = 1; public static final int NORMAL = 2; public static final int SIZE = 16; public static int xBound; public static int yBound; private int X, Y; int ylow; int xlow; int yhigh; public minegrid (int x, int y) {super (); this.x = x; THIS.Y = Y; STATUS = Normal; mark = false; xhigh = x; yhigh = y; xlow = x; ylow = y; if (x> 0) xlow--; if (x 0) YLOW -;} public void setmarked (boolean m) {mark = m;} public boolean ismarked () {return mark;} public void setstatus (int s) {status = s; } public int getXpos () {return x;} public int getYpos () {return y;} public boolean isClicked () {return status == CLICKED;} public boolean isLabeled () {return status == LABELED;} public boolean isNormal () {RETURN STATUS == Normal;}} / ***************************************** ************ / * STATUS CLICKE LabLABLE DOUBLICK ** CLICKED FALSE TRUE ** LABELED FALSE TRUE FALSE ** NORMAL TRUE TRUE FALSE * / ************ ***************************************** / // file imagefactory.javaPackage nicholas.game.mine;

Import javax.swing.imageic

Public class imagefactory {

Private static imagefactory imagefactory; private static imageicon images [];

Private imageFactory () {images = new imageicon [21]; Images [0] = new imageicon ("image / 0.gif"); images [1] = new imageicon (getClass (). getresource ("image / 1.gif"); images [2] = new imageicon ("image / 2.gif"); images [3] = new imageicon (GetClass (). getResource (" Image / 3.gif "); images [4] = new imageicon (" Image / 4.gif "); images [5] = new imageicon (" image /). GetResource ("image / 5.gif "); images [6] = new imageicon (" Image / 6.gif "); images [7] = new imageicon (" image / 7. GIF ")); Images [8] = new imageicon (" Image / 8.gif "); images [9] = new imageicon (" image / normal.gif " )); Images [10] = new imageicon ("image / flag.gif"); images [11] = new imageicon ("image / mine.gif")) Images [12] = new imageicon (GetClass (). Get Resource ("image / onmine.gif"); images [13] = new imageicon ("image / question.gif"); images [14] = new imageicon (getClass (). Getresource (GetClass (). Getresource "image / Topbar.gif"); images [15] = new imageicon ("image / wrong.gif"); images [16] = new imageicon ("image) (" Image ("image). /mineico.gif "); images [17] = new imageicon (" image / qq1.gif "); images [18] = new imageicon (" iMage / QQ2) "));

Images [19] = new imageicon ("image / qq3.gif"); images [20] = new imageicon ("image / qq4.gif");} PUBLIC Imageicon getImageicon (INT i) {return images [i];

public static synchronized ImageFactory getInstance () {if (imagefactory = null!) {return imagefactory;} else {imagefactory = new ImageFactory (); return imagefactory;}}} // file LevelInfo.javapackage nicholas.game.mine;

Import java.io.serializable;

/ * * Modifiable Level * / Public class levelinfo imports serializable {public static final levelinfo default_level [] = {New LevelInfo (9, 9, 10), New LevelInfo (16, 16, 40), New LevelInfo (16, 30, 99 )}; Private int xbound; private int ybound; public levelinfo (int x, int y, int mc) {if (x> 24) {xbound = 24;} else if (x <9) {xbound = 9;} else {xbound = x;} if (y> 30) {ybound = 30;} else if (y <9) {ybound = 9;} else {ybound = y;} if (mc> (xbound-1 * (YBOUND-1)) {mineCount = (xbound-1) * (YBOUND-1);} else if (mc <10) {mineCount = 10;} else {minecount = mc;}} public int getMinecount () {Return MineCount;} public int getXbound () {return xbound;}

/ * * Record write to file * / class LevelLog implements Serializable {private static final String DEFAULT_NAME = "Anonymous"; private static final int DEFAULT_RECORD = 999; private int record; private String user; public LevelLog () {setDefault ();} public void setDefault () {user = DEFAULT_NAME; record = DEFAULT_RECORD;} public void setRecord (int r) {record = r;} public void setUserName (String name) {user = name;} public int getRecord () {return record; PUBLIC STRING GETUSERNAME () {RETURN User;} PUBLIC STRING TOSTRING () {RETURN RECORD "/ T" user "/ n";}} // file logdialog.javaPackage nicholas.game.mine; import java.aw IMPORT JAVA.AWT.EVENT. *; Import Javax.swing. *;

public class LogDialog extends JDialog implements ActionListener {private LevelLog levelLog []; private JTextArea logArea; private JButton resetButton; private JButton confirmButton; public LogDialog (JFrame frame, LevelLog log []) {super (frame, "demining Heroes", true) ;. getContentPane () setLayout (null); levelLog = log; logArea = new JTextArea (); logArea.setEditable (false); logArea.setBackground (UIManager.getColor ( "CheckBox.background")); logArea.setBounds (10, 10, 160, 60); getContentPane (). Add (logarea, null); resetButton = new jbutton ("Re-Score"); ResetButton.SetBounds (10, 70, 90, 25); ResetButbutton.AddActionListener (this); getContentpane ) .add (resetButton, null); setTextArea (); confirmButton = new JButton ( "OK"); confirmButton.setBounds (105,70,60,25); confirmButton.addActionListener (this);. getContentPane () add (confirmButton , NULL); Setsize (180, 140); setLocationRELATIVETO (FRAME); setresizable (false); show ();} private void setTextarea () {Logare A.Settext ("Primary:" Levellog [0] .tostring () "Intermediate:" LevelLog [1] .tostring () "Advanced:" LevelLog [2] .tostring ());} PUBLIC VOID ActionPerformed (E.GetSource () == resetButton) {for (int i = 0; i <3; i ) {levellog [i] .setDefault ();} setTextarea ();} else {Dispose ();}}} // file customDialog.javaPackage nicholas.game.mine; import java.awt. *; Import java.awt.event. *; Import javax.swing. *;

public class CustomDialog extends JDialog implements ActionListener {private JTextField widthField; private JTextField heightField; private JTextField mineField; private JButton confirmButton; private JButton cancelButton; private static LevelInfo level; public CustomDialog (Frame frame, LevelInfo levelInfo) {super (frame, "Custom Lei District ", true); getContentPane (). SetLayout (null); jlabel templabel = new Jlabel (" height: "); Templabel.setBounds (10, 10, 30, 20); Heightfield = New jtextfield (" levelinfo .GETXBOUND ()); Heightfield.SetBounds (50, 10, 40, 20); getContentPane (). add (templabel, null); getContentPane (). add (heightfield, null); templabel = new jlabel ("Width:" ); Templabel.setbounds (10, 40, 30, 20); widthfield = new jtextfield (" levelinfo.get"); widthfield.setBounds (50, 40, 40, 20); getContentPane (). Add (Templabel). Add (Templabel , NULL); getContentPane (). add (widthfield, null); templabel = new Jlabel ("Moonlight:"); Templabel.setBounds (10, 70, 30, 20); minefield = new jtextfield (" levelinfo. GetMineco UND ()); Minefield.setBounds (50, 70, 40, 20); getContentPane (). add (templabel, null); getContentPane (). add (minefield, null);

confirmButton = new JButton ( "OK"); confirmButton.addActionListener (this); confirmButton.setBounds (100,10,60,25);. getContentPane () add (confirmButton, null); cancelButton = new JButton ( "Cancel") ; cancelButton.addActionListener (this); cancelButton.setBounds (100,45,60,25);. getContentPane () add (cancelButton, null); setSize (180,137); setLocationRelativeTo (frame); setResizable (false); show () ;} public void actionPerformed (ActionEvent e) {level = null; if (e.getSource () == confirmButton) {int x = Integer.parseInt (heightField.getText ()); int y = Integer.parseInt (widthField.getText ()); Int m = integer.Parseint (); level = new levelinfo (x, y, m);} dispose ();} public static levelinfo getuserlevel (jframe frame, levelinfo levelinfo) {CustomDialog Dialog = New CustomDialog (Frame, LevelInfo); Return Level;}} // file userdialog.javaPackage nicholas.game.mine; import java.awt. *; import java.awt.event. *; import javax.swing. *;

public class UserDialog extends JDialog implements ActionListener {private JButton confirmButton; private JTextField nameField; private String [] level = { "primary", "intermediate", "Advanced"}; private static String name; public UserDialog (JFrame frame, int l, String n) {Super (Frame, "New Record", True; getContentPane (). SetLayout (null); jlabel textlabel = new Jlabel ("Broken" Level [L] "record,"); textlabel.setbounds (30, 5, 100, 20); getContentPane (). Add (textlabel, null); TextLabel = New Jlabel ("Please leave your name."); TextLabel.setBounds (30, 25, 100, 20); getContentPane (). Add. Add (TextLabel, NULL); Namefield = New JtextField (N); Namefield.setBounds (10, 60, 120, 20); Namefield.Selectall (); getContentPane (); add (namefield, null); confirmbutton = new jbutton ("OK" ); confirmButton.addActionListener (this); confirmButton.setBounds (40,90,60,25); getContentPane () add (confirmButton, null);. this.setUndecorated (true); setSize (145,130); setLocationRelativeTo (frame);setResizable (false); show ();} public void actionPerformed (ActionEvent e) {name = nameField.getText (); dispose ();} public static String showInputNameDialog (JFrame frame, int l, String n) {UserDialog dialog = new UserDialog (frame, l, n); return name;}} // file aboutdialog.javaPackage nicholas.swing; import java.awt. *; Import java.awt.event. *; Import javax.swing. *;

public class AboutDialog extends JDialog implements ActionListener {JButton cancelButton; JTextArea textArea; JLabel titleLabel; JLabel topbarLabel; JLabel iconLabel; public AboutDialog (JFrame frame, String title, String readme, ImageIcon topbar, ImageIcon icon) {super (frame, "about" title, true);. getContentPane () setLayout (null); JTextArea textArea; JLabel topbarLabel; JLabel iconLabel; topbarLabel = new JLabel (topbar); topbarLabel.setBounds (0,0,413,77);. getContentPane () add (topbarLabel) IConlabel = New Jlabel (Icon); Iconlabel.setBounds (New Rectangle (10, 90, 36, 36)); getContentPane (). Add (iconlabel); Jlabel TitleLabel = New Jlabel ("ColinSoft (r)" Title) Titlelabel.SetFont (New Font ("Dialog", 1, 13)); Titlelabel.SetBounds (56, 84, 345, 26); getContentPane (). Add (titleLabel);

textArea = new JTextArea (); textArea.setText (readme); textArea.setBackground (UIManager.getColor ( "CheckBox.background")); textArea.setLineWrap (true); textArea.setEditable (false); textArea.setCaretPosition (0) ; JScrollPane scrollPane = new JScrollPane (); JViewport viewport = scrollPane.getViewport (); viewport.add (textArea); scrollPane.setBounds (new Rectangle (56, 110, 345, 188)); scrollPane.setBorder (null); getContentPane () .add (scrollpane, borderLayout.ceter); CancelButton = New JButton; CancelButton.SetBounds (New Rectangle (340, 315, 60, 23)); CancelButton.AddActionListener (this); getContentPane (). add (cancelButton); JLabel separator = new JLabel (); separator.setBounds (60,307,340,1); separator.setBorder (BorderFactory.createRaisedBevelBorder ());. getContentPane () add (separator); separator = new JLabel (); separator .SetBounds (60, 308, 340, 1); Separetor.SetBorder (bo rderFactory.createLoweredBevelBorder ());. getContentPane () add (separator); setSize (419,378); setLocationRelativeTo (frame); setResizable (false); show ();} public void actionPerformed (ActionEvent e) {dispose ();}} // file LedNumber.javapackage nicholas.awt; import java.awt.Component; import java.awt.Graphics; import java.awt.Polygon; import java.awt.Image; import java.awt.Color; import java.awt. Image.BufferedImage;

Public class ledNumber Extends Component {Private Polygon SegmentPolygon []; Private Int NumBerSegment [] [] = {{0, 1, 2, 3, 4, 5}, // 0 {1, 2}, // 1 {0, 1, 3, 4, 6}, // 2 {0, 1, 2, 3, 6}, // 3 {1, 2, 5, 6}, // 4 {0, 2, 3, 5, 6 }, // 5 {0, 2, 3, 4, 5, 6}, //6 {0, 1, 2}, // 7 {0, 1, 2, 3, 4, 5, 6}, / / 8 {0, 1, 2, 3, 5, 6} // 9}; private int div [] = {1,10,100,100,10000,100000}; private image numberimage []; private color fontcolor = color. red; // the color of number private Color bgColor = Color.black; private Color maskColor = Color.darkGray; private int dWidth = 12; private int dHeight = 21; public LedNumber () {init ();} public LedNumber (Color Fc) {fontcolor = fc; init ();} public ledNumber (Color FC, Color BGC) {bgcolor = bgc; fontcolor = fc; init ();} public LedNumber (Color FC, Color BGC, C Olor MC) {bgcolor = BGC; fontcolor = fc; maskcolor = mc; init ();} public image getledimage (int DG, int bound) {DG% = div [bound]; image image = new bufferedimage (dwidth * bound, DHEIGHT, BUFFEREDIMAGE.TYPE_INT_RGB); Graphics g = image.getgraphics (); bound ---; for (int i = bound; i> = 0; i -) {g.drawImage (NumberImage [DG / DIV [i]] , (Bound-I) * dwidth, 0, this); DG% = DIV [i];} return image;}

public void init () {segmentPolygon = new Polygon [7]; numberImage = new Image [10]; // setup polygons setNumberPolygon (); setNumberImage ();} public void setBackGround (Color bgc) {bgColor = bgc;} public void setFontColor (Color fc) {fontColor = fc;} public void setMaskColor (Color mkc) {maskColor = mkc;} public void setDigitWidth (int w) {dWidth = w; init ();} public void setDigitHeight (int h) {dHeight = h; init ();} public void setdigitsize (int w, int h) {dwidth = W; dHEight = h; init ();

Private void setNumberImage () {INT i = 0; int K; INT K; GRAPHICS G; While (i <10) {NumberImage [i] = new bufferedimage (15, 20, bufferedimage.type_int_rgb); g = numberImage [ I] .getgraphics (); g.setcolor (bgcolor); g.FillRect (0, 0, 15, 20); g.setColor (color.dark_gray); j = 0; while (j

SegmentPolygon [3] .addpoint (1, DHEIGHT-1); segmentpolygon [3] .addpoint (4, DHEIGHT-4); segmentpolygon [3] .addpoint (dwidth-4, dHEight-4); segmentpolygon [4] = new Polygon (); segmentpolygon [4] .addpoint (1, DHEIGHT-2); SegmentPolygon [4] .addpoint (1, mid); segmentpolygon [4] .addpoint (3, mid); segmentpoin [4] .addpoint (4 , MID 1); SegmentPolygon [4] .addpoint (4, DHEIGHT-5); segmentpolygon [5] = new polygon (); segmentpolygon [5] .addpoint (1, mid-1); segmentpoin [5] .addpoint (1, 1); segmentpolygon [5] .addpoint (4, 4); segmentpolygon [5] .addpoint (4, mid-3); segmentpolygon [5] .addpoint (2, MID-1); segmentpolygon [6] = new polygon (); segmentpolygon [6] .addpoint (3, mid-1); segmentpolygon [6] .addpoint (4, MID-2); SegmentPolygon [6] .addpoint (DWIDTH-4, MID-2); SegmentPolygon [6] .addpoint (dwidth-3, mid-1); segmentpolygon [6] .addpoint (dwidth-5, mid 1); segmentpolygon [6] .addpoint (4 , MID 1);}} PS: Wow, copy sticky pain, I don't know if there is any missed file ... Which friend knows how free can be applied, please tell me. The pictures and files can't put it up. Everyone will look at it ... if you want .jar files, please write email or message. ------- Develop Note of ----------- Mine in Java by Nicholas --- 2004.11.20i Hate Java Layout Management! See the ghost, there is a problem with two-dimensional array, with one Nothing! Grids are all squeezed into a piece ... There is no way 2004.11.21a small step out! Question is on minegrid, all overwritten, there is no problem ... then put the layout together, the general layout is coming out.

2004.11.22 It seems that I feel more easier to implement the Grid in one-dimensional array ... If I first put the thunder in the top ten, then only ten exchanges ... Thunder distribution should be even uniform .. .

2004.11.23

Finally, it is almost the same. The only problem is to break the record, if the left right is pressed, then the next start will release the right click.

2004.11.27

The final completed. The modification has been changed for several days, finally passed his own test, officially became a Version 0.9

转载请注明原文地址:https://www.9cbs.com/read-62082.html

New Post(0)