回覆列表
  • 1 # 深夜最科技

    給您一個例子:

    import javax.swing.*;

    import java.awt.*;

    import java.awt.geom.*;

    public class paint

    {

    public static void main(String[] args)

    {

    CenteredFrame frame=new CenteredFrame();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setVisible(true);

    }

    }

    class CenteredFrame extends JFrame

    {

    private static final int WIDTH=400;

    private static final int HEIGHT=400;

    public CenteredFrame()

    {

    Toolkit kit=Toolkit.getDefaultToolkit();

    Dimension screenSize=kit.getScreenSize();

    int screenHeight = screenSize.height;

    int screenWidth = screenSize.width;

    int X = (screenWidth - WIDTH)/2;

    int Y = (screenHeight - HEIGHT)/2;

    setLocation(X, Y);

    setSize(WIDTH,HEIGHT);

    Container con=getContentPane();

    StringPanel panel=new StringPanel();

    con.add(panel);

    setResizable(true);

    }

    }

    class StringPanel extends JPanel

    {

    public void paintComponent(Graphics g)

    {

    Graphics2D g2=(Graphics2D)g;

    int x[]=new int[33];

    int y[]=new int[33];

    x[0]=0;

    y[0]=0;

    for(int i=1;i<=16;i++)

    {

    x[i]=184+i;

    y[i]=200-(17-i)*(17-i);

    x[i+16]=i+200;

    y[i+16]=200-i*i;

    }

    g.drawPolyline(x,y,33);

    Line2D L1 = new Line2D.Double(0,200,400,200);

    g2.draw(L1);

    Line2D L2=new Line2D.Double(200,40,200,400);

    g2.draw(L2);

    Line2D L3=new Line2D.Double(380,195,395,200);

    g2.draw(L3);

    Line2D L4=new Line2D.Double(380,205,395,200);

    g2.draw(L4);

    Line2D L5=new Line2D.Double(200,40,195,55);

    g2.draw(L5);

    Line2D L6=new Line2D.Double(200,40,205,55);

    g2.draw(L6);

    g.drawString("X",370,190);

    g.drawString("Y",205,40);

    }

    }

  • 中秋節和大豐收的關聯?
  • 建設銀行廣告詞是什麼?