Results 1 to 1 of 1
- 05-26-2008, 01:17 PM #1
Member
- Join Date
- May 2008
- Posts
- 4
- Rep Power
- 0
New to Java, Creating screens with swings on Mac OS X
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?
Java Code: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
Similar Threads
-
Drawing charts using swings
By ravindarjobs in forum New To JavaReplies: 19Last Post: 07-21-2009, 11:03 PM -
creating image using java
By mmahesh_mca in forum New To JavaReplies: 1Last Post: 04-26-2008, 11:23 PM -
java swings
By emperoraj in forum AWT / SwingReplies: 0Last Post: 03-26-2008, 11:50 AM -
Creating a Downloader using JAVA
By shinojkk in forum New To JavaReplies: 0Last Post: 01-08-2008, 05:08 PM -
Creating Sub forms in java netbeans 5.0
By java_newbie in forum NetBeansReplies: 14Last Post: 08-06-2007, 07:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks