Jump to content

Black box not showing

Recommended Posts

I'm required to make a sorta candyland (they told me to call it ASCIILAND...Anyway it's like candyland and I need a black box to represent players. I have done this before but once I added GridBag it stopped showing...but I need that.

/*ACSIILAND Game BoardPretty sexy stuff here*/ //Importing crap to make this workimport javax.swing.*;import java.util.Random;import java.awt.*;import java.awt.geom.*;import java.awt.event.*;import java.awt.image.*;import java.io.*;import javax.imageio.*;//Start the public class, aka the main classpublic class ASCIILAND extends JComponent{   //Declare all variables that won't change   public static final String p1="John";   public static final String p2="Bobby";   public static final String p3="Joseph";      public static void main(String args[])   {	  //Declare all the constructors so that I can access crap off of it 	  Random generator=new Random();	  JFrame frame=new JFrame();		   	  int[] cells= new int[29];	  //Oh yea, now it loops to fill up all the variables	  //29 Variables total here	  for (int i=0; i < 29; i++)	  {		  cells[i] = i+1;	  }	  //Gotta manually declare these variables because they need seperate names D;	  int START;	  int END;	  final int roll=generator.nextInt(8)+1;	   	  //Set crap for frame	  frame.setSize(780, 550);	  frame.setTitle("ASCIILAND Game Board");	  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	  	  GridBagLayout gridbag = new GridBagLayout();	  GridBagConstraints c = new GridBagConstraints();		  	  frame.setLayout(gridbag);			  c.fill = GridBagConstraints.BOTH;	  c.gridx = 0;	  c.gridy = 0;			  JPanel board = new JPanel();	  board.setSize(550,650);	  board.setMinimumSize(new Dimension(550, 650));	  board.setPreferredSize(new Dimension(550, 650));		//Loading the image...		LoadImageApp image=new LoadImageApp();		//Loading the  game board...		board.add(image);				gridbag.setConstraints(board, c);		frame.add(board);		  		final JButton buttonPane = new JButton("Player 1 Roll");		//Inside the brackets it is the code to be executed		buttonPane.addActionListener(		new ActionListener()		{		  public void actionPerformed(ActionEvent e)			{				buttonPane.setEnabled(false);				buttonPane.setText("Player 1 rolled a "+roll+". Moving now...");		  }		});				//Jbutton crap.		JPanel buttonPane2 = new JPanel();	  buttonPane2.setSize(200, 200);	  buttonPane2.setMinimumSize(new Dimension(200, 200));	  buttonPane2.setPreferredSize(new Dimension(200, 200));	  buttonPane2.add(buttonPane);			  //INTENSE GRIDBAG STUFF!!!			  c.gridx=0;	  c.gridy=1;				  gridbag.setConstraints(buttonPane, c);	  frame.add(buttonPane2);	  //Make it so you can see the frame			  frame.setVisible(true);		}	public void paintComponent(Graphics g)		{			Graphics2D graphic = (Graphics2D) g;			graphic.setColor(Color.BLACK);			Rectangle2D.Double box = new Rectangle2D.Double(10, 10, 40, 40);			graphic.fill(box);		} 	public int boardMovement(int roll, Graphics g)	{		//This will do the board movement		return roll;	}}//Class to make the imageclass LoadImageApp extends Component{	BufferedImage img;	//"Draws" the image	public void paint(Graphics g)	{		g.drawImage(img, 0, 0, null);	}	//Loads the image with a try/catch	public LoadImageApp()	{	 	//Need a try/catch becuase ImageIO.read. It requires one to be caught/thrown...not baseball though;D.		try		{			img = ImageIO.read(new File("ASCIILAND.jpg"));		}		catch (IOException e)		{				  //Empty catch statement because quite frankly I need it to compile :/		}	}	 //Sets the dimensions of the image	 public Dimension getPreferredSize()	{		if (img == null)		{			return new Dimension(100,100);		}		else		{			return new Dimension(img.getWidth(null), img.getHeight(null));		}	}}

I'll attach the image to make it so you can compile. Any reason why it isn't showing?(Can't post an attachment...or a link it seems. Don't ban me!) Just google candyland picturehttp: //tbn0.google.com /images?q=tbn:Xf6IevmnnboJ::blog.makezine.com/candyland.jpgIt's that picture but photoshopped to say ASCIILAND.BTW DON'T TELL ME THE ANSWER. JUST GIVE ME A POINTER!!!This program is a bit extreme for only 2 months in but me and 2 other people in my class got moved up to AP AP computer science (before it was AP computer science) so I have to do harder ****.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...