Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Add Images to Panels

 
barron logan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i've been teaching myself java for the past few months and am currently working on a project. I'm experiencing trouble adding Images to Panels.
Can someone supply a working method(technique) to Adding Images to Panels?
Below is a portion of my code:

import java.awt.*;

public class Sample extends javax.swing.JApplet implements Runnable
{
Image[] picture = new Image[6];
int totalPictures = 0;
int current = 0;
Panel panel1 = new Panel();
Panel panel2 = new Panel();


public void init()
{
for (int i = 0; i<6; i++)
{
String imageText = null;
imageText = getParameter("image"+i);
if (imageText != null)
{
totalPictures++;
picture[i] = getImage
(getCodeBase(), imageText);
}
else
break;
}


GridLayout grid = new GridLayout
(1,2,10,10);

setLayout(grid);
/**how do you add the images to the
*panels???
*/

add(Panel1);
add(Panel2);



advTHANKSance
 
Joe Ess
Bartender
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Teaching yourself Java, eh? Then you probably know about the Java Tutorial, right? It covers the basics on most everything, including how to use Icons to do perform simple tasks with images and how to use the 2d Graphics API to manipulate and display graphics.
 
barron logan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx for the recomendations Joe Ess. Those are some pretty great tutorials...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic