0

我和我的朋友整个下午都在对这个程序进行故障排除。我可以在我的mac上编译这个很好。但是,他无法在他的 Windows 7 机器上编译它。我们都在运行 Netbeans。有人可以指出可能导致他这个错误的原因。它不喜欢 setBackgroundColor 的声明。

显示的错误如下....

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
    at java.awt.Frame.setBackground(Frame.java:986)
    at FadeOut.<init>(FadeOut.java:24)
    at FadeOut$2.run(FadeOut.java:70)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

代码

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Paint;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class FadeOut extends javax.swing.JFrame
{
    public javax.swing.JPanel panel1;

 public FadeOut() 
{

        super("FadeOut");
        setBackground(new Color(0,0,0,0));//////////////Compiler doesn't like me
        setSize(new Dimension(800,800));
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel()
        {
            @Override
            protected void paintComponent(Graphics g)
            {
                if (g instanceof Graphics2D)
                {
                    final int R = 100;
                    final int G = 100;
                    final int B = 100;
                    Paint p = new GradientPaint(0.f,0.f,new Color(R, G, B, 0),0.f, getHeight(), new Color(R, G, B, 0), true);
                    Graphics2D g2d = (Graphics2D)g;
                    g2d.setPaint(p);
                    g2d.fillRect(0,0,getWidth(),getHeight());
                }//END GRAPHICS2D
            }//END PAINTCOMPONENT
        };//END FRAME & PANEL TRANSLUCENT DEFINITION
        setContentPane(panel);
        init();
    }//END FadeOut CONSTRUCTOR

 public void init()
 {
     setLayout(new GridLayout(1,1));
     Border blueLine;
     blueLine = BorderFactory.createLineBorder(Color.decode("0xFF00FF"));

     panel1 = new JPanel(new GridLayout(1,1));
     panel1.setBorder(BorderFactory.createTitledBorder(blueLine,"I'm translucent bitches!!", TitledBorder.CENTER,2,null,Color.decode("0x007FF")));
     add(panel1);
 }




  public static void main(String args[])
    {
         SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                FadeOut gtw = new
                    FadeOut();
                // Display the window.
                gtw.setVisible(true);
            }//END RUN
        });//SWINGUTILITIES.INVOKELATER  
    }//END MAIN

}//END FadeOut
4

1 回答 1

2

Dont forget when you get a weird exception that you cant diagnose ALWAYS look for it on the internet chances are very likely other people have had the same problem.

I searched for "java.awt.IllegalComponentStateException: The frame is decorated" and found Is The Java Tutorials Translucent Window example giving trouble to those playing with jdk7?

于 2013-08-26T01:06:08.247 回答