Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  i nid a simple games puzzle program using a java  (Read 751 times)
0 Members and 1 Guest are viewing this topic.
Offline nightkids07

Senior Newbie


Exp: 1 month or less



« Posted 2014-02-04 04:54:33 »

plss help me
Offline zFollette

Junior Duke


Exp: 2 years


I like jokes


« Reply #1 - Posted 2014-02-04 04:55:02 »

plss help me


Are you serious?

Humor will keep you alive.
Offline yokiyoki

Junior Duke


Exp: 1 month or less


"It is fun to learn new things"


« Reply #2 - Posted 2014-02-04 04:58:15 »

why don`y you try and we will help you if you got some problems.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2014-02-04 05:00:01 »

Featured games is for games that are selected my moderators (read the board rules). Also this question is incredibly vague and I'm tempted to just move it to the chitchat monster, so please provide your specific problem and what you're using.
Offline zFollette

Junior Duke


Exp: 2 years


I like jokes


« Reply #4 - Posted 2014-02-04 05:20:13 »

if i try unknown source

What?

Humor will keep you alive.
Offline nightkids07

Senior Newbie


Exp: 1 month or less



« Reply #5 - Posted 2014-02-04 05:25:24 »

exception i thread main java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown soure)
at Puzzle.<init>(puzzle.java:41)
at Puzzle.main(puzzle.java:80
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #6 - Posted 2014-02-04 05:25:36 »

http://www.mazeworks.com/home.htm

No... I can't do this. I mean, it is obvious you are trying to learn games programming, but there is no way you'll get it like this.

It looks like there is a bug somewhere in your code, that you didn't post up yet... can you post some source code so we can look at it at least?

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #7 - Posted 2014-02-04 05:30:39 »

sorry this is my 1st time

First time or not, you should have the common sense to know to post what you're trying to do, what the problem is, and what the code related to the problem is.
Offline zFollette

Junior Duke


Exp: 2 years


I like jokes


« Reply #8 - Posted 2014-02-04 05:33:59 »

exception i thread main java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown soure)
at Puzzle.<init>(puzzle.java:41)
at Puzzle.main(puzzle.java:80

You are trying to add an ImageIcon that does not exist to a JFrame. This will not work.

Humor will keep you alive.
Offline nightkids07

Senior Newbie


Exp: 1 month or less



« Reply #9 - Posted 2014-02-04 06:02:39 »

this is a copy of totorial puzzle program how can i run it....
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;

import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class Puzzle extends JFrame implements ActionListener {

    private JPanel centerPanel;
    private JButton button;
    private JLabel label;
    private Image source;
    private Image image;
    int[][] pos;
    int width, height;

    public Puzzle() {

        pos = new int[][] {
                            {0, 1, 2},
                            {3, 4, 5},
                            {6, 7, 8},
                            {9, 10, 11}
                        };


        centerPanel = new JPanel();
        centerPanel.setLayout(new GridLayout(4, 4, 0, 0));

        ImageIcon sid = new ImageIcon(Puzzle.class.getResource("icesid.jpg"));
        source = sid.getImage();

        width = sid.getIconWidth();
        height = sid.getIconHeight();


        add(Box.createRigidArea(new Dimension(0, 5)), BorderLayout.NORTH);   
        add(centerPanel, BorderLayout.CENTER);


        for ( int i = 0; i < 4; i++) {
            for ( int j = 0; j < 3; j++) {
                if ( j == 2 && i == 3) {
                    label = new JLabel("");
                    centerPanel.add(label);
                } else {
                    button = new JButton();
                    button.addActionListener(this);
                    centerPanel.add(button);
                    image = createImage(new FilteredImageSource(source.getSource(),
                        new CropImageFilter(j*width/3, i*height/4,
                            (width/3)+1, height/4)));
                    button.setIcon(new ImageIcon(image));
                }
            }
        }

        setSize(325, 275);
        setTitle("Puzzle");
        setResizable(false);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setVisible(true);
    }


    public static void main(String[] args) {

        new Puzzle();

    }

    public void actionPerformed(ActionEvent e) {
        JButton button = (JButton) e.getSource();
        Dimension size = button.getSize();

        int labelX = label.getX();
        int labelY = label.getY();
        int buttonX = button.getX();
        int buttonY = button.getY();
        int buttonPosX = buttonX / size.width;
        int buttonPosY = buttonY / size.height;
        int buttonIndex = pos[buttonPosY][buttonPosX];



        if (labelX == buttonX && (labelY - buttonY) == size.height ) {

             int labelIndex = buttonIndex + 3;

             centerPanel.remove(buttonIndex);
             centerPanel.add(label, buttonIndex);
             centerPanel.add(button,labelIndex);
             centerPanel.validate();
        }

        if (labelX == buttonX && (labelY - buttonY) == -size.height ) {

             int labelIndex = buttonIndex - 3;
             centerPanel.remove(labelIndex);
             centerPanel.add(button,labelIndex);
             centerPanel.add(label, buttonIndex);
             centerPanel.validate();
        }

        if (labelY == buttonY && (labelX - buttonX) == size.width ) {

             int labelIndex = buttonIndex + 1;

             centerPanel.remove(buttonIndex);
             centerPanel.add(label, buttonIndex);
             centerPanel.add(button,labelIndex);
             centerPanel.validate();
        }

        if (labelY == buttonY && (labelX - buttonX) == -size.width ) {

             int labelIndex = buttonIndex - 1;

             centerPanel.remove(buttonIndex);
             centerPanel.add(label, labelIndex);
             centerPanel.add(button,labelIndex);
             centerPanel.validate();
        }
    }
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LiquidNitrogen
« Reply #10 - Posted 2014-02-04 06:07:42 »

I found this tutorial very useful when i started out learning java: http://zetcode.com/lang/java/

Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #11 - Posted 2014-02-04 06:08:38 »

Puzzle.class.getResource("icesid.jpg")
must be returning null.

Offline kramin42
« Reply #12 - Posted 2014-02-04 06:09:43 »

You need an image named icesid.jpg (e.g. this one) in the project's folder.

"All science is either physics or stamp collecting." - Ernest Rutherford.
CodeGolf4k
M4nkala
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (45 views)
2014-10-17 03:59:02

Norakomi (36 views)
2014-10-16 15:22:06

Norakomi (27 views)
2014-10-16 15:20:20

lcass (31 views)
2014-10-15 16:18:58

TehJavaDev (61 views)
2014-10-14 00:39:48

TehJavaDev (61 views)
2014-10-14 00:35:47

TehJavaDev (51 views)
2014-10-14 00:32:37

BurntPizza (69 views)
2014-10-11 23:24:42

BurntPizza (39 views)
2014-10-11 23:10:45

BurntPizza (81 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!