Author Topic: Java GUI help needed  (Read 409 times)

So I am attempting to make a program that needs to be able to display an arbitrary number of images at specific pixel locations.

So far I have discovered that using templates are completely useless for anything involving specific locations, but I can't seem to render multiple images on a single panel without using them, so I am at an impasse between the two requirements.

Can someone point me to a good resource to use or some tips as to what I should be doing to accomplish what I want?

For reference, this is what I am using to load an image:

Code: [Select]
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

public class Btn_Graphic extends JPanel
{
    private BufferedImage image;
    private int xpos, ypos;

    public Btn_Graphic(String path, int x, int y)
    {
        try
        {
            image = ImageIO.read(new File(path));
        }
        catch(IOException ex)
        {
            // too darn bad
        }
        this.xpos = x;
        this.ypos = y;
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        g.drawImage(image, this.xpos, this.ypos, null);
    }
}

Thanks in advance for the help.
« Last Edit: January 14, 2013, 10:38:08 PM by Nexus »

Alright I figured out how to do what I was trying to do.  I needed to make the images JComponents instead of JPanels and then make the panel that I am putting them onto a null layout.  Then I can use the JComponent.setBounds(x, y, width, height); to position it where I need it.

I'll lock this shortly unless someone else has additional comments