Switch to full style
General Java code examples
Post a reply

Ellipse in Rectangle

Tue Nov 11, 2008 8:47 pm

drawing Ellipse in Rectangle using java graphics
Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;

public class 
DrawRectangleAndEllipse extends JApplet {
  final static 
BasicStroke stroke = new BasicStroke(2.0f);
  public 
void init() {
    
setBackground(Color.white);
    
setForeground(Color.white);
  }
  public 
void paint(Graphics g) {
    
Graphics2D g2 = (Graphics2Dg;
    
g2.setPaint(Color.red);
    
int x 6;
    
int y 8;
    
g2.setStroke(stroke);
    
g2.draw(new Rectangle2D.Double(xy150150));
  
g2.draw(new Ellipse2D.Double(xy150150));
    }
  public static 
void main(String args[]) {
    
JFrame frame = new JFrame("Draw Ellipse inside Rectangle");
    
JApplet applet = new DrawRectangleAndEllipse();
    
frame.getContentPane().add("Center"applet);
    
applet.init();
    
frame.setSize(250200);
    
frame.show();
  }



Attachments
rectEll.gif
drawing Ellipse in Rectangle
rectEll.gif (4.58 KiB) Viewed 6804 times

Post a reply
  Related Posts  to : Ellipse in Rectangle
 ellipse, circle, rectangle, square, or parallelogram     -  
 Draw Filled Ellipse in php     -  
 How to Calculate Volume of a Rectangle     -  
 Draw rectangle on image     -  
 Draw Fill Rectangle     -  
 Java Rectangle Class     -  
 Drawing rectangle using stars in java     -  
 Draw Oval,Arc,Polygon,string,Line,Round and 3D Rectangle     -  

Topic Tags

Java Graphics