TXT

Interface

By Carrie Hall,2014-12-31 08:29
13 views 0
Interface

/*

     * ÀàÃû:Interface

     * ˵Ã?: ?çÃæ

     */

import java.awt.*;

    import java.awt.event.*;

    import javax.swing.*;

    import javax.swing.border.*;

    import java.io.File;

public class Interface {

     //LcdPanelÍ?Ïñ

     public static int NUMBER_OF_LCD_PANEL_IMAGES_FILES = 12;

     public static File[] LCD_PANEL_IMAGES_FILES = {

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/0.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/1.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/2.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/3.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/4.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/5.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/6.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/7.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/8.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/9.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/minus.jpg"),

     new File(System.getProperty("user.dir") + "/lcdNumbersImages/blank.jpg")};

     //StatusPanelÍ?Ïñ

     public static final int NUMBER_OF_STATUS_PANEL_IMAGES_FILES = 5;

     public static final File[] STATUS_PANEL_IMAGE_FILES = {

     new File(System.getProperty("user.dir") + "/expressionsImages/smiling.jpg"),

     new File(System.getProperty("user.dir") + "/expressionsImages/smilingPressed.jpg"),

     new File(System.getProperty("user.dir") + "/expressionsImages/frightened.jpg"),

     new File(System.getProperty("user.dir") + "/expressionsImages/proud.jpg"),

     new File(System.getProperty("user.dir") + "/expressionsImages/depressed.jpg")};

     public static final int SMILING = 0;

     public static final int SMILING_PRESSED = 1;

     public static final int FRIGHTENED = 2;

     public static final int PROUD = 3;

     public static final int DEPRESSED = 4;

     //MinesPanelÍ?Ïñ

     public static final int NUMBER_OF_MINES_PANEL_IMAGES_FILES = 16;

     public static final File[] MINES_PANEL_IMAGES_FILES = {

     new File(System.getProperty("user.dir") + "/mineImages/unpressed.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/1.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/2.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/3.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/4.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/5.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/6.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/7.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/8.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/pressed.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/flag.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/question.jpg"),

     new new File(System.getProperty("user.dir") + "/mineImages/unexploded.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/exploded.jpg"),

     new File(System.getProperty("user.dir") + "/mineImages/wrongMarked.jpg")};

     public static final int UNPRESSED = 0;

     public static final int PRESSED = 9;

     public static final int FLAG_MARK = 10;

     public static final int QUESTION_MARK = 11;

     public static final int QUESTION_PRESSED = 12;

     public static final int UNEXPLODED = 13;

     public static final int EXPLODED = 14;

     public static final int WRONG_MARKED = 15;

     //?çÃæÍ??ê??Ãû?ƺÍ˵Ã?

     public static final String NAME = "É?À×";

     public static final String ABOUT_MESSAGE = "" +

     "Ãû?Æ?ºÉ?À×\n" +

     "?æ???ºv2.0\n" +

     "Ê??ä?º2010.10\n" +

     "×?Õß?º?ç×Ó\n" +

     "ÓÊÏä?ºhzliu226@qq.com";

     //?çÃæÑÕÉ?ºÍ?ß?ç

     public static final Color COLOR_OF_MENU_BAR = Color.white;

     public static final Color COLOR_OF_MENU_ITEM = Color.black;

     public static final Color COLOR_OF_CHOSEN_MENU_ITEM = Color.red;

     public static final Color COLOR_OF_GLOBAL_PANEL = Color.lightGray;

     public static final Color COLOR_OF_STATES_PANEL = COLOR_OF_GLOBAL_PANEL;

     public static final int WIDTH_OF_GLOBAL_PANEL_BORDER = 7;

     public static final int WIDTH_OF_MIDDLE_BORDER = 7;

     public static final int WIDTH_OF_STATES_PANEL_BORDER = 5;

     //ÆäËüÄ?ÈÏÖµ

     public static final int BITS_OF_DISPLAYERS = 3;

     public static final int NUMBER_OF_LEVELS = 4;

     //?ò?ܺÍÃæ?å

     private JFrame jFrame;

     private JPanel jPanel_Global;

     private JPanel jPanel_Head;

     private JPanel jPanel_MinesBorder;

     private JPanel jPanel_HeadBlank;

     private MyStatusPanel jPanel_Status;

     private MyLcdPanel jPanel_MinesLeft;

     private MyLcdPanel jPanel_Time;

     private MyImagesPanel jPanel_Mines;

     //?˵?

     private JMenuBar jMenuBar;

     private JMenu jMenu_Game = new MyMenu("ÓÎÏ?(G)", 'G');

     private JMenu jMenu_Help = new MyMenu("?ïÖú(H)", 'H');

     private JMenuItem jMenuItem_Begin = new JMenuItem("?ªÊ?(B)", 'B');

     private JMenuItem jMenuItem_Exit = new JMenuItem("ÍË?ö(E)", 'E');

     private JMenuItem jMenuItem_Record = new JMenuItem("Ó?ÐÛ?ñ(R)", 'R');

     private JMenuItem jMenuItem_About = new JMenuItem("?ØÓÚ(A)", 'A');

     private JMenuItem[] jMenuItem_Levels = {

     new JMenuItem("?õ??(J)", 'J'),

     new JMenuItem("ÖÐ??(M)", 'M'),

     new JMenuItem("?ß??(H)", 'H'),

     new JMenuItem("?è?ñ(C)", 'C')

     };

     public Interface() {

     //µ?ÈëÍ?Æ?

     MyImagesCollection lcdNumbersImages

     = new MyImagesCollection(LCD_PANEL_IMAGES_FILES,

     NUMBER_OF_LCD_PANEL_IMAGES_FILES);

     MyImagesCollection statusImages

     = new MyImagesCollection(STATUS_PANEL_IMAGE_FILES,

     NUMBER_OF_STATUS_PANEL_IMAGES_FILES);

     MyImagesCollection minesImages

     = new MyImagesCollection(MINES_PANEL_IMAGES_FILES,

     NUMBER

     //Ö??ò?Ü

     jFrame = new JFrame(NAME);

     jFrame.setResizable(false);

     jFrame.setVisible(true);

     //?˵?À?

     jMenuBar = new JMenuBar();

     jMenuBar.setBackground(COLOR_OF_MENU_BAR);

     jFrame.add(jMenuBar, BorderLayout.NORTH);

     //ÓÎÏ??˵?

     jMenuBar.add(jMenu_Game);

     //?ªÊ??˵?Ñ?Ïî

     jMenu_Game.add(jMenuItem_Begin);

     jMenu_Game.addSeparator();

     //µÈ???˵?Ñ?Ïî

     for (int i = 0; i < NUMBER_OF_LEVELS; i++) {

     jMenu_Game.add(jMenuItem_Levels[i]);

     jMenuItem_Levels[i].addActionListener(new ActionListener()

    {

     public void actionPerformed(ActionEvent event) {

     Object jMenuClicked = event.getSource();

     for (int j = 0; j < NUMBER_OF_LEVELS; j++) {

     if (jMenuClicked == jMenuItem_Levels[j]) {

     chooseLevel(j);

     } else {

     dischooseLevel(j);

     }

     }

     }

     }

     );

     }

     jMenu_Game.addSeparator();

     //ÍË?ö?˵?Ñ?Ïî

     jMenu_Game.add(jMenuItem_Exit);

     //?ïÖú?˵?

     jMenuBar.add(jMenu_Help);

     //Ó?ÐÛ?ñ?˵?Ñ?Ïî

     jMenu_Help.add(jMenuItem_Record);

     jMenu_Help.addSeparator();

     //?ØÓÚ?˵?Ñ?Ïî

     jMenu_Help.add(jMenuItem_About);

     jMenuItem_About.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent event) {

     showMessageDialog("?ØÓÚ", ABOUT_MESSAGE);

     }

     }

     );

     //Ãæ?åÇø

     jPanel_Global = new JPanel(new BorderLayout(0, WIDTH_OF_MIDDLE_BORDER));

     jFrame.getContentPane().add (jPanel_Global);

     jPanel_Global.setBorder(BorderFactory.createEmptyBorder(

     WIDTH_OF_GLOBAL_PANEL_BORDER,

     WIDTH_OF_GLOBAL_PANEL_BORDER,

     WIDTH_OF_GLOBAL_PANEL_BORDER,

     WIDTH_OF_GLOBAL_PANEL_BORDER));

     jPanel_Global.setBackground(COLOR_OF_GLOBAL_PANEL);

     //ÏÔÊ?ÇøÃæ?å

     jPanel_Head = new JPanel(new BorderLayout());

     jPanel_Global.add(jPanel_Head, BorderLayout.NORTH);

     jPanel_Head.setBorder(BorderFactory.createCompoundBorder

     (BorderFactory.createBevelBorder(BevelBorder.LOWERED,

     Color.white, Color.white,

     Color.gray, Color.gray),

     BorderFactory.createEmptyBorder

     (WIDTH_OF_STATES_PANEL_BORDER,

     WIDTH_OF_STATES_PANEL_BORDER,

     WIDTH_OF_STATES_PANEL_BORDER,

     WIDTH_OF_STATES_PANEL_BORDER)));

     jPanel_Head.setBackground(COLOR_OF_STATES_PANEL);

     //Ê?ÓàÀ×ÊýÃæ?å

     jPanel_MinesLeft = new MyLcdPanel(BITS_OF_DISPLAYERS, lcdNumbersImages);

     jPanel_Head.add(jPanel_MinesLeft, BorderLayout.WEST);

     //ÖØÐÂ?ªÊ????üÃæ?å

     jPanel_HeadBlank = new JPanel();

     jPanel_HeadBlank.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

     jPanel_HeadBlank.setBackground(COLOR_OF_STATES_PANEL);

     jPanel_Head.add(jPanel_HeadBlank, BorderLayout.CENTER);

     jPanel_Status = new MyStatusPanel(statusImages);

     jPanel_HeadBlank.add(jPanel_Status);

     //ÒÑÓÃÊ??äÃæ?å

     jPanel_Time = new MyLcdPanel(BITS_OF_DISPLAYERS, lcdNumbersImages);

     jPanel_Head.add(jPanel_Tim

     //ÓÎÏ?Ãæ?å

     jPanel_MinesBorder = new JPanel(new BorderLayout());

     jPanel_Global.add(jPanel_MinesBorder, BorderLayout.CENTER);

     jPanel_MinesBorder.setBorder(BorderFactory.createCompoundBorder

     (BorderFactory.createBevelBorder(BevelBorder.LOWERED,

     Color.lightGray, Color.white,

     Color.gray, Color.lightGray),

     BorderFactory.createBevelBorder(BevelBorder.LOWERED,

     Color.white, Color.white,

     Color.gray, Color.gray)));

     jPanel_Mines = new MyImagesPanel(minesImages);

     jPanel_MinesBorder.add(jPanel_Mines);

     //Ñ???Ä?ÈϵÈ??

     jMenuItem_Levels[Minesweeper.DEFAULT_LEVEL].setForeground(COLOR_OF_CHOSEN_MENU_ITEM);

     }

     public MyTimerThread newMyTimer() {

     MyTimeDisplayer myTimer = new MyTimeDisplayer(jPanel_Time);

     myTimer.setEndTime(jPanel_Time.getMaxPositiveNumber());

     return (myTimer);

     }

     public int getBitsOfDisplayers() {

     return BITS_OF_DISPLAYERS;

     }

     public int getTime() {

     return jPanel_Time.getNumber();

     }

     public void setTime(int time) {

     this.jPanel_Time.setNumber(time);

     }

     public int getMinesLeft() {

     return jPanel_MinesLeft.getNumber();

     }

     public void setMinesLeft(int minesLeft) {

     this.jPanel_MinesLeft.setNumber(minesLeft);

     }

     public void setMatrixSize(int xSize, int ySize) {

     Dimension oldPreferredSize = jPanel_Mines.getPreferredSize();

     jPanel_Mines.setMatrixSize(xSize, ySize);

     Dimension newPreferredSize = jPanel_Mines.getPreferredSize();

     if ((oldPreferredSize.width == newPreferredSize.width)

     && (oldPreferredSize.width == newPreferredSize.width)) {

     return;

     }

     jFrame.pack();

     }

     public void setExpression(int imageStatus) {

     jPanel_Status.setStatus(imageStatus);

     }

     public void setGridStatus(int xSite, int ySite, int gridStatus) {

     jPanel_Mines.setImageIndex(xSite, ySite, gridStatus);

     }

     public int getXSite(int xMousePosition) {

     return jPanel_Mines.getXSite(xMousePosition);

     }

     public int getYSite(int yMousePosition) {

     return jPanel_Mines.getYSite(yMousePosition);

     }

     public boolean isOutOfStatusPanel(int xMousePosition, int yMousePosition) {

     return jPanel_Status.isOutOfPanel(xMousePosition, yMousePosition);

     }

     public boolean isOutOfMinesPanel(int xMousePosition, int yMousePosition) {

     return jPanel_Mines.isOutOfPanel(xMousePosition, yMousePosition);

     }

     public JFrame getJFrame() {

     return jFrame;

     }

     public void initializeLocation() {

     Dimension screenSize =

    Toolkit.getDefaultToolkit().getScreenSize();

     Dimension frameSize = jFrame.getSize();

     jFrame.setLocation((screenSize.width - frameSize.width) / 2,

     (screenSize.height - frameSize.height) / 2);

     }

     public void showMessageDialog(String title, String information) {

     JOptionPane.showMessageDialog(jFrame, information, title,

     JOptionPane.INFORMATION_MESSAGE);

     }

     public String showInputDialog(String title, String information) {

     return JOptionPane.showInputDialog(jFrame, information,

     JOptionPane.INFORMATION_MESSAGE);

     }

     public void showWarningDialog(String title, String information) {

     JOptionPane.showMessageDialog(jFrame, information, title,

     JOptionPane.WARNING_MESSAGE);

     }

     public MyImagesPanel getJPanelMines() {

     return jPanel_Mines;

     }

     public MyStatusPanel getJPanelStatus() {

     return jPanel_Status;

     }

     public JMenuItem getJMenuItemBegin() {

     return jMenuItem_Begin;

     }

     public JMenuItem getJMenuItemExit() {

     return jMenuItem_Exit;

     }

     public JMenuItem getJMenuItemRecord() {

     return jMenuItem_Record;

     }

     public JMenuItem[] getJMenuItemLevels() {

     return jMenuItem_Levels;

     }

     public JMenuItem getJMenuItemLevel(int level) {

     return jMenuItem_Levels[level];

     }

     public JMenuItem getJMenuItem_About() {

     return jMenuItem_About;

     }

     public void chooseLevel(int i) {

     jMenuItem_Levels[i].setForeground(COLOR_OF_CHOSEN_MENU_ITEM);

     }

     public void dischooseLevel(int i) {

     jMenuItem_Levels[i].setForeground(COLOR_OF_MENU_ITEM);

     }

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com