Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-06 11:43:14
Now it works fine

new ImageIcon(ImageIO.read(new BufferedInputStream(getClass().getResourceAsStream("Blank.png"))));
2  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-05 20:32:57
I also tried this one

new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("/White.png")));

new ImageIcon(ImageIO.read(getClass().getClassLoader().getResource("White.png")));

new ImageIcon(ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("White.PNG")));

new ImageIcon(ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("/White.PNG")));

new ImageIcon("White.PNG");

new ImageIcon("/White.PNG");

without succes

When i compile i get a note that says "Note: Some input files use or override a deprecated API."

And when i try to debug now then under the compile process it comes with an error, but when i "just" compile nothing happens before runtime?

3  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-05 12:10:13
so if they are in the same folder as the class files it is (File.seperator + "Filename.type"); ?

becuse i tried that and "/Filename.type" and "Filename.type"

and it didnt work

my calling of the images is in a nested class, do that effect something here?
4  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-05 11:39:23
hmmm... it seems that i canot get it to work.

i read the api too http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)

I have tried different things and they all return null:

Quote
return new ImageIcon(getClass().getClassLoader().getResource("White.png"));

Quote
Image Black = null;
//                try {
//                    Black = ImageIO.read(getClass().getClassLoader().getResourceAsStream("Black.png"));
//                } catch (IOException e) {
//                   
//                    System.out.println("Black billedet mangler");
//                   
//                }

as you can se i have also changed my images to png.



5  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-05 09:22:54
I tryed that now, and all 3 variables are comming out with "null" values"

The files are in the same map as the class files, and i treid to load them with:

("White.JPEG")

(File.separator + "White.JPEG")

(File.separator + "Engine" + File.separator + "White.JPEG")

(File.separator + "build" + File.separator + "Engine" + File.separator + "White.JPEG")

but nothing works, i also tried with jpg and gif files too.

6  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-03 22:18:06
I have made a method that checks the status of the button and then returns the IconImage coresponding to that:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
public ImageIcon KnapIcon(int x, int y) {
       
        Image White = null;
                try {
                    White = ImageIO.read(new File(File.separator + "Engine" + File.separator + "White.JPEG"));
                } catch (Exception e) {
                   
                    System.out.println("White billedet mangler");
                   
                }
       
        Image Blank = null;
                try {
                    Blank = ImageIO.read(new File(File.separator + "Engine" + File.separator + "Blank.JPEG"));
                } catch (Exception e) {
                   
                    System.out.println("Blank billedet mangler");
                   
                }
       
        Image Black = null;
                try {
                    Black = ImageIO.read(new File(File.separator + "Engine" + File.separator + "Black.JPEG"));
                } catch (Exception e) {
                   
                    System.out.println("Black billedet mangler");
                   
                }
       
        if(feltFarveTjekker(x,y,felter.WHITE)) {
                   return new ImageIcon(White);
                }
        else if(feltFarveTjekker(x,y,felter.BLACK)) {
                   return new ImageIcon(Black);
                }
               
        else {
                   return new ImageIcon(Blank);
                }
    }


I compile and it goes fine, then at runtime i get this error:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
White billedet mangler
Blank billedet mangler
Black billedet mangler
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
        at Engine.blackAndWhite.KnapIcon(blackAndWhite.java:529)
        at Engine.blackAndWhite$pladenPanel.<init>(blackAndWhite.java:575)
        at Engine.blackAndWhite.<init>(blackAndWhite.java:93)
        at Engine.Main$1.run(Main.java:23)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)



What am I doing wrong?
7  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-03 14:31:14
Just one more problem (I hope)... I cant find any getSender() method in the ActionEvent API http://java.sun.com/javase/6/docs/api/java/awt/event/ActionEvent.html

This is the last error NetBean shows to me right now, thank you for all your support so far... sry becuse it is kind af basic, but i hope i just need a push in the right direction then i can stand for myself Smiley
8  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-02 11:02:00
the MouseAdapter is a class, not an interface, so your can not use it with implements. You need to implement a MouseListener instead or create an anonymous instance of the MouseAdapter directly while adding.

Anyway, this is not what you should do. Implement an ActionListener and add it to the button instead.

Speaking of the button:
1  
2  
int placering = y+i;
Pladen.add(new JButton().putClientProperty(placering , Point(y,i)));


is wrong, since this way you would add the result of putClientProperty() to "pladen". Also you are missing a "new" statement before the Point, hence the "Cannot find symbol" message. The meanign of your "placering" variable is not clear to me. You won't gain anything by having a client property name, that's changing for every button. How do you know, which client property you would extract in the actionPerformed() method? Reread my post that suggests the putClientProperty().

Try
1  
2  
3  
4  
JButton button= new JButton();
button.putClientProperty("location" , new Point(y,i));
button.addActionListener(this); // implement ActionListener in PladenPanel.
pladen.add(button);


Btw. you should adhere to some coding conventions:
- class and interface names should start with a capital letter (public class PladenPanel extends JPanel implements ActionListener)
- method and variable names should start with a lower case letter (JPanel pladen = new JPanel(new GridLayout(10,10));)
- name your interfaces, classes, methods and variables in english

All this is fairly basic stuff. I would advice to find some decent tutorials to teach you java and swing and follow them word by word until you have grasped the concepts.

Linking to your local drive will obviously not work Wink

thank you for the answer.

I see now that there is some basic stuff i forgot to make, i were to fast on that ocation sry, and then there is some stuff that i am very unsercure in (especially swing) and i thank you for advecing me
9  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-11-01 17:08:04
Now i have read the swing tutorial again, i have read a lot of API's too.

But there I have some questions still.

this is what i have done for now, not at all finished but still i get a lot of problems and questions to ask (it is only a part of the class, this snippet is a part of the BWA class): http://pastebin.com/f5d55545a

In the first line i get a "interface expected here" when i have "import java.awt.event.MouseAdapter;" why that?

Then i get a error in line 9: I have "import java.awt.Point;" but it says the "Cannot find symbol" error

line 14 and 21 also give errors but i think that have something to do with that error in line 1.

is this done enterily wrong?

Documentation:

mouse adapter/listener
file:///C:/Documents%20and%20Settings/STS-b%C3%A6rbar/Skrivebord/programering/tutorial/tutorial/uiswing/events/mouselistener.html

JPanels
file:///C:/Documents%20and%20Settings/STS-b%C3%A6rbar/Skrivebord/programering/tutorial/tutorial/uiswing/components/panel.html
10  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-10-28 15:18:19
- Use aButton.putClientProperty("location", new Point(x,y)); to store the square's location for later use.

I cant find any methods or API's that have such command?
11  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-10-28 14:43:29
- Just create a JPanel inside your games JFrame with NetBeans and call it e.g. boardPanel.
- Set the boardPanel to gridLayout with 10 rows and 10 cols.
- Use two nested for loops (x and y coordinates) to add the JButtons to the cells. (See swing tutorials)
- Use aButton.putClientProperty("location", new Point(x,y)); to store the square's location for later use.
- Add an ActionListener to the buttons to change the states.
- In the actionPerformed(event) you can use ((JButton)event.getSender()).getClientProperty("location")
  to get the location of the square which was clicked
- change the square-state in BAW class and change the state of the buttons directly

You should not need any Thread to update the squares.

One question:

When you in the game  push one button you don't only change the state of that button but probebly several buttons. what is the best method to refresh all the buttons?
12  Java Game APIs & Engines / Java 2D / Re: Creating a GUI for a board game on: 2007-10-28 13:29:19
- Just create a JPanel inside your games JFrame with BetBEans and call it e.g. boardPanel.
- Set the boardPanel to gridLayout with 10 rows and 10 cols.
- Use two nested for loops (x and y coordinates) to add the JButtons to the cells. (See swing tutorials)
- Use aButton.putClientProperty("location", new Point(x,y)); to store the square's location for later use.
- Add an ActionListener to the buttons to change the states.
- In the actionPerformed(event) you can use ((JButton)event.getSender()).getClientProperty("location")
  to get the location of the square which was clicked
- change the square-state in BAW class and change the state of the buttons directly

You should not need any Thread to update the squares.

Thank you...
13  Java Game APIs & Engines / Java 2D / Creating a GUI for a board game on: 2007-10-28 12:36:39
First please read my topic here: http://forums.java.net/jive/message.jspa?messageID=242477#242477

As you can se I were told to go here... and i hope I have plased this topic the right place.

Thank you for reeding this.

PS: this is only the first steps, I have a lot of cool ideas to throw in this projekt.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

pw (37 views)
2014-07-24 01:59:36

Riven (38 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00

Cero (60 views)
2014-07-16 00:42:17

Riven (57 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!