Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    SplashScreen của Java 6 không làm việc, luôn trả về null?

    Hi,

    Mình có đọc qua bài viết về sử dụng SplashScreen object của Java ở đây
    http://docs.oracle.com/javase/tutori...ashscreen.html

    Làm theo y như nó, thế mà khi chạy thì luôn luôn nhận được

    SplashScreen.getSplashScreen() returned null
    Mình trích lại code ở đây:


    Mã:
     public class SplashDemo extends Frame implements ActionListener {    static void renderSplashFrame(Graphics2D g, int frame) {        final String[] comps = {"foo", "bar", "baz"};        g.setComposite(AlphaComposite.Clear);        g.fillRect(120,140,200,40);        g.setPaintMode();        g.setColor(Color.BLACK);        g.drawString("Loading "+comps[(frame/5)%3]+"...", 120, 150);    }    public SplashDemo() {        super("SplashScreen demo");        setSize(300, 200);        setLayout(new BorderLayout());        Menu m1 = new Menu("File");        MenuItem mi1 = new MenuItem("Exit");        m1.add(mi1);        mi1.addActionListener(this);        this.addWindowListener(closeWindow);         MenuBar mb = new MenuBar();        setMenuBar(mb);        mb.add(m1);        final SplashScreen splash = SplashScreen.getSplashScreen();        if (splash == null) {            System.out.println("SplashScreen.getSplashScreen() returned null");            return;        }        Graphics2D g = splash.createGraphics();        if (g == null) {            System.out.println("g is null");            return;        }        for(int i=0; i<100; i++) {            renderSplashFrame(g, i);            splash.update();            try {                Thread.sleep(90);            }            catch(InterruptedException e) {            }        }        splash.close();        setVisible(true);        toFront();    }    public void actionPerformed(ActionEvent ae) {        System.exit(0);    }         private static WindowListener closeWindow = new WindowAdapter(){        public void windowClosing(WindowEvent e){            e.getWindow().dispose();        }    };         public static void main (String args[]) {        SplashDemo test = new SplashDemo();    }}
    Có bạn nào gặp phải trường hợp này chưa, giúp mình với.
    Đọc cái SplashScreen.getSplashScreen() thì thấy nó viết:

    ....
    This class cannot be instantiated. Only a single instance of this class can exist, and it may be obtained
    by using the getSplashScreen() static method. In case the splash screen has not been created at
    application startup via the command line or manifest file option, the getSplashScreen method returns
    null.

    Hay là do mình chạy từ mode debug của Eclipse nên mới bị nó nhở :-?

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Đây là bug, và link sau chứa cách sửa: _http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6372061

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •