Java Version Note paper Small item __java

Source: Internet
Author: User

1 supports the following functions:

1 exit

2 new multiple
3 Double click/Three click to implement hidden delete
4 support sticky paper Management--"view, delete
5 Support Drag


2 Effect Chart



3

Package com.wanju.tool.function;
Import java.awt.AWTException;
Import Java.awt.BorderLayout;
Import Java.awt.Color;
Import java.awt.Component;
Import java.awt.Dimension;
Import Java.awt.Font;
Import Java.awt.MenuItem;
Import Java.awt.Point;
Import Java.awt.PopupMenu;
Import Java.awt.Rectangle;
Import Java.awt.SystemTray;
Import Java.awt.Toolkit;
Import Java.awt.TrayIcon;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Java.awt.event.MouseAdapter;
Import java.awt.event.MouseEvent;
Import Java.net.URL;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

Import Java.util.Map.Entry;
Import Javax.swing.BorderFactory;
Import Javax.swing.ImageIcon;
Import Javax.swing.JDialog;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
Import Javax.swing.JTextArea;

Import javax.swing.SwingConstants; public class Convienttool extends JFrame {public static void main (String args[]) {Convienttool frame = new convientTool ();
		Frame.setvisible (TRUE);
			try {//Frame.addicontotray ();
		Frame.addcomplete (Frame.addicontotray ());
		catch (Awtexception e) {e.printstacktrace (); } public void Addcomplete (TrayIcon trayicon) {Systemtray Systemtray = Systemtray.getsystemtray ();//Get System Tray Object tr
		y {systemtray.add (TrayIcon);
		catch (Awtexception e) {//TODO auto-generated catch block E.printstacktrace ();		}//Add pallet pictures to the system tray} public Convienttool () {//Super ();//Settitle ("Use system tray");//SetBounds (100, 100, 500, 375);//
Setdefaultcloseoperation (Jframe.exit_on_close);
Final JLabel label = new JLabel ();
Label.setforeground (New Color (0, 128, 0));
Label.setfont (New Font ("", Font.Bold, 16));
Label.sethorizontalalignment (Swingconstants.center); Label.settext ("See the changes in the system tray.)
");
		
	Getcontentpane (). Add (label, Borderlayout.center);
	} list<component> lists = new arraylist<component> (); map<string, component> map = new Hashmap<striNg, component> ();

	private int dialogindex = 0;
	TrayIcon TrayIcon = null; Public TrayIcon Addicontotray () throws Awtexception {if (systemtray.issupported ()) {//Determine whether the system supports the system Tray function URL Resource = This.getclass (). GetResource ("01.jpg");//Get picture path ImageIcon icon = new ImageIcon (Resource);//Create Picture Object PopupMenu Popu Pmenu = new PopupMenu ()//Create pop-up Menu object MenuItem item = new MenuItem ("exit");//Create Exit menu item Object Item.addactionlistener (new Ac
			Tionlistener () {//Adds action listener public void actionperformed (ActionEvent e) {system.exit (0);//Exits system}} for the menu item;
			MenuItem item1 = new MenuItem ("New sticky paper");  Item1.addactionlistener (new ActionListener () {@Override public void actionperformed (ActionEvent e) {JDialog
					dialog = new JDialog ();
					JTextArea area = new JTextArea ();
					Area.setbackground (New Color (255, 255, 128));
					Area.setborder (Borderfactory.createlineborder (Color.yellow, 2));
					Area.settooltiptext ("Double click Hide, three click to delete this note paper"); JLabel label = new JlabeL ("");
					Dialog.add (label, Borderlayout.north);
					Dialog.add (area, borderlayout.center);
					Dialog.setsize (250, 300);
					Dialog.setundecorated (TRUE);
					Dialog.setresizable (TRUE);
					Dimension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();
					Dimension framesize = Dialog.getsize (); Dialog.setlocation (screensize.width-framesize.width)/1-100 + * Dialogindex, (screensize.height-f

					Ramesize.height)/2 + * dialogindex);
					Mouseadapter mouseadapter = new Windowdraglistener (dialog);
					Dialog.addmouselistener (Mouseadapter);
Dialog.addmousemotionlistener (Mouseadapter);
					Dialog.settitle ("" +dialogindex);
					Dialog.setvisible (TRUE);
					Lists.add (Dialog);
					Map.put ("" + dialogindex, Dialog);
				dialogindex++;
			}
			});
			MenuItem item2 = new MenuItem ("Hidden sticky paper");
			
			MenuItem item3 = new MenuItem ("Refresh"); Item2.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {for (int i = 0; i < lists.size (); i++) {(JDialog) lists.get (i)). setvisible (false);
			}
				}
			});
			PopupMenu Pagesmenu = new PopupMenu ("Manage sticky paper");
			AddPage (Pagesmenu);
			Popupmenu.add (item1);//Add the Exit menu item to the pop-up menu Popupmenu.add (Pagesmenu);
			Popupmenu.add (ITEM2);
			Popupmenu.add (ITEM3); Popupmenu.add (item)//Add the Exit menu item to the pop-up menu TrayIcon = new TrayIcon (Icon.getimage (), "Use System tray", popupmenu);//Create pallet picture  Object Item3.addactionlistener (New ActionListener () {@Override public void actionperformed (ActionEvent e)
							{Systemtray Systemtray = Systemtray.getsystemtray ()//Get system Tray Object try {systemtray.remove (TrayIcon);
						Addcomplete (Addicontotray ());
						catch (awtexception E2) {//TODO auto-generated catch block E2.printstacktrace ();
		}//Add the Tray picture to the system tray}});
	return TrayIcon;
		Class Windowdraglistener extends Mouseadapter {Private JDialog dialog; Private PoiNT Presspoint = new Point (); Public Windowdraglistener () {//TODO auto-generated constructor stub} public Windowdraglistener (JDialog Dialog)
		{this.dialog = Dialog;
		@Override public void mousepressed (MouseEvent e) {presspoint = E.getpoint ();
		@Override public void mousereleased (MouseEvent e) {presspoint = new point ();
			@Override public void mousedragged (MouseEvent e) {Rectangle r = dialog.getbounds ();
		Dialog.setlocation (r.x + (E.getx ()-presspoint.x), R.y + (E.gety ()-presspoint.y)); public void mouseclicked (MouseEvent evt) {if (evt.getclickcount () = = 3) {//Lists.remove (dialog);//Map
. Remove (Dialog.gettitle ());
				Dialog.dispose ();
			Handle mouse three hit} else if (Evt.getclickcount () = 2) {//Handle mouse double-click dialog.setvisible (false);
			}} public void AddPage (PopupMenu pagesmenu) {for (entry<string, component> entity:map.entrySet ()) {
	PopupMenu submenu = new PopupMenu (entity);		MenuItem item = new MenuItem (Entity.getkey () + "view");
			MenuItem item2 = new MenuItem (Entity.getkey () + "delete");
			Final String tempstring = Entity.getkey (); Item.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {if Map.get (tempstring
						instanceof jdialog) {jdialog dialog = (jdialog) map.get (tempstring);
					Dialog.setvisible (TRUE);
			}
				}
			}); Item2.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {if Map.get (Tempstrin
						g) instanceof JDialog) {jdialog dialog = (jdialog) map.get (tempstring);
						Lists.remove (Dialog);
					Dialog.dispose ();
				} map.remove (tempstring);
			}
			});
			Pagesmenu.add (item);
		Pagesmenu.add (ITEM2); }
	}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.