|
java help
im really stuck its a game i have to make nothing too hard if yu know what u are doin but im a lil stuck on a specific bit.
CODE
package mypackage6;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Panel;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Button;
import java.awt.BorderLayout;
public class puzzleapplet extends Applet
{
private Image[] imageArray; // the array of images
private int numImages; // number of images in the array
private int imageIndex; // holds the index of the image to be displayed
private Panel[] panelArray; // the array of panels
private int numPanels; // number of panles in the array
Panel boardPanel; // panel to hold the cells (i.e. the board)
private GridLayout gridLayout1;
public void init() {
try {
jbInit();
numImages = 6;
numPanels = 7;
imageIndex = 0;
loadImages();
} catch(Exception e) {
e.printStackTrace();
}
} // end init()
public puzzleapplet()
{
}
private void loadImages(){
imageArray = new Image[numImages];
for(int i = 0; i < numImages; i++) {
imageArray[i] = getImage(getCodeBase(), "images/" + "puzzle" + (i+1) + ".jpg");
}
} // end loadImages()
private void loadPanels(){
panelArray = new Panel[numPanels];
} // end loadImages()
public void paint(Graphics g) {
g.drawImage(imageArray[imageIndex], 0, 50, this);
g.drawImage(imageArray[imageIndex], 200, 50, this);
} // end paint()
public void start()
{
}
public void stop()
{
}
public void destroy()
{
}
private void jbInit() throws Exception {
boardPanel = new Panel(); // creates a new panel
gridLayout1 = new GridLayout(); // and an instance of GridLayout
gridLayout1.setColumns(7); // with 7 columns
this.setSize(new Dimension(534, 300));
boardPanel.setLayout(gridLayout1); // and set the layout of boardPanel to be GridLayout
this.add(boardPanel, BorderLayout.CENTER);
}
}
that is the code i have so far i want to be abel to put one of the images onto a panel but how?
|