🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / Java / tray icon avira gibi sağ alta küçültür

1-) Java - tray icon avira gibi sağ alta küçültür

/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */

package javaapplication6;

 

import java.awt.AWTException;

import java.awt.Image;

import java.awt.MenuItem;

import java.awt.PopupMenu;

import java.awt.SystemTray;

import java.awt.Toolkit;

import java.awt.TrayIcon;

import java.awt.Window;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.logging.Level;

import java.util.logging.Logger;

 

/**

 *

 * @author rambo

 */

public class NewJFrame extends javax.swing.JFrame {

 

    Window visibleWindows;

 

    public NewJFrame() throws AWTException {

 

        initComponents();

        visibleWindows = new Window(this);

 

        setTitle("RMOC OCR");

        setIconImage(Toolkit.getDefaultToolkit().getImage("rmos.jpg"));

        final TrayIcon trayIcon;

 

        if (SystemTray.isSupported()) {

 

            SystemTray tray = SystemTray.getSystemTray();

            Image image = Toolkit.getDefaultToolkit().getImage("rmos.jpg");

 

            MouseListener mouseListener = new MouseListener() {

 

                public void mouseClicked(MouseEvent me) {

                    if (me.getButton() == MouseEvent.BUTTON1) { // BUTTON1=LEFT CLİCK .... BUTTON2=MİDDLE CLİCK ....BUTTON3=RİGHT CLİCK...

                        System.out.println("Tray Icon - Mouse clicked!");

 

                        for (Window w : Window.getWindows()) {

                            if (w.getName().equals("frame0")) {

                                if (w.isShowing()) {

                                    //System.out.println("eklendi");

                                    w.setVisible(false);

                                } else {

                                    //System.out.println("silindi");

                                    w.setVisible(true);

                                }

                            }

                        }

                    }

                }

 

                public void mouseEntered(MouseEvent e) {

                    System.out.println("Tray Icon - Mouse entered!");

                }

 

                public void mouseExited(MouseEvent e) {

                    System.out.println("Tray Icon - Mouse exited!");

                }

 

                public void mousePressed(MouseEvent e) {

                    System.out.println("Tray Icon - Mouse pressed!");

                }

 

                public void mouseReleased(MouseEvent e) {

                    System.out.println("Tray Icon - Mouse released!");

                }

 

            };

 

            ActionListener exitListener = new ActionListener() {

                public void actionPerformed(ActionEvent e) {

                    System.out.println("Exiting...");

                    System.exit(0);

                }

            };

 

            PopupMenu popup = new PopupMenu();

            MenuItem defaultItem = new MenuItem("Kapat");

            defaultItem.addActionListener(exitListener);

            popup.add(defaultItem);

 

            trayIcon = new TrayIcon(image, "Tray Demo", popup);

 

            ActionListener actionListener = new ActionListener() {

                public void actionPerformed(ActionEvent e) {

                    //trayIcon.displayMessage("Action Event","An Action Event Has Been Peformed!", TrayIcon.MessageType.INFO);

                }

            };

 

            trayIcon.setImageAutoSize(true);

            trayIcon.addActionListener(actionListener);

            trayIcon.addMouseListener(mouseListener);

 

            //    Depending on which Mustang build you have, you may need to uncomment

            //    out the following code to check for an AWTException when you add

            //    an image to the system tray.

            //    try {

            tray.add(trayIcon);

            //    } catch (AWTException e) {

            //        System.err.println("TrayIcon could not be added.");

            //    }

            trayIcon.displayMessage("RMOS OCR", "RMOS OKUR", TrayIcon.MessageType.INFO);

        } else {

            System.err.println("System tray is currently not supported.");

        }

    }

 

    /**

     * Creates new form NewJFrame

     */

    /**

     * This method is called from within the constructor to initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is always

     * regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          

    private void initComponents() {

 

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 400, Short.MAX_VALUE)

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGap(0, 300, Short.MAX_VALUE)

        );

 

        pack();

    }// </editor-fold>                        

 

    /**

     * @param args the command line arguments

     */

    public static void main(String args[]) {

        /* Set the Nimbus look and feel */

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

         */

        try {

            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

                if ("Nimbus".equals(info.getName())) {

                    javax.swing.UIManager.setLookAndFeel(info.getClassName());

                    break;

                }

            }

        } catch (ClassNotFoundException ex) {

            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (InstantiationException ex) {

            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (IllegalAccessException ex) {

            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (javax.swing.UnsupportedLookAndFeelException ex) {

            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        }

        //</editor-fold>

 

        /* Create and display the form */

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                try {

                    new NewJFrame().setVisible(false);

                } catch (AWTException ex) {

                    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);

                }

            }

        });

    }

 

    // Variables declaration - do not modify                     

    // End of variables declaration                   

}

 2021 Ocak 18 Pazartesi
 475