Hello everybody,
While I am doing the program( pasted below ), I am able to see the frame but not the rectangles. Can anyone please help me to get it done.
Thanks in advance.
KiranJyothi
import java.awt.Graphi cs;
import java.awt.Graphi cs2D;
import java.awt.Rectan gle;
import javax.swing.JPa nel;
import javax.swing.JCo mponent;
public class Rectangle1 extends JComponent
{
public void painComponent( Graphics g )
{
Graphics2D g2 = ( Graphics2D ) g;
Rectangle box = new Rectangle( 5, 10, 20, 30 );
g2.draw( box );
box.translate( 15, 25 );
g2.draw( box );
}
}
/* Driver Class */
import javax.swing.JFr ame;
public class RectangleViewer
{
public static void main( String args[] )
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 700;
frame.setSize( FRAME_WIDTH,FRA ME_HEIGHT );
frame.setTitle( "MyRectangl es. ");
frame.setDefaul tCloseOperation ( JFrame.EXIT_ON_ CLOSE );
Rectangle1 component = new Rectangle1();
frame.add( component );
frame.setVisibl e( true );
}
}
While I am doing the program( pasted below ), I am able to see the frame but not the rectangles. Can anyone please help me to get it done.
Thanks in advance.
KiranJyothi
import java.awt.Graphi cs;
import java.awt.Graphi cs2D;
import java.awt.Rectan gle;
import javax.swing.JPa nel;
import javax.swing.JCo mponent;
public class Rectangle1 extends JComponent
{
public void painComponent( Graphics g )
{
Graphics2D g2 = ( Graphics2D ) g;
Rectangle box = new Rectangle( 5, 10, 20, 30 );
g2.draw( box );
box.translate( 15, 25 );
g2.draw( box );
}
}
/* Driver Class */
import javax.swing.JFr ame;
public class RectangleViewer
{
public static void main( String args[] )
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 300;
final int FRAME_HEIGHT = 700;
frame.setSize( FRAME_WIDTH,FRA ME_HEIGHT );
frame.setTitle( "MyRectangl es. ");
frame.setDefaul tCloseOperation ( JFrame.EXIT_ON_ CLOSE );
Rectangle1 component = new Rectangle1();
frame.add( component );
frame.setVisibl e( true );
}
}
Comment