can't get anything to display on my JPanel
I'm writing this program to screw with my cousin, she's 15 and learning to drive and she drove a car her first time with me and was so excited and freaked out she was forgetting right and left. SO I'm writing this program to 'quiz' her on lefts and rights hehe.
Anyway, I laid everything out but no dice, nothing is showing up. I get the feeling I have a case of heavyweight vs. lightweight components on my hands, but if someone could point me toward the light I would be very grateful.
I'm pretty green when it comes to Swing so I've been coding a little at a time then compiling and getting it to display and moving on, so yea I do see that my buttons don't do anything ;) I'm just trying to see them first.
Code:
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class BG extends JPanel
{
Image image;
public BG()
{
try
{
image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("bgImage.jpg"), "bgImage.jpg"));
}
catch (Exception e) { /*handled in paintComponent()*/ }
}
protected void paintComponent(Graphics g)
{
if (image != null)
g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this);
}
public void prompt()
{
GridLayout gridlayout1 = new GridLayout( 4, 3, 5, 5 );
setLayout( gridlayout1 );
add( new JLabel( "" )); //1,1
JLabel intro = new JLabel( "Is it left or is it right?" );
intro.setToolTipText( "Quit screwing around." ); //1,2
intro.setHorizontalAlignment( SwingConstants.CENTER );
add( intro );
add( new JLabel( "" )); //1, 3
add( new JLabel( "" )); //2, 1
Icon arrowFace = new ImageIcon( getClass().getResource( "question.png" ) ); //2,2
JLabel arrow = new JLabel( arrowFace );
add( arrow );
add( new JLabel( "" )); //2,3
add( new JLabel( "" )); //3,1
JButton left = new JButton( "Left?" ); //3,2
add( left );
add( new JLabel( "" )); //3,3
add( new JLabel( "" )); //4,1
JButton right = new JButton( "Right?" ); //4,2
add( right );
Random genRandom = new Random();
int direction = genRandom.nextInt( 1 );
Icon arrowRight = new ImageIcon( "arrowRight.png" );
Icon arrowLeft = new ImageIcon( "arrowLeft.png" );
}
}
Code:
import javax.swing.*;
import java.awt.*;
public class main
{
public static void main( String args[] )
{
JFrame frame = new JFrame( "Left or Right??" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
BG backGround = new BG();
frame.add( backGround );
frame.setSize( 700, 700 );
frame.setVisible( true );
}
}