Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  Game Development / Newbie & Debugging Questions / Re: get image of panel on: 2011-05-29 04:32:56
ya i understand the difference.  What I am trying to do is get the img path that was placed inside of a panel.  So I dont have to keep track of them.  I tried to do something with the path but I get null.
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  
class ImagePanel extends JPanel {

     private Image img;
     private String path2;
     
     public ImagePanel(String path) {
        Image image = new ImageIcon(path).getImage();
        path2 = path;
       //this(new ImageIcon(img).getImage());
   
     }
     public ImagePanel(Image img) {
       this.img = img;
     
       Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
       setPreferredSize(size);
       setMinimumSize(size);
       setMaximumSize(size);
       setSize(size);
       setLayout(null);
     }

     public void paintComponent(Graphics g) {
       g.drawImage(img, 0, 0, null);
     }
     
     public String getImg() {
        return path2;
        }

   }

2  Game Development / Newbie & Debugging Questions / Re: get image of panel on: 2011-05-28 18:37:48
ok I will use that.  another question I want to save this string how do I do that?

1  
2  
3  
4  
5  
6  
7  
 public ImagePanel(String img) {
       this(new ImageIcon(img).getImage());
}
 public String getImg() {
        return img.toString();
        }    
     }


doesnt work I want the imageicon string i suppose? how do I go about doing that
3  Game Development / Newbie & Debugging Questions / get image of panel on: 2011-05-27 16:28:02
currently I have no way of getting the current image icon of a panel that is placed.

  Right now I am using getcomponent and figuring out its location to determine which image I used which isn't the best way any ideas?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
 for(lkm = 0; lkm < counter; lkm++)
                      {
                      ImagePanelList.get(lkm).addMouseListener(new MouseAdapter() {
                           @Override
                           public void mouseClicked(MouseEvent events) {
                              int letz;
                              char let;
                              String text;
                            text = events.getComponent().toString();
                            //gives me the panels location
                            System.out.println(text);
                            let = text.charAt(25);
                            //get first number of location
                            letz = Character.getNumericValue(let);
                            letz = letz - 1;
                            //minus one since my array list of images starts at 0
                              if(cardpicked[letz] == false && place[0] == -1)
                                {
                                   alPickedStringCardName.add(strCardName[letz]);
4  Game Development / Newbie & Debugging Questions / Re: timer on: 2011-05-10 04:39:16
I figured out that a client side timer( swing timer) is the best way to accomplish what I want as I can just terminate the game and take away points if the user doesnt move in a set of time and update mysql.  But I am running into another problem.

right now i have a column in mysql called startTime and endTime.  When I start a game I put a new timedate into startTime.

When a user wants to join a game I select all the games with endTime's of 0000000 or whatever my default is.  Then the user clicks the button and goes into the game.  The problem with this is that I can get games in which users created but then left- alt f4 etc..  Is their another way to do this without the need for a server?
5  Game Development / Newbie & Debugging Questions / timer on: 2011-05-08 22:54:59
I am writing an applet based game that uses some php for mysql read/writes w/ URLConnection.  I am trying to figure out what is the best way to implement a timer.

i.e. two players are playing against each other.  each one must make move in 2 minutes or points are rewarded to other player.
  can i just do the timer in the applet i.e. write to database user turn.  read if user has not posted new move give points to new player?

 or is their a better method?
6  Game Development / Newbie & Debugging Questions / Re: easier way to implement this code; on: 2011-03-28 23:29:19
edit^ I will try your way( i see how you are doing mouse events) but how would that implementation work for above if you don't mind?
7  Game Development / Newbie & Debugging Questions / Re: easier way to implement this code; on: 2011-03-28 23:28:10
I like your suggestion but I need to add events so panels work just as fast.  My problem when turning it into into an array is I can not add it or proper way to declare.
1  
2  
3  
4  
5  
6  
7  
8  
ImagePanel[] cards1[];

cards1[i] = new ImagePanel[10];

// not sure how to set
cards1[0] = new ImagePanel(new ImageIcon(getClass().getResource("name.jpg")).getImage());

add(cards1[0]);
8  Game Development / Newbie & Debugging Questions / Re: easier way to implement this code; on: 2011-03-28 23:16:08
could I create an array of class ImagePanel?  I know you can have an array of panel? how would that look?

panel1[1] = new ImagePanel(new ImageIcon(getClass().getResource("back.jpg")).getImage());  Huh?

heres the class for ImagePanel

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
class ImagePanel extends JPanel {

     private Image img;
     
     public ImagePanel(String img) {
       this(new ImageIcon(img).getImage());
     }
     public ImagePanel(Image img) {
       this.img = img;
     
       Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
       setPreferredSize(size);
       setMinimumSize(size);
       setMaximumSize(size);
       setSize(size);
       setLayout(null);
     }

     public void paintComponent(Graphics g) {
       g.drawImage(img, 0, 0, null);
     }

   }
9  Game Development / Newbie & Debugging Questions / Re: easier way to implement this code; on: 2011-03-27 23:57:01
I tried the above and it just just would not work : ( .  I ended up signing the applet and its working well now : )  maybe l8er down the road ill try to figure out what it doesnt like. ty guys!
10  Game Development / Newbie & Debugging Questions / Re: easier way to implement this code; on: 2011-03-27 17:57:07
I am sorry I am not understanding I think I need to change the image panel class also which I posted above.  The above code says can not convert from image panel to image.  or if I try it w/ an image icon it says can not convert from image icon to image.
11  Game Development / Newbie & Debugging Questions / Re: easier way to implement this code; on: 2011-03-27 05:03:25
tried the above code but it wasn't seeming to work wasn't liking the .getimage at the end wanted .getfile .   I am using image panel class for loading background panel imageswhich i got from the net.

ImagePanel cards = new ImagePanel(new ImageIcon("back.jpg").getImage()); 

breaks secruity rules for applet  i suppose so I am trying to get past that by loading from jar archive?
any other ideas

code of imagepanel class
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  
41  
42  
43  
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ImageTest {

  public static void main(String[] args) {
    ImagePanel panel = new ImagePanel(new ImageIcon("images/background.png").getImage());

    JFrame frame = new JFrame();
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
  }
}

class ImagePanel extends JPanel {

  private Image img;

  public ImagePanel(String img) {
    this(new ImageIcon(img).getImage());
  }

  public ImagePanel(Image img) {
    this.img = img;
    Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
    setPreferredSize(size);
    setMinimumSize(size);
    setMaximumSize(size);
    setSize(size);
    setLayout(null);
  }

  public void paintComponent(Graphics g) {
    g.drawImage(img, 0, 0, null);
  }

}
12  Game Development / Newbie & Debugging Questions / Re: easier way to implement this code; on: 2011-03-27 02:21:03
I also have another problem I am trying to load images w/ imagepanel class that loads images into a panel background and I am running into secruity errors.  I thought if the images where on the same domain as the applet they would load?

i.e.
ImagePanel cards = new ImagePanel(new ImageIcon("back.jpg").getImage()); 

how might I fix this for an applet?

aused by: java.security.AccessControlException: access denied (java.io.FilePermission back.jpg read)
   at java.security.AccessControlContext.checkPermission(Unknown Source)
   at java.security.AccessController.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkPermission(Unknown Source)
   at java.lang.SecurityManager.checkRead(Unknown Source)
   at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
   at sun.awt.SunToolkit.getImage(Unknown Source)
   at javax.swing.ImageIcon.<init>(Unknown Source)
   at javax.swing.ImageIcon.<init>(Unknown Source)
   at foursidecard.strauss.<init>(strauss.java:44)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at java.lang.Class.newInstance0(Unknown Source)
   at java.lang.Class.newInstance(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
   at java.awt.event.InvocationEvent.dispatch(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)
Exception: java.lang.reflect.InvocationTargetException
13  Game Development / Newbie & Debugging Questions / easier way to implement this code; on: 2011-03-26 18:36:38

Basically I want to display around 50 to 300 images that I will also be allowed to click on to do an event.  If I do it this way I have to have 300 imagepanels(which just load a bg image into a panel).  Can anyone think of a easier way to do this?
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  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
  int counter = 0;
                         while (rs.next ())
                         {
                             String idVal = rs.getString (1);
                             if(idVal.contentEquals("1") & tokens[6].contentEquals(Level))
                             {
                                System.out.println(tokens[7]);
                                if(counter == 0)
                                {
                                cards = new ImagePanel(new ImageIcon("tokens[7]" + ".jpg").getImage());
                                cards.setBounds(296, 38, 100, 127);
                                frame.getContentPane().add(cards);
                                cards.addMouseListener(new MouseAdapter() {
                                       @Override
                                       public void mouseClicked(MouseEvent arg0) {
                                          //click event data
                                         
                                       }
                                    });
                                counter++;
                                }
                                else if(counter ==1)
                                {
                                   cards1 = new ImagePanel(new ImageIcon("tokens[7]" + ".jpg").getImage());
                                    cards1.setBounds(396, 38, 100, 127);
                                    frame.getContentPane().add(cards1);
                                    cards1.addMouseListener(new MouseAdapter() {
                                         @Override
                                         public void mouseClicked(MouseEvent arg0) {
                                            //click event data
                                           
                                         }
                                      });
                                    counter++;
                                }
                                else if(counter == 2)
                                {
                                   cards2 = new ImagePanel(new ImageIcon("tokens[7]" + ".jpg").getImage());
                                    cards2.setBounds(496, 20, 100, 127);
                                    frame.getContentPane().add(cards2);
                                    cards2.addMouseListener(new MouseAdapter() {
                                           @Override
                                           public void mouseClicked(MouseEvent arg0) {
                                              //click event data
                                             
                                           }
                                        });
                                    counter++;
                                }
                               
                               
                               
                                frame.setVisible(true);

                             }
14  Game Development / Networking & Multiplayer / Re: Options? on: 2011-03-22 17:16:26
right now I am rewriting code to connect to http to run php code that gets moves through gets.  I will eventually want to encrypt that so thank you for the advise.
15  Game Development / Networking & Multiplayer / Re: Options? on: 2011-03-21 18:23:06
Lame but I know thats the answer hehe.
16  Game Development / Networking & Multiplayer / Re: Options? on: 2011-03-21 17:20:31
Well I was trying to think up a method in which I wouldn't need a server and somehow I could just use the mysql database.  I am almost done writing it but its not secure at all lol.
17  Game Development / Networking & Multiplayer / Re: Options? on: 2011-03-21 03:57:10
any way that that information could be hidden?  Or would it be easy to find out the password in the applet since its being sent out?
18  Game Development / Networking & Multiplayer / Re: Options? on: 2011-03-19 06:02:48
I think I need to use php for talking to the database as thats more secure?  Just unsure of how that would work. insted of doing client to client just have clients read from database and have clients send moves to database.  client waits to see if move has occured or something like that.   I know how to do this in straight java but it would be unsecure as someone could just decompile and find root pw or raw sql.
19  Game Development / Networking & Multiplayer / Re: Options? on: 2011-03-19 04:53:19
thats what I was afraid of.  I have a mysql database and php but not root its not a vpn so thats not an option ;s.  lol maybe I should of researched this before I wrote most of the game!   I was thinking of doing something like http://www.ttadvance.ca but w/ java in browser.  I guess I could make it like worms and have two play on one keyboard.  But that would require a friend /wrist lol j/k.
20  Game Development / Networking & Multiplayer / Options? on: 2011-03-19 02:48:39
What are my options if I want to keep my game as an applet but allow player vs player network play?
  The only problem I can think of is how I would obtain the IP's of the server and post them on the website for the client users to play versus?  I know I can use jdbc to write user scores and stuff to the sql database or at least I think so.
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.

rwatson462 (33 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (51 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (58 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!