Results 1 to 7 of 7
Thread: Creating a 3x3 matrix of imgs
- 11-16-2010, 01:15 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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
than i init the array by doing sooJava Code:static Image[] imgs;
than declare the base URL like sooJava Code:imgs = new Image[9];
than use a for loop for assignment if array like soJava Code:URL b_url = null; try { b_url = new URL("/home/user/pic/"); } catch (java.net.MalformedURLException ex){}
than i would have to think of a simple algorithm to correctly place the image parts in the "frame".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); }
i do realize that i have to override the paint().
soo like somthing like this
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: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; } }
(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
- 11-16-2010, 01:56 PM #2
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
- 11-17-2010, 03:44 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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:
- 11-17-2010, 04:44 PM #4
Senior Member
- Join Date
- Jul 2008
- Posts
- 125
- Rep Power
- 0
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.
- 11-17-2010, 07:05 PM #5
I already told you that.what is the easiest way to display a image with out the need of paint(Graphics g).
You don't. And you don't ever need to, as far as painting to a component is concerned.basicly how can i init a Graphics var in my own method.
If you're painting to a BufferedImage, read the API of that class for the correct method to obtain its Graphics reference.
db
- 11-24-2010, 11:36 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
im having a hard time getting a image to load. i look up help and all i get is errors
i tried this code:
than i get this from the compilerJava 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); } } }
why am i getting a error from ImageIO.read?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)
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.
-
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
-
help in matrix
By Engineer in forum New To JavaReplies: 7Last Post: 10-06-2010, 01:26 PM -
matrix multiply
By slixtrix in forum New To JavaReplies: 8Last Post: 09-13-2010, 06:50 AM -
Scalability of matrix
By ajay kumar in forum New To JavaReplies: 0Last Post: 12-04-2009, 05:19 AM -
[SOLVED] Help with Matrix
By Bernard Robitaille in forum JCreatorReplies: 10Last Post: 02-14-2009, 02:19 AM -
Help with matrix
By susan in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks