import javax.swing.JFrame;import javax.swing.JComponent;import java.awt.BorderLayout;import java.awt.Graphics;import java.awt.Font;import java.awt.Color;public class ShapeDemo {class GraphicPane extends JComponent {publicGraphicPane() {super();}@Overridepublic voidpaint(Graphics g) {//// line
g.setColor(Color.BLACK);// drawLine(int x1, int y1, int x2, int y2)
g.drawLine(0,0,100,100);//// ovals
g.setColor(newColor(250,100,120));// drawOval(int x, int y, int width, int height)
g.drawOval(30,30,100,200);// same, but it fills the oval with the current color
g.fillOval(300,30,100,200);//// Rectangle
g.setColor(Color.BLUE);// drawRect(int x, int y, int width, int height)
g.drawRect(30,300,100,200);// fillRect(int x, int y, int width, int height)
g.fillRect(300,300,100,200);}}publicShapeDemo() {
JFrame jf =newJFrame("Hello, World!");
GraphicPane gp =newGraphicPane();
jf.setBounds(0,0,800,600);
jf.setLayout(newBorderLayout());
jf.add(gp, BorderLayout.CENTER);// Remember, the method show() is deprecated
jf.setVisible(true);}public static voidmain(String[] args) {newShapeDemo();}}