Olá pessoal, eu to com uma dúvida bem básica, como coloco uma imagem no netbeans? Só pra fazer o aplicativo achar uma imagem?
package tests;
import javax.swing.*;
import java.awt.*;
public class MapPanel extends JPanel{
private Square[][] tiles;
public MapPanel( int x, int y ){
if ( x < 1 )
x = 1;
if ( y < 1 )
y = 1;
tiles = new Square[x][y];
for ( int xc = 0 ; xc < tiles.length ; xc++ ){
for ( int yc = 0 ; yc < tiles[xc].length ; yc++ ){
if ( xc == 0 && yc == 0 ){
tiles[0][0] = new Square( new Company(
new ImageIcon( "redsquare.gif" )));
continue;
}
tiles[xc][yc] = new Square();
}
}
}
public void painComponent( Graphics g ){
super.paintComponent( g );
for( int x = 0 ; x < tiles.length ; x++ ){
for ( int y = 0 ; y < tiles[x].length ; y++ ){
tiles[x][y].getIcon().paintIcon(this, g, x * 64, y * 64);
}
}
}
private class Square{
private Company x;
public Square( Company x ){
this.x = x;
}
public Square(){
this.x = null;
}
public ImageIcon getIcon(){
if ( x == null )
return new ImageIcon( "emptysquare.gif" );
return x.getIcon();
}
}
private class Company{
private ImageIcon icon;
public Company( ImageIcon icon ){
this.icon = icon;
}
public ImageIcon getIcon(){
return icon;
}
}
}
package tests;
import javax.swing.JFrame;
public class MapTest{
public static void main( String args[] ){
JFrame frame = new JFrame( "Map test" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
MapPanel panel = new MapPanel( 6, 6 );
frame.add( panel );
frame.setSize( 6 * 64, 6 * 64 );
frame.setVisible( true );
}
}
vlw a todos… só to em duvida onde colocar a imagem pro netbeans achar