Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

java - Functional discrepancy for SystemTray in Ubuntu

I have a java application, the Icon of which doesn't appear consistently in the notification area(Ubuntu) on startup.

                 As suggested by my mentor this has to be the issue of the jar I'm using. So I was asked to find a different jar (Which I Couldn't) and make corresponding changes in the code and most importantly to get rid of the imports involving dorkbox. 

Is there any other jars I could use at the place? And btw, this is the complete code of my program including the imports used:

import javax.swing.JCheckBoxMenuItem;
import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.Box;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import dorkbox.systemTray.MenuItem;
import dorkbox.systemTray.SystemTray;
import dorkbox.util.Desktop;

The following is the complete code of my program


public class Tray { 
    
    public static String email,admin,olduser;
    public static SystemTray systemTray;
    public static MenuItem on, of, op; 

    public static void main(String[] args) {
        
   systemTray=SystemTray.get(); 
   System.out.println("systemTray is "+systemTray);
   showTray();
    }
    
    public static void showTray()
    {
        if (systemTray==null)
        {           
            System.exit(0); 
        }
        else
        {
            System.out.println("SystemTray works"); 
        }
        //String[] args= {"",""};
          
        // ImageIcon icon = new ImageIcon("/home/ioss/Downloads/hexagon-clipart.jpeg");
        systemTray.setImage("/home/ioss/Downloads/c4f9.png"); 
        systemTray.setStatus("Running"); 
        

        // MenuItem user_email=new MenuItem(email);
        MenuItem chgImg=new MenuItem("Change Icon",new ActionListener()
                {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        // TODO Auto-generated method stub
                        
                        System.out.println("Inside ActionLisener"); 
                         JButton button1 = new JButton("One");
                         JButton button2 = new JButton("Two");
                          
                         
                          
//                        Icon icon = new ImageIcon("/home/ioss/Downloads/hexagon-clipart.jpeg");
//                        JButton button3 = new JButton(icon);
                          Box box = Box.createVerticalBox();
                          box.add(button1);
                          box.add(button2);
//                        box.add(button3);
                         
                        
                          JFrame frame = new JFrame();
                          frame.add(box);
                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                          frame.setLocationByPlatform(true);
                          frame.setSize(500, 300);
                          frame.setVisible(true);
                        
                    }
            
                });     
        MenuItem link =new MenuItem ("My Desklog"); 
            MenuItem version=new MenuItem("Version-1.0.4");
           
            systemTray.getMenu().add(link).setShortcut('q');
            systemTray.getMenu().add(version).setShortcut('q');
            
          
    
            systemTray.getMenu().add(chgImg).setShortcut('q');
        
        PopupMenu pm=new PopupMenu();   
        
        op=new MenuItem("About"); 
          systemTray.getMenu().add(op).setShortcut('q');
        
        on =new MenuItem("Go Online");
         systemTray.getMenu().add(on).setShortcut('q');
         on.setEnabled(false);
        
ActionListener online = new ActionListener() {

            
            @Override
            public void actionPerformed(ActionEvent arg0) { 
                System.out.println("Inside Online Listener"); 
                systemTray.setImage("/home/ioss/Downloads/c4f9.png"); 
                    
                    System.out.println("On enabled");
                    
                of.setEnabled(true);
                System.out.println("online..");
                systemTray.setStatus("online");                 
            }
            
        };
        
        of =new MenuItem("Go Offline");
        
        
        ActionListener offline = new ActionListener() {

            
            @Override
            public void actionPerformed(ActionEvent arg0) {
                
//              systemTray.setImage("/home/ioss/Downloads/prohibition-symbol.jpeg"); 
                on.setEnabled(true);
                of.setEnabled(false);
                System.out.println("offline..");
                systemTray.setStatus("offline"); 
                
            }
            
        };
          systemTray.getMenu().add(of).setShortcut('q');
        
        ActionListener myDesklog =new ActionListener()
                {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        
                        
                    
                        try {
                            System.out.println("Desklog Listener"); 
//                          Desktop.getDesktop().browse(new URI("https://app.desklog.io/user/home#"));
                            
                            String url_open ="http://javadl.sun.com/webapps/download/AutoDL?BundleId=76860";
//                          java.awt.Desktop.getDesktop().browse(java.net.URI.create(url_open));
                            
                            java.awt.Desktop.getDesktop().browse(new URI("https://app.desklog.io/user/home#"));
                            
                            
                        } catch (IOException e) {
                            
                            e.printStackTrace();
                        } catch (URISyntaxException e) {
                            
                            e.printStackTrace();
                        }
                        
                    }
            
                };
                //LOGOUT 
        MenuItem logout =new MenuItem("Logout");
        
          ActionListener logout1 =new ActionListener()
            {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    System.exit(0);
                    
                }
        
            }; 
        
                
        
        
        ///////////////Change Icon
        
ActionListener changeIcon = new ActionListener() {


            @Override
            public void actionPerformed(ActionEvent arg0) {
                
                System.out.println("Inside ActionLisener"); 
                 JButton button1 = new JButton("One");
                 JButton button2 = new JButton("Two");
                  
                 
    /hexagon-clipart.jpeg");

                  Box box = Box.createVerticalBox();
                  box.add(button1);
                  box.add(button2);
                
                  JFrame frame = new JFrame();
                  frame.add(box);
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setLocationByPlatform(true);
                  frame.setSize(500, 300);
                  frame.setVisible(true);
                }};}}

If possible pls suggest what library to use to fix this error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...