始终在顶部窗口即使在显示全屏Flash视频时仍保持在顶部

时间:2013-03-02 07:46:56

标签: java linux swing user-interface ubuntu

我正在尝试为Ubuntu 12.04编写一个简单的subtitle player application,即使在全屏播放Flash视频时也能保持最佳状态。此应用程序类似于Greenfish Subtitle Player,它在Windows中运行得非常好。

我的问题是我该怎么做?我正在尝试使用Java的代码段(下面列出,我从此link获得并修改为包含setAlwaysOnTop()),这使得JFrame保持在最佳状态,而不是在全屏制作Flash视频时。我的代码:

import java.awt.*; //Graphics2D, LinearGradientPaint, Point, Window, Window.Type;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

/**
 * From JavaMagazine May/June 2012
 * @author josh
 */
public class ShapedAboutWindowDemo {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //switch to the right thread
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new JFrame("About box");
                //turn of window decorations
                frame.setUndecorated(true);
                frame.setAlwaysOnTop(true);
                //turn off the background
                frame.setBackground(new Color(0,0,0,0));
                frame.setContentPane(new AboutComponent());
                frame.pack();
                //size the window
                frame.setSize(500, 200);
                frame.setVisible(true);
                //center on screen
                frame.setLocationRelativeTo(null);
            }
        }
        );
    }

    private static class AboutComponent extends JComponent {
        public void paintComponent(Graphics graphics) {
            Graphics2D g = (Graphics2D) graphics;

            //create a translucent gradient
            Color[] colors = new Color[]{
                           new Color(0,0,0,0)
                            ,new Color(0.3f,0.3f,0.3f,1f)
                            ,new Color(0.3f,0.3f,0.3f,1f)
                            ,new Color(0,0,0,0)};
            float[] stops = new float[]{0,0.2f,0.8f,1f};
            LinearGradientPaint paint = new LinearGradientPaint(
                                        new Point(0,0), new Point(500,0),
                                        stops,colors);
            //fill a rect then paint with text
            g.setPaint(paint);
            g.fillRect(0, 0, 500, 200);
            g.setPaint(Color.WHITE);
            g.drawString("My Killer App", 200, 100);
        }
    }
}

请告诉我这是否可以在Ubuntu / Linux中使用,如果可以,请告诉我如何。如果不能使用Java,我可以切换到任何其他语言。

0 个答案:

没有答案