Hi,
am totally new to the forum and Java itself. I bought a book to teach me how to write Java programs from beginning.. The book has a CD attached with it, everything seem to be working fine accept when I try to create classes that contain javax.swing.JPanel.. look at the code below I couldn't run this on Mac OS X.. is there something am missing or should I download some library files in order for this class to run?
import java.awt.Graphics;
import javax.swing.JPanel;
public class Shapes extends JPanel
{
private int choice; // user's choice of which shape to draw
// constructor sets the user's choice
public Shapes( int userChoice )
{
choice = userChoice;
} // end Shapes constructor
// draws a cascade of shapes starting from the top-left corner
public void paintComponent( Graphics g )
{
super.paintComponent( g );
for ( int i = 0; i < 10; i++ )
{
// pick the shape based on the user's choice
switch ( choice )
{
case 1: // draw rectangles
g.drawRect( 10 + i * 10, 10 + i * 10,
50 + i * 10, 50 + i * 10 );
break;
case 2: // draw ovals
g.drawOval( 10 + i * 10, 10 + i * 10,
50 + i * 10, 50 + i * 10 );
break;
} // end switch
} // end for
} // end method paintComponent
} // end class Shapes