编写Applet实现以下画面.完成后请运行以供考试检查.
由于无法贴图,就用口叙述:
一个正方形,里面有一个圆在中间,并且从圆的左边相切处有一条直线与正方形的上面相连接,
右边相切处有一条直线与正方形的下面相连接
大概就这样:*********************
*      *            *
*      *            *
*      *            *
*      * 圆 *       *
*           *       *
*           *       *
*           *       *
*********************

解决方案 »

  1.   

    import java.awt.*;public class Test extends Panel
    {
         public static void main(String []args)
         {
              Frame f=new Frame("Test");
              Test t=new Test();
              f.add("Center",t);
              f.setSize(500,500);
              f.setVisible(true);
         }
         
         public void paint(Graphics g)
         {
              g.drawOval();   
              g.drawRect();
              g.drawLine();
              g.drawLine();
         }所有绘图方法的参数坐标,自己写就OK了~
    }
      

  2.   

    顺便给你函数参考:
    drawOval(int x, int y, int width, int height) 
              Draws the outline of an oval.
    drawRect(int x, int y, int width, int height) 
              Draws the outline of the specified rectangle.
    drawLine(int x1, int y1, int x2, int y2) 
              Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
      

  3.   

    算坐标可把我算坏了
    源代码如下,测试成功:
    import java.awt.*;public class Test
    {
    public static void main(String []args)
         {
              Frame f=new Frame("Test");
              TestPanel t = new TestPanel(100,100,50,"Icon Demo",3.0F,Color.BLUE);
              f.add("Center",t);
              f.setSize(500,500);
              f.setVisible(true);
         }
    }class TestPanel extends Panel
    {
         private String title;
         private float stroke;
         private Color color;
         private int x,y,r;     
         public TestPanel(int x,int y,int r,String title,float stroke,Color color)
         {
          this.title = title;
          this.stroke = stroke;
          this.color = color;
             this.x = x;
             this.y = y;
             this.r = r;
         }
         
         public void paint(Graphics g)
         {
              Graphics2D g2 = (Graphics2D)g;
              
              g2.drawString(title,x+r,y-r/2);
              
              g2.setStroke(new BasicStroke(stroke));
              
              g2.setColor(color);
              
              g2.drawRect(x,y,x+r,y+r);
              
              g2.drawOval(x+r/2,y+r/2,2*r,2*r);   
                      
              g2.drawLine(x+r/2,y+r/2,x+r/2,y+r/2+r+10);
              
              g2.drawLine(x+r/2+2*r,y+r/2+2*r,x+r/2+2*r,y+r/2+2*r-r-10);
         }
    }