Solved

Graphics/Images

Posted on 2004-04-14
8
220 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
even odd program using while loop 3 74
runtime exception 2 50
Java array 10 63
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

733 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