Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: output did not appear

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default output did not appear

    Hai i have a coding for game here, unfortunely after i run this coding nothing display as output. PLease would you recheck and correct my coding. For your inform i am using JEcreator software to buld this coding


    package cc.conroy.kf;

    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Random;

    import javax.swing.JWindow;

    public class KidWindow1 extends JWindow implements MouseListener {
    private static int SIZE = 200;

    private GraphicsDevice monitor;

    private Color[] colors = {
    // Purple
    new Color(153, 0, 204),
    // Pink
    new Color(255, 153, 204),
    // Orange
    new Color(255, 153, 0),
    // Red
    new Color(255, 0, 0),
    // Blue
    new Color(0, 0, 255),
    // Green
    new Color(0, 204, 0),
    // Yellow
    new Color(255, 255, 102),
    // Grey
    new Color(153, 153, 153), };

    private enum STATE {
    NEW, STARTED, DONE
    };

    private static STATE currState = STATE.NEW;

    public KidWindow1() {
    super();

    monitor = GraphicsEnvironment.getLocalGraphicsEnvironment()
    .getDefaultScreenDevice();

    createBoard();

    if (monitor.isFullScreenSupported())
    monitor.setFullScreenWindow(this);
    addMouseListener(this);
    }

    private void newGame() {
    currState = STATE.NEW;
    createBoard();
    repaint();
    }

    int clickedCount = 0;
    public void mouseClicked(MouseEvent e) {
    System.out.println(currState);
    if (currState == STATE.DONE) {
    newGame();
    return;
    }

    int x = e.getX();
    int y = e.getY();

    for (BoardItem item : board) {
    if (item.matched)
    continue;

    if (x >= item.x && x <= item.x + SIZE &&
    y >= item.y && y <= item.y + SIZE) {
    if (item.clicked) {
    clickedCount--;
    item.clicked = false;
    } else {
    item.clicked = true;

    if (clickedCount == 1) {
    clickedCount = 0;
    if (checkMatches()) {
    if (checkFinish()) {
    currState = STATE.DONE;
    if (SIZE > 50)
    SIZE = SIZE - 50;
    else
    SIZE = 20;
    }
    }

    continue;
    }

    clickedCount++;
    }
    }
    }

    repaint();
    }

    public boolean checkFinish() {
    for (BoardItem item : board) {
    if (!item.matched)
    return false;
    }
    return true;
    }

    public boolean checkMatches() {
    List<BoardItem> list = new ArrayList<BoardItem>();
    for (BoardItem item : board) {
    if (item.clicked) {
    list.add(item);
    item.clicked = false;
    }
    }

    boolean matched = false;
    Color c = null;
    for (BoardItem item : list) {
    if (c == null)
    c = item.color;
    else if (item.color == c)
    matched = true;
    }

    if (matched)
    for (BoardItem item : list)
    item.matched = true;

    return matched;
    }


    class BoardItem {
    int x;
    int y;
    Color color;
    boolean clicked;
    boolean matched;
    }

    private BoardItem[] board = new BoardItem[16];
    private void createBoard() {
    final int padding = 10;
    final int rowscols = 4;
    int startx = (monitor.getDisplayMode().getWidth() - (SIZE * rowscols + (padding * rowscols))) / 2;
    int starty = (monitor.getDisplayMode().getHeight() - (SIZE * rowscols + (padding * rowscols))) / 2;
    int itemCount = 0;
    for (int i = startx; i < startx + padding + SIZE * rowscols; i = i + SIZE
    + padding) {
    for (int j = starty; j < starty + padding + SIZE * rowscols; j = j
    + SIZE + padding) {
    BoardItem item = new BoardItem();
    item.color = getUnusedColor();
    item.clicked = false;
    item.matched = false;
    item.x = i;
    item.y = j;
    board[itemCount] = item;
    itemCount++;
    }
    }
    usedMap = null;
    }

    private void drawBoard() {
    createBufferStrategy(2);
    Graphics g = getBufferStrategy().getDrawGraphics();

    g.setColor(Color.BLACK);
    g.fillRect(0, 0, monitor.getDisplayMode().getWidth(), monitor
    .getDisplayMode().getHeight());

    for (BoardItem item : board) {
    if (item.matched)
    g.setColor(Color.BLACK);
    else if (item.clicked)
    g.setColor(Color.WHITE);
    else
    g.setColor(item.color);
    g.fillRoundRect(item.x, item.y, SIZE, SIZE, 2, 2);
    }

    g.dispose();
    getBufferStrategy().show();
    currState = STATE.STARTED;
    }

    private void drawFinish() {
    createBufferStrategy(2);
    Graphics g = getBufferStrategy().getDrawGraphics();

    g.setColor(Color.BLACK);
    g.fillRect(0, 0, monitor.getDisplayMode().getWidth(), monitor
    .getDisplayMode().getHeight());

    g.setColor(Color.GREEN);

    g.setFont(new Font("TimesRoman", Font.PLAIN, 44));
    g.drawString("GOOD JOB!", 100, 100);

    g.dispose();
    getBufferStrategy().show();
    }

    public void paint(Graphics g) {
    if (currState == STATE.NEW || currState == STATE.STARTED)
    drawBoard();

    else if (currState == STATE.DONE)
    drawFinish();
    }

    HashMap<Integer, Integer> usedMap = null;
    public Color getUnusedColor() {
    if (usedMap == null)
    usedMap = new HashMap<Integer, Integer>();

    Random r = new Random();
    boolean used = true;
    int index;
    do {

    index = r.nextInt(8);
    if (usedMap.get(index) == null) {
    usedMap.put(index, 1);
    used = false;
    } else if (usedMap.get(index) == 1) {
    usedMap.put(index, 2);
    used = false;
    }
    } while (used);

    return colors[index];
    }

    public void close() {
    monitor.setFullScreenWindow(null);
    }

    public void mouseEntered(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }

    public void mouseExited(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }

    public void mousePressed(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }

    public void mouseReleased(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }
    }


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    50
    My Mood
    Fine
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: output did not appear

    Put your code between
    [highlight=java] and [/highlight]
    se everyone can read it easier.

    application context
    Last edited by daniel.j2ee; December 13th, 2011 at 05:01 PM.

Similar Threads

  1. What would be the output of this?
    By colerelm in forum Java Theory & Questions
    Replies: 2
    Last Post: October 24th, 2011, 04:51 PM
  2. Why is my output not right?
    By Bryan229 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 16th, 2011, 08:17 AM
  3. Help with output
    By jch02140 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 8th, 2011, 01:09 PM
  4. Why am I getting this output?
    By ptabatt in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 6th, 2010, 08:36 PM
  5. need help with output.
    By VictorCampudoni in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 25th, 2010, 12:25 AM