用Java写一个在线金山词霸程序
代码贴上, 其它的就不多说了import java.awt.AWTEvent;import java.awt.AWTException;import java.awt.Color;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.event.AWTEventListener;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.InputStream;import java.net.URL;import java.util.Arrays;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.UIManager;import com.sun.awt.AWTUtilities;class RefBoolean {public boolean var = false;}class RefInt {public int var = 0;}public class DictFrame {public static void main(String[] args) {try {UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");}catch (Exception e) { System.out.println(e); }Toolkit tk = Toolkit.getDefaultToolkit();final RefBoolean canDrag = new RefBoolean();final RefBoolean isFirst = new RefBoolean();final RefInt oldX = new RefInt();final RefInt oldY = new RefInt();isFirst.var = true;final JFrame jf = new JFrame();final JDialog jdmean = new JDialog();final JTextField jtfWord = new JTextField("");final JTextArea jtamean = new JTextArea("");JScrollPane jScmean=new JScrollPane(jtamean);JPanel jp = new JPanel();Image image = tk.getImage("c:/ico.jpg"); //一张16*16的图片jf.setAlwaysOnTop(true);jf.setIconImage(image);jdmean.setBounds((int)(tk.getScreenSize().getWidth()-270), (int)(tk.getScreenSize().getHeight()-320)+60, 260, 200);jdmean.setUndecorated(true);jdmean.setAlwaysOnTop(true);jtamean.setLineWrap(true);jdmean.add(jScmean);jdmean.setVisible(true);AWTUtilities.setWindowOpacity(jf,0.9f);AWTUtilities.setWindowOpacity(jdmean,0.0f);jtfWord.setBounds(5, 10, 250, 21);jp.setLayout(null);jp.add(jtfWord);jp.setBackground(Color.GRAY);jf.setContentPane(jp);jf.setBounds((int)(tk.getScreenSize().getWidth()-270), (int)(tk.getScreenSize().getHeight()-320), 260, 50);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);jf.setUndecorated(true);jp.validate();jf.setVisible(true);try {if(SystemTray.isSupported()) {SystemTray st = SystemTray.getSystemTray();TrayIcon ti = new TrayIcon(image);ti.setToolTip("dict");PopupMenu popupMenu1 = new PopupMenu();MenuItem menuItem1 = new MenuItem();ti.setPopupMenu(popupMenu1);ti.addMouseListener(new MouseAdapter() {public void mouseClicked(MouseEvent e) {if (e.getClickCount() == 2) {jf.setVisible(true);}}});st.add(ti);popupMenu1.setLabel("dict");menuItem1.setLabel("退出");menuItem1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent evt) {System.exit(0);}});popupMenu1.add(menuItem1);}} catch (AWTException e) {e.printStackTrace();}jf.addWindowListener(new WindowAdapter() {public void windowIconified(WindowEvent evt) {}});tk.addAWTEventListener(new AWTEventListener() {@Overridepublic void eventDispatched(AWTEvent event) {if(((KeyEvent) event).getID() == KeyEvent.KEY_PRESSED) {if(((KeyEvent) event).getKeyCode()==KeyEvent.VK_F4) {System.exit(0);}else if( ((KeyEvent) event).getKeyCode()==KeyEvent.VK_ESCAPE) {jf.setVisible(false);if(AWTUtilities.getWindowOpacity(jdmean)>0.1d) {double[] ds = {0.69, 0.59, 0.49, 0.45, 0.39, 0.35, 0.29, 0.25, 0.19, 0.1, 0.05, 0.0};for(double d:ds) {_sleep(10);AWTUtilities.setWindowOpacity(jdmean,(float)d);}}} else if( ((KeyEvent) event).getKeyCode()==KeyEvent.VK_F1) {jf.setVisible(true);jtfWord.requestFocus();}}}}, AWTEvent.KEY_EVENT_MASK);jp.addMouseMotionListener(new MouseMotionListener() {@Overridepublic void mouseMoved(MouseEvent arg0) {}@Overridepublic void mouseDragged(MouseEvent arg0) {int x = arg0.getX() + jf.getX();int y = arg0.getY() + jf.getY();if(isFirst.var) {oldX.var = x;oldY.var = y;isFirst.var = false;}int detaX = x-oldX.var;int detaY = y-oldY.var;补充:软件开发 , Java ,
上一个:class版本问题导致-严重: Null component Catalina:type=JspMonitor,name=jsp,WebModule=//localhost/web
下一个:java中的浮点(float)运算
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- jsp+javaBean中Column 'ordersPrice' specified twice的错误
- Java TCP/IP Socket网络编程系列
- 大家来讨论一下我到底该用什么好?Swing 还是 JavaFX
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- spring 获取上下文问题
- SSH 导入导出excel 谁有这块的资料吗?
- Ext TreePanel 刷新问题
- springmvc 加载一个jsp页面执行多个方法 报404
- checkbox数组action怎么向页面传值