Solved

Graphics/Images

Posted on 2004-04-14
8
213 Views
Last Modified: 2010-03-31
I'm new to game programming in java. I need to know how the basics...where to begin. How do I create an image object, load a picture, move it, etc.

For this, should I use a wrapper class? Graphics engine?
Suggestions on above would be appreciated.
0
Comment
Question by:starwarp2k2
  • 3
  • 3
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10827815
ImageIcon icon = new ImageIcon(filename);
0
 
LVL 4

Assisted Solution

by:john-at-7fff
john-at-7fff earned 25 total points
ID: 10827929
Your best bet is to search for tutorials on Swing (http://java.sun.com/docs/books/tutorial/uiswing/), or perhaps buy the book Swing by Robinson and Vorobiev.

In the meantime, here's some code that should get you started . . .

import java.awt.Image;
import java.awt.Insets;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ShowImage extends JFrame {

      private Image image = null;
      private Insets insets = null;
      
      public ShowImage(URL u) {
            super(u.toString());
            JLabel label = new JLabel(new ImageIcon(u));
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().add(label);
            pack();
            setVisible(true);
      }

      public static void main(String[] args) throws MalformedURLException, IOException {
            new ShowImage(new URL("http://us.news1.yimg.com/us.yimg.com/p/ap/20040414/thumb.pmm10704141855.bush_sharon_mideast_israel_pmm107.jpg"));
      }
}
0
 

Author Comment

by:starwarp2k2
ID: 10828179
I was leaning more towards full screen type games, not limited by java's frames, labels, etc.
I would appreciate it if you could help me there.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Expert Comment

by:objects
ID: 10828189
0
 

Author Comment

by:starwarp2k2
ID: 10828190
Hey objects, what is the import for ImageIcon
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 10828219
import javax.swing.ImageIcon;
0
 

Author Comment

by:starwarp2k2
ID: 11046098
Sorry, I didn't realize that I hadn't awarded points. Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 74
Java and GPO 11 66
eclipse java  build path 6 43
java stored proc example 9 19
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now