Results 1 to 9 of 9
  1. #1
    neha_bat is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Exclamation urgent...minesweeper problem

    hello
    I have made the game minesweeper in java using frames.:) It is getting compiled but i am facing the following run time error:(.....

    C:\mines>javac mine.java

    C:\mines>java mine
    Exception in thread "main" java.lang.NoClassDefFoundError: mine (wrong name: Min
    e)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)

    My code is as follows:



    Java Code:
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    
    import java.util.Random;
    
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.awt.BorderLayout;
    
    import javax.swing.JFrame;
    
    class Board extends JPanel {
    
        private final int NUM_IMAGES = 13;
        private final int CELL_SIZE = 15;
    
        private final int COVER_FOR_CELL = 10;
        private final int MARK_FOR_CELL = 10;
        private final int EMPTY_CELL = 0;
        private final int MINE_CELL = 9;
        private final int COVERED_MINE_CELL = MINE_CELL + COVER_FOR_CELL;
        private final int MARKED_MINE_CELL = COVERED_MINE_CELL + MARK_FOR_CELL;
    
        private final int DRAW_MINE = 9;
        private final int DRAW_COVER = 10;
        private final int DRAW_MARK = 11;
        private final int DRAW_WRONG_MARK = 12;
    
        private int[] field;
        private boolean inGame;
        private int mines_left;
        private Image[] img;
        private int mines = 40;
        private int rows = 16;
        private int cols = 16;
        private int all_cells;
        private JLabel statusbar;
    
    
        public Board(JLabel statusbar) {
    
            this.statusbar = statusbar;
    
            img = new Image[NUM_IMAGES];
    
            for (int i = 0; i < NUM_IMAGES; i++) {
                img[i] =
                        (new ImageIcon(this.getClass().getResource((i)
                            + ".png"))).getImage();
            }
    
            setDoubleBuffered(true);
    
            addMouseListener(new MinesAdapter());
            newGame();
        }
    
    
        public void newGame() {
    
            Random random;
            int current_col;
    
            int i = 0;
            int position = 0;
            int cell = 0;
    
            random = new Random();
            inGame = true;
            mines_left = mines;
    
            all_cells = rows * cols;
            field = new int[all_cells];
            
            for (i = 0; i < all_cells; i++)
                field[i] = COVER_FOR_CELL;
    
            statusbar.setText(Integer.toString(mines_left));
    
    
            i = 0;
            while (i < mines) {
    
                position = (int) (all_cells * random.nextDouble());
    
                if ((position < all_cells) &&
                    (field[position] != COVERED_MINE_CELL)) {
    
    
                    current_col = position % cols;
                    field[position] = COVERED_MINE_CELL;
                    i++;
    
                    if (current_col > 0) { 
                        cell = position - 1 - cols;
                        if (cell >= 0)
                            if (field[cell] != COVERED_MINE_CELL)
                                field[cell] += 1;
                        cell = position - 1;
                        if (cell >= 0)
                            if (field[cell] != COVERED_MINE_CELL)
                                field[cell] += 1;
    
                        cell = position + cols - 1;
                        if (cell < all_cells)
                            if (field[cell] != COVERED_MINE_CELL)
                                field[cell] += 1;
                    }
    
                    cell = position - cols;
                    if (cell >= 0)
                        if (field[cell] != COVERED_MINE_CELL)
                            field[cell] += 1;
                    cell = position + cols;
                    if (cell < all_cells)
                        if (field[cell] != COVERED_MINE_CELL)
                            field[cell] += 1;
    
                    if (current_col < (cols - 1)) {
                        cell = position - cols + 1;
                        if (cell >= 0)
                            if (field[cell] != COVERED_MINE_CELL)
                                field[cell] += 1;
                        cell = position + cols + 1;
                        if (cell < all_cells)
                            if (field[cell] != COVERED_MINE_CELL)
                                field[cell] += 1;
                        cell = position + 1;
                        if (cell < all_cells)
                            if (field[cell] != COVERED_MINE_CELL)
                                field[cell] += 1;
                    }
                }
            }
        }
    
    
        public void find_empty_cells(int j) {
    
            int current_col = j % cols;
            int cell;
    
            if (current_col > 0) { 
                cell = j - cols - 1;
                if (cell >= 0)
                    if (field[cell] > MINE_CELL) {
                        field[cell] -= COVER_FOR_CELL;
                        if (field[cell] == EMPTY_CELL)
                            find_empty_cells(cell);
                    }
    
                cell = j - 1;
                if (cell >= 0)
                    if (field[cell] > MINE_CELL) {
                        field[cell] -= COVER_FOR_CELL;
                        if (field[cell] == EMPTY_CELL)
                            find_empty_cells(cell);
                    }
    
                cell = j + cols - 1;
                if (cell < all_cells)
                    if (field[cell] > MINE_CELL) {
                        field[cell] -= COVER_FOR_CELL;
                        if (field[cell] == EMPTY_CELL)
                            find_empty_cells(cell);
                    }
            }
    
            cell = j - cols;
            if (cell >= 0)
                if (field[cell] > MINE_CELL) {
                    field[cell] -= COVER_FOR_CELL;
                    if (field[cell] == EMPTY_CELL)
                        find_empty_cells(cell);
                }
    
            cell = j + cols;
            if (cell < all_cells)
                if (field[cell] > MINE_CELL) {
                    field[cell] -= COVER_FOR_CELL;
                    if (field[cell] == EMPTY_CELL)
                        find_empty_cells(cell);
                }
    
            if (current_col < (cols - 1)) {
                cell = j - cols + 1;
                if (cell >= 0)
                    if (field[cell] > MINE_CELL) {
                        field[cell] -= COVER_FOR_CELL;
                        if (field[cell] == EMPTY_CELL)
                            find_empty_cells(cell);
                    }
    
                cell = j + cols + 1;
                if (cell < all_cells)
                    if (field[cell] > MINE_CELL) {
                        field[cell] -= COVER_FOR_CELL;
                        if (field[cell] == EMPTY_CELL)
                            find_empty_cells(cell);
                    }
    
                cell = j + 1;
                if (cell < all_cells)
                    if (field[cell] > MINE_CELL) {
                        field[cell] -= COVER_FOR_CELL;
                        if (field[cell] == EMPTY_CELL)
                            find_empty_cells(cell);
                    }
            }
    
        }
    
        public void paint(Graphics g) {
    
            int cell = 0;
            int uncover = 0;
    
    
            for (int i = 0; i < rows; i++) {
                for (int j = 0; j < cols; j++) {
    
                    cell = field[(i * cols) + j];
    
                    if (inGame && cell == MINE_CELL)
                        inGame = false;
    
                    if (!inGame) {
                        if (cell == COVERED_MINE_CELL) {
                            cell = DRAW_MINE;
                        } else if (cell == MARKED_MINE_CELL) {
                            cell = DRAW_MARK;
                        } else if (cell > COVERED_MINE_CELL) {
                            cell = DRAW_WRONG_MARK;
                        } else if (cell > MINE_CELL) {
                            cell = DRAW_COVER;
                        }
    
    
                    } else {
                        if (cell > COVERED_MINE_CELL)
                            cell = DRAW_MARK;
                        else if (cell > MINE_CELL) {
                            cell = DRAW_COVER;
                            uncover++;
                        }
                    }
    
                    g.drawImage(img[cell], (j * CELL_SIZE),
                        (i * CELL_SIZE), this);
                }
            }
    
    
            if (uncover == 0 && inGame) {
                inGame = false;
                statusbar.setText("Game won");
            } else if (!inGame)
                statusbar.setText("Game lost");
        }
    
    
        class MinesAdapter extends MouseAdapter {
            public void mousePressed(MouseEvent e) {
    
                int x = e.getX();
                int y = e.getY();
    
                int cCol = x / CELL_SIZE;
                int cRow = y / CELL_SIZE;
    
                boolean rep = false;
    
    
                if (!inGame) {
                    newGame();
                    repaint();
                }
    
    
                if ((x < cols * CELL_SIZE) && (y < rows * CELL_SIZE)) {
    
                    if (e.getButton() == MouseEvent.BUTTON3) {
    
                        if (field[(cRow * cols) + cCol] > MINE_CELL) {
                            rep = true;
    
                            if (field[(cRow * cols) + cCol] <= COVERED_MINE_CELL) {
                                if (mines_left > 0) {
                                    field[(cRow * cols) + cCol] += MARK_FOR_CELL;
                                    mines_left--;
                                    statusbar.setText(Integer.toString(mines_left));
                                } else
                                    statusbar.setText("No marks left");
                            } else {
    
                                field[(cRow * cols) + cCol] -= MARK_FOR_CELL;
                                mines_left++;
                                statusbar.setText(Integer.toString(mines_left));
                            }
                        }
    
                    } else {
    
                        if (field[(cRow * cols) + cCol] > COVERED_MINE_CELL) {
                            return;
                        }
    
                        if ((field[(cRow * cols) + cCol] > MINE_CELL) &&
                            (field[(cRow * cols) + cCol] < MARKED_MINE_CELL)) {
    
                            field[(cRow * cols) + cCol] -= COVER_FOR_CELL;
                            rep = true;
    
                            if (field[(cRow * cols) + cCol] == MINE_CELL)
                                inGame = false;
                            if (field[(cRow * cols) + cCol] == EMPTY_CELL)
                                find_empty_cells((cRow * cols) + cCol);
                        }
                    }
    
                    if (rep)
                        repaint();
    
                }
            }
        }
    }
    
    
    
    public class Mine extends JFrame {
    
        private final int width = 250;
        private final int height = 290;
       
    
        private JLabel statusbar;
        
        public Mine() {
             
               super();
               initialize();
                     }
       private void initialize()
            {
        
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setSize(width, height);
            this.setLocationRelativeTo(null);
            this.setTitle("Minesweeper");
    
            this.statusbar = new JLabel("");
            this.add(statusbar, BorderLayout.SOUTH);
    
           this.add((statusbar));
    
            this.setResizable(false);
            this.setVisible(true);
        }
        
        public static void main(String[] args) {
            new Mine();
        }
    }
    Please help me......
    Last edited by Fubarable; 08-15-2010 at 02:00 PM. Reason: m

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What is the name of the file?

    Also, please let me welcome you to our forum. I do have a couple of suggestions that may help you get answers quicker:

    1) please check out my 1st signature link to see how to use code tags. Using these will help your code retain its formatting, be easier to read, and thus be more likely to have been read.

    2) Avoid marking your threads "urgent". While it may be urgent to you, it's not to us, and many of the volunteers here resent being pushed or rushed to give a solution. Many also don't like the implication from an "urgent" marked post that the poster feels his post is more important than the other posts, since quite frankly it isn't. Thus marking it "urgent" can often have the exact opposite effect you intended. Simply leave that out and you'll usually get an answer faster.

    Much luck.
    Last edited by Fubarable; 08-15-2010 at 01:47 PM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by neha_bat View Post
    hello
    I have made the game minesweeper in java using frames.:) It is getting compiled but i am facing the following run time error:(.....

    C:\mines>javac mine.java

    C:\mines>java mine
    Exception in thread "main" java.lang.NoClassDefFoundError: mine (wrong name: Mine)
    The name of your class is 'Mine' (capital M), not 'mine' (lowecase m). That silly MS Windows filing system doesn't really care about upper/lowercase but the jvm does.

    kind regards,

    Jos

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  7. #7
    neha_bat is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Post

    thanks

    @fubarable
    i will keep that in mind n it'll nt be repeated in future.


    I am not able to upload images in the frame.....my image files name are 0.png,1.png............12.png.
    the code is displaying the frame without any image on it.

    public Board(JLabel statusbar) {

    this.statusbar = statusbar;

    img = new Image[NUM_IMAGES];

    for (int i = 0; i < NUM_IMAGES; i++) {
    img[i] =
    (new ImageIcon(this.getClass().getResource((i)
    + ".png"))).getImage();
    }

    setDoubleBuffered(true);

    addMouseListener(new MinesAdapter());
    newGame();
    }

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Code tags!!!
    n it'll nt be
    What is that supposed to mean?
    http://www.catb.org/~esr/faqs/smart-...ons.html#intro
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,448
    Rep Power
    25

    Default

    displaying the frame without any image
    Where do you attempt to display any images?
    Just having some bytes in storage won't do it.

Similar Threads

  1. urgent problem
    By mudit222 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-20-2010, 07:59 PM
  2. urgent problem
    By mudit222 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-12-2010, 07:24 PM
  3. MineSweeper!
    By CrushOverwrite in forum New To Java
    Replies: 17
    Last Post: 02-24-2010, 02:34 PM
  4. Another Urgent problem!!
    By winnie99 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-18-2009, 06:25 PM
  5. Minesweeper problem! need help!
    By jeffrey in forum New To Java
    Replies: 1
    Last Post: 10-02-2009, 04:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •