簡體   English   中英

使用JLayer的GUI

[英]GUI using JLayer

我已經使用JLayer來裝飾GUI,背景顏色將每秒更改一次。 這是圖像。

在此處輸入圖片說明

在此圖像中,您可以看到計時器中出現了藍線和黃線。 我意識到出現這些行是因為文本在文本區域中發生了變化,當新的表達式顯示在文本區域中時,也會發生類似的情況。

如何刪除這些行?

class MyLayerUISubclass extends LayerUI<JComponent>{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public void paint(Graphics g, JComponent c){

        super.paint(g, c);

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

        int red = (int) (Math.random()*255);
        int green = (int) (Math.random()*255);
        int blue = (int) (Math.random()*255);

        Color startColor = new Color(red, green, blue);

        red = (int) (Math.random()*255);
        green = (int) (Math.random()*255);
        blue = (int) (Math.random()*255);

        Color endColor = new Color(red, green, blue);

        int w = c.getWidth();
        int h = c.getHeight();
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, .5f));
        g2.setPaint(new GradientPaint(0, 0, startColor, 0, h, endColor));
        g2.fillRect(0, 0, w, h);

        g2.dispose();

    }

 }

提前致謝!

我沒有使用JTextField,而是使用了垃圾桶建議的JLabel。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM