answersLogoWhite

0

Java Swings has a lot of nice features and one of them is the ability to display images on its components. You can select any image that is available in the local system or somewhere on the internet and display it on Graphics objects. As of Java SE 1.4, reading an image is very simple.

If the image is stored in a local file:

String filename = "...";

Image image = ImageIO.read(new File(filename));

Otherwise, you can supply a URL:

String urlname = "...";

Image image = ImageIO.read(new URL(urlname));

The read method throws an IOException if the image is not available.

Now the variable image contains a reference to an object that encapsulates the image data. You can display the image with the drawImage method of the Graphics class.

public void paintComponent(Graphics g)

{

. . .

g.drawImage(image, x, y, null);

}

Sometimes, you may want to tile an image across a components canvas if it is much smaller than the component size. We can do the tiling in the paintComponent method. We first draw one copy of the image in the top-left corner and then use the copyArea call to copy it into the entire window using the code below:

for (int i = 0; i * imageWidth <= getWidth(); i++) for (int j = 0; j * imageHeight <= getHeight(); j++) if (i + j > 0)

g.copyArea(0, 0, imageWidth, imageHeight, i * imageWidth, j * imageHeight);

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What is the display device takes the electrical signals from the video card and forms an image using points of colored light on the screen?

java swings


How do you get a Java program to display a backslash in output without it interpreting it as a program command?

Follow the backslash with another backslash: System.out.println("\\ " \"); will display \ " \ on the screen.


What is the display device that takes the electrical signals from the video card and forms an image using points of colored light on the screen?

The display device is called a monitor or screen. It receives electrical signals from the video card and uses pixels to create an image composed of colored points of light on the screen, which together form the visual content that we see.


Write a program in java to display a string message using Servlets?

i dont no string for servlate


List out the version of java?

Running "java -version" will display the current version of Java.


Why net is need when have java?

Java (from Sun) is a programming language that is interpreted in bytecode using a virtual interface, it sounds complicated and it is more complicated than simply using HTML to display a page, and it is also much slower.


What is javadoc?

write a java program to display "Welcome Java" and list its execution steps.


How can you include images in a webpage using HTML and Java script?

You would not need JavaScript to include an image. &lt;img&gt; in HTML can do the work of including.


Are there any photo or image sharing websites which you can disable right clicking of your images?

No, this is a browser feature. Technically, it may be possibile to disable images by embedding them into another format -like java applets- or using java script to eliminate the menu (none of those solution are known to me in the real world).


What does animation mean in java?

It means moving images.


How do you display text with a label in java?

button.getLabel(); button.setLabel("label");


How do you stores images in an array using java?

File file=new File("c:\\Time.jpg"); PreparedStatement ps=connection.prepareStatement("insert into Table1 (image_id, image_data)...