0

每当我将鼠标悬停在菜单项上时,我都会在图像中看到一个奇怪的黑色空间,我不知道为什么。当我使用系统的外观和感觉时,我没有这个问题,所以我认为这是因为物质的外观和感觉。

public final class MainFrame extends JFrame {

public MainFrame(final Loader loader) {
    super(Configuration.CLIENT_NAME + " v" + Configuration.getVersion());
    try {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = kit.createImage(new URL(Configuration.Paths.Resources.ICON));
        setIconImage(img);
    } catch (Exception e) {
    }

    final Container c = getContentPane();
    c.setLayout(new GridBagLayout());
    ((GridBagLayout) c.getLayout()).columnWeights = new double[]{1.0, 0.0};
    ((GridBagLayout) c.getLayout()).rowWeights = new double[]{1.0};
    c.setBackground(Color.BLACK);

    final AppletPanel appletPanel = new AppletPanel(loader);
    appletPanel.reload();
    c.add(appletPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
            GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

    final JMenuBar menu = new JMenuBar();
    menu.add(new FileMenu());
    menu.add(new ViewMenu());
    menu.add(new UtilitiesMenu());
    menu.add(new PluginsMenu());
    menu.add(new LinksMenu());
    menu.add(new ScreenshotMenu());
    menu.add(new HelpMenu());
    setJMenuBar(menu);

    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(final WindowEvent e) {
            validate();
        }
    });

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    pack();
    setLocationRelativeTo(null);
    setVisible(true);
}

public final class AppletPanel extends JPanel {

    enum State {
        SPLASH,
        CONFIG,
        DOWNLOAD,
        IDENTIFY,
        INITIALIZE,
        ERROR,
        OSR
    }

    private static final ExecutorService pool = Executors.newFixedThreadPool(1);
    private State state = State.SPLASH;
    private volatile String error;
    private volatile Applet applet = null;
    private volatile Loader loader;

    public AppletPanel(final Loader loader) {
        super(new BorderLayout());
        this.loader = loader;
        this.setBackground(Color.BLACK);
        this.setMaximumSize(new Dimension(765, 503));
        this.setPreferredSize(new Dimension(765, 503));
        this.setSize(765, 503);
        revalidate();
    }

    public void reload() {
        synchronized (this) {
            if (state == State.CONFIG || state == State.DOWNLOAD || state == State.IDENTIFY) return;
            state = State.CONFIG;
        }
        if (applet != null) {
            remove(applet);
            applet.destroy();
            System.gc();
            applet = null;
            error = null;
        }
        pool.submit(new Runnable() {
            public void run() {
                state = State.DOWNLOAD;
                loader.load();
                state = State.INITIALIZE;
                try {
                    applet = loader.createApplet();
                } catch (Exception e) {
                    error(e.toString());
                    return;
                }
                applet.setStub(loader.getCrawler());
                applet.init();
                applet.start();
                add(applet, BorderLayout.CENTER);
                state = State.OSR;
                revalidate();
            }
        });
        new Thread(new Runnable() {
            public void run() {
                while (state != State.OSR && state != State.ERROR) {
                    repaint();
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException ex) {
                        break;
                    }
                }
                repaint();
            }
        }).start();
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        switch (state) {
            case CONFIG: {
                String message = "Loading configuration...";
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 25);
                break;
            }
            case DOWNLOAD: {
                String message = "Processing... " + loader.current();
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 175);
                g.setColor(Color.RED);
                g.drawRoundRect(getWidth() / 2 - 100, 200, 200, 50, 10, 10);
                g.fillRoundRect(getWidth() / 2 - 100, 200, (int) (loader.downloaded() * 200), 50, 10, 10);
                g.setColor(new Color(255, 255, 255, 50));
                g.fillRoundRect(getWidth() / 2 - 100, 200, 200, 35, 10, 10);
                break;
            }
            case IDENTIFY: {
                String message = "Identifying classes...";
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 25);
                g.setColor(Color.RED);
                break;
            }
            case INITIALIZE: {
                String message = "Initializing...";
                FontMetrics fm = g.getFontMetrics();
                g.setColor(Color.RED);
                g.drawString(message, getWidth() / 2 - fm.stringWidth(message) / 2, 25);
                break;
            }
            case ERROR: {
                FontMetrics fm = g.getFontMetrics();
                g.drawString(error, getWidth() / 2 - fm.stringWidth(error) / 2, 50);
                break;
            }
        }
    }

    private synchronized void error(String message) {
        state = State.ERROR;
        this.error = message;
    }

    public void setSize(final Dimension dimension) {
        super.setSize(dimension);
        if (applet != null) {
            applet.setSize(dimension);
        }
    }
}

    public void setPreferredSize(final Dimension dimension) {
        super.setPreferredSize(dimension);
        if (applet != null) {
            applet.setPreferredSize(dimension); 
        }
    }
}
4

2 回答 2

0

在脚本中的任何位置使用此代码:

System.setProperty("jgoodies.popupDropShadowEnabled", "false");

或更准确地说:

UIManager.put("jgoodies.popupDropShadowEnabled", "false");
于 2015-06-25T15:33:35.760 回答
-1

我认为删除“c.setBackground(Color.BLACK);” 以及所有其他 JFrame 修改以更改背景颜色,将通过使背景透明来解决此问题。好像黑色区域是您在顶部的 JFrame 菜单的一部分,看起来,我只从个人经验中知道,通过将未使用的区域更改为透明或空,它将删除它。这似乎是您的问题,对吗?试一试,然后让我知道我是否有帮助。

于 2013-11-10T20:10:02.260 回答