Results 1 to 7 of 7
  1. #1
    Zarcorp is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default Creating a 3x3 matrix of imgs

    this is alot easier in objective-c language. but Java class and method throw me off track a bit or it might be the syntax. im not sure.

    so i create a array of images like soo
    Java Code:
    static Image[] imgs;
    than i init the array by doing soo
    Java Code:
    imgs = new Image[9];
    than declare the base URL like soo
    Java Code:
    URL b_url = null;
    try {
    b_url = new URL("/home/user/pic/");
    }
    catch (java.net.MalformedURLException ex){}
    than use a for loop for assignment if array like so
    Java Code:
    int part;
    
    for(int i = 0; i<=9; i++){
    part = i;
    String f_name = "pic_"+part+".jpg";
    imgs[i] = getImage(b_url, f_name);
    }
    than i would have to think of a simple algorithm to correctly place the image parts in the "frame".

    i do realize that i have to override the paint().
    soo like somthing like this
    Java Code:
    public void paint(Graphics g){
     int x = 0;
     int y = 0;
    
     for(int i =0; i <=9; i++){
      g.drawImage(imgs[i], x, y, null);
      x = x +100;
      y = y+ 100;
     }
    }
    now i have a theorized concept of how i can make this work but i have a hard time getting out of my mind and transmitting it to the dam keyboard to the computer. may some please fill my blanks.:confused:

    (i wish their wasn't so many classes for one objective)
    NSImage = every thing about images (obj-c)
    Image, BufferedImage, ImageIO, and more (java)
    Last edited by Zarcorp; 11-16-2010 at 01:22 PM. Reason: image sizes are 100px sqaure

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Construct ImageIcons from the images, set them to an array of JLabels and add them to a container that has a GridLayout(3, 3)

    db

  3. #3
    Zarcorp is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    i mostly need help with getting the image to show in a frame. but the image is going to be split up more than 9 parts. im just keeping it to small scale so it easier to fix mistake. i want hard-code the coordinates.

    this is what my applet is going to do in steps;

    #1: Select Image Name;
    #2: Initialize Selected Image;
    #3: Display Image Parts in respected coordinates;

    IF mouse point is on part of (full)image than show popup menu;
    each part of the full image will have it own respected popup if assigned one;

    so like:
    assign popup to image part in (x,y) if no popup assign than proceed else output error || (x+1, y+1);

    java is a new langaue for me.. soo the class that java uses is very new to me. im more use to doing C coding and i dont want to rely on java class to do my drawing.

    what is the easiest way to display a image with out the need of paint(Graphics g). i would like to override the paint method inside a method of my own is their any way of doing this or will i have to override the pain() in my class as a separate method

    basicly how can i init a Graphics var in my own method.

    the image will be scalable and will have its own custom bounds. it would trapped in a frame/canvas bound but it should be scrollable by using a drag from mouse. any help with my project?

    hidden labels could become of use for logging purposes but i wouldn't want them to be viewable to the public.

    maybe im asking to much.:confused:

  4. #4
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default

    You have presented a lot of details,
    which is ok. This gives the impression
    that, at least, this project is not a
    homework assignment.

    People may have difficulty volunteering
    any specific help because you haven't
    presented "The problem" you are having.

    For example:
    The only help I think I can provide is
    that you should develope a small
    working project without the image
    rendering section.

    Present this code on the forum to show
    the readers where you are having
    difficulty coding.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    what is the easiest way to display a image with out the need of paint(Graphics g).
    I already told you that.
    basicly how can i init a Graphics var in my own method.
    You don't. And you don't ever need to, as far as painting to a component is concerned.

    If you're painting to a BufferedImage, read the API of that class for the correct method to obtain its Graphics reference.

    db

  6. #6
    Zarcorp is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    im having a hard time getting a image to load. i look up help and all i get is errors

    i tried this code:
    Java Code:
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    
    /**
     *
     * @author zar
     */
    public class loadImage_ {
    
    
        private void load(JFrame inFrame) throws IOException{
            URL url = this.getClass().getResource("Image.jpg");
            BufferedImage img = ImageIO.read(url);
            inFrame.setBounds(0,0,img.getWidth(), img.getHeight());
            inFrame.setVisible(true);
    
            Graphics2D g = (Graphics2D)inFrame.getRootPane().getGraphics();
            g.drawImage(img, null, 0, 0);
        }
    
        public static void img(){
            loadImage_ li = new loadImage_();
            JFrame frame = new JFrame("Image Display");
            try {
                li.load(frame);
            } catch (IOException ex) {
                Logger.getLogger(loadImage_.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
    }
    than i get this from the compiler

    run:
    Exception in thread "main" java.lang.IllegalArgumentException: input == null!
    at javax.imageio.ImageIO.read(ImageIO.java:1362)
    at imagespilt.loadImage_.load(loadImage_.java:28)
    at imagespilt.loadImage_.img(loadImage_.java:40)
    at imagespilt.init_.main(init_.java:18)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)
    why am i getting a error from ImageIO.read?

    i have the method img() executed from the main() that is in init_()

    so like loadImage_.img() in init_.main()

    how do i just load a image? just loading it is what im stuck on. and wh is it not finding the image correctly?
    Last edited by Zarcorp; 11-24-2010 at 11:39 PM.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There's so much wrong with that code, that I don't think it's worth dissecting. Also, I'm reluctant to give you specific advice when you're ignoring all of Darryl's sound advice without telling us why. I recommend that you dump your current code and do what you should have done all along -- read the graphics tutorials at the Oracle tutorial site. It will show you that Darryl's recommendations are the correct ones.
    Last edited by Fubarable; 11-25-2010 at 01:38 AM.

Similar Threads

  1. help in matrix
    By Engineer in forum New To Java
    Replies: 7
    Last Post: 10-06-2010, 01:26 PM
  2. matrix multiply
    By slixtrix in forum New To Java
    Replies: 8
    Last Post: 09-13-2010, 06:50 AM
  3. Scalability of matrix
    By ajay kumar in forum New To Java
    Replies: 0
    Last Post: 12-04-2009, 05:19 AM
  4. [SOLVED] Help with Matrix
    By Bernard Robitaille in forum JCreator
    Replies: 10
    Last Post: 02-14-2009, 02:19 AM
  5. Help with matrix
    By susan in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •