Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (683)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (751)
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  
  get image of panel  (Read 2309 times)
0 Members and 1 Guest are viewing this topic.
Offline civilwar

Senior Newbie





« Posted 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]);
Offline ra4king

JGO Kernel


Medals: 435
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-05-27 19:27:56 »

Did you know there is a Component.getBounds() method?

Offline civilwar

Senior Newbie





« Reply #2 - Posted 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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 435
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2011-05-28 19:06:33 »

You want the String to become an image?
The String parameter in ImageIcon specifies the path to the image in your file system. The toString() method is available to all classes because Object is the superclass of all classes. There are no guarantees on what is returned in the String. Each class can have its own implementation of it. ImageIcon's toString() returns the path to the image. Image's toString() returns its name plus its hashcode.

Try actually reading the Javadocs.

Offline civilwar

Senior Newbie





« Reply #4 - Posted 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;
        }

   }

Offline ra4king

JGO Kernel


Medals: 435
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2011-05-29 04:50:46 »

Haha you never actually assign img = image Wink
Try doing "this(image)" inside your first constructor.
Never mind, this(...) needs to be your first call.
do this:
1  
2  
3  
4  
public ImagePanel(String path) {
    this(new ImageIcon(path).getImage());
    path2 = path;
}

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
orrenravid (221 views)
2016-07-16 03:57:23

theagentd (291 views)
2016-07-11 14:28:54

Hydroque (379 views)
2016-07-06 05:56:57

Hydroque (530 views)
2016-07-03 08:52:54

GrandCastle (400 views)
2016-07-01 09:13:47

GrandCastle (393 views)
2016-07-01 09:09:45

CopyableCougar4 (446 views)
2016-06-25 16:56:52

Hydroque (421 views)
2016-06-22 02:17:53

SwampChicken (386 views)
2016-06-20 13:22:57

SwampChicken (306 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17
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!