2014-03-04 42 views
0

我試圖讓點擊'右鍵'點擊貝寶徽標出現。不幸的是,所有顯示的是咖啡和一支筆的默認Java標誌。ImageIcon +關閉點擊一個JOptionPane

另外,如何讓它一旦你點擊「確定」或「取消」它關閉JOptionPane,當前,當你點擊「確定」沒有任何反應時,它會一直給你「確​​定」/「取消」選項。

rightbutton = new JButton("Right."); 
    add(rightbutton); 
    rightbutton.addActionListener(
      new ActionListener(){ 
       public void actionPerformed(ActionEvent event){ 
        //what do we want to happen when we 
        //click the button 
        final ImageIcon icon = new ImageIcon("C:\\Users\\Scr3am\\Desktop\\paypal.jpg"); 
        JOptionPane.showOptionDialog(null, "Congratulations, you clicked the button.", "Congrats", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { panel }, icon); 

謝謝!

回答

0

我看到你試圖使用一個JFrame更有用的JOptionPane。

JOptionPane被簡單地用作信息或錯誤消息,其中作爲JFrame用於其他任何事情。

解決方案:

製作一個JFrame,添加一個JLabel到它,並設置爲與JLabel.setImage( 「目錄」)的圖像;

然後添加兩個按鈕,確定和取消。

我會建議netbeans JFrame表單編輯器。

如果您還不熟悉java,請嘗試下載一些示例並從中學習並嘗試獲取關於java編程的書籍。

祝你好運。