如何恢复 BasicStroke class 中的默认笔划?

How to restore the default stroke in the BasicStroke class?

我有一个程序,我在其中定义了一堆新的破折号图案并使用 BasicStroke class 使它们成为笔画。比我用的 .setStroke() 方法并用我的破折号图案制作线条。现在我希望能够 setStroke() 回到默认的破折号模式(实线)。我该怎么做呢? 这是我的代码:

    float[] dash1 = {2f, 0f, 2f};
        float[] dash2 = {1f, 1f, 1f};
        float[] dash3 = {16f, 10f, 4f, 10f};
        float[] dash4 = {4f, 4f, 1f};

        Graphics2D g2d = (Graphics2D) g.create();
        g2d.drawLine(20, 40, 250, 40);

        BasicStroke bs1 = new BasicStroke(1, BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_ROUND, 1.0f, dash3, 0f);

        BasicStroke bs2 =new BasicStroke(1, BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_ROUND, 1.0f, dash3, 16f);

        BasicStroke bs3 = new BasicStroke(1, BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_ROUND, 1.0f, dash3, 2f);

        BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_ROUND, 1.0f, dash4, 2f);



        g2d.setStroke(bs1);
        g2d.drawLine(20, 80, 250, 80);

        g2d.setStroke(bs2);
        g2d.drawLine(20, 120, 250, 120);

        g2d.setStroke(bs3);
        g2d.drawLine(20, 160, 250, 160);

        g2d.setStroke(bs4);
        g2d.drawLine(20, 200, 250, 200);

你可以把它存储在一个变量中,然后像@StanislavL 说的那样访问它

    Stroke defaultStroke;

    Graphics2D g2d = (Graphics2D) g.create();

    defaultStroke = g2d.getStroke();
    //
    //do your thing
    //
    //reset by
    g2d.setStroke(defaultStroke);