知识大全 用Java写一个在线金山词霸程序

Posted 词义

篇首语:智者不为愚者谋,勇者不为怯者死。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 用Java写一个在线金山词霸程序相关的知识,希望对你有一定的参考价值。

用Java写一个在线金山词霸程序  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  代码贴上 其它的就不多说了

  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 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 sun awt AWTUtilities;

  class RefBoolean public boolean var = false;

  class RefInt public int var = ;

  public class DictFrame

  public static void main(String[] args)

  try UIManager setLookAndFeel( 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 ) //一张 * 的图片

  jf setAlwaysOnTop(true)

  jf setIconImage(image)

  jdmean setBounds((int)(tk getScreenSize() getWidth() ) (int)(tk getScreenSize() getHeight() )+ )

  jdmean setUndecorated(true)

  jdmean setAlwaysOnTop(true)

  jtamean setLineWrap(true)

  jdmean add(jScmean)

  jdmean setVisible(true)

  AWTUtilities setWindowOpacity(jf f)

  AWTUtilities setWindowOpacity(jdmean f)

  jtfWord setBounds( )

  jp setLayout(null)

  jp add(jtfWord)

  jp setBackground(Color GRAY)

  jf setContentPane(jp)

  jf setBounds((int)(tk getScreenSize() getWidth() ) (int)(tk getScreenSize() getHeight() ) )

  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 popupMenu = new PopupMenu()

  MenuItem menuItem = new MenuItem()

  ti setPopupMenu(popupMenu )

  ti addMouseListener(new MouseAdapter()

  public void mouseClicked(MouseEvent e)

  if (e getClickCount() == )

  jf setVisible(true)

  

  

  )

  st add(ti)

  popupMenu setLabel( dict )

  menuItem setLabel( 退出 )

  menuItem addActionListener(new ActionListener()

  public void actionPerformed(ActionEvent evt)

  System exit( )

  

  )

  popupMenu add(menuItem )

  

   catch (AWTException e)

  e printStackTrace()

  

  jf addWindowListener(new WindowAdapter()

  public void windowIconified(WindowEvent evt)

  

  )

  tk addAWTEventListener(new AWTEventListener()

  @Override

  public void eventDispatched(AWTEvent event)

  if(((KeyEvent) event) getID() == KeyEvent KEY_PRESSED)

  if(((KeyEvent) event) getKeyCode()==KeyEvent VK_F )

  System exit( )

  else if( ((KeyEvent) event) getKeyCode()==KeyEvent VK_ESCAPE)

  jf setVisible(false)

  if(AWTUtilities getWindowOpacity(jdmean)> d)

  double[] ds = ;

  for(double d:ds)

  _sleep( )

  AWTUtilities setWindowOpacity(jdmean (float)d)

  

  

    else if( ((KeyEvent) event) getKeyCode()==KeyEvent VK_F )

  jf setVisible(true)

  jtfWord requestFocus()

  

  

  

   AWTEvent KEY_EVENT_MASK)

  jp addMouseMotionListener(new MouseMotionListener()

  @Override

  public void mouseMoved(MouseEvent arg )

  

  @Override

  public void mouseDragged(MouseEvent arg )

  int x = arg getX() + jf getX()

  int y = arg 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;

  jf setBounds(jf getX()+detaX jf getY()+detaY )

  jdmean setBounds(jf getX()+detaX jf getY()+detaY+ )

  oldX var = x;

  oldY var = y;

  

  )

  jp addMouseListener(new MouseListener()

  @Override

  public void mouseReleased(MouseEvent arg )

  canDrag var = false;

  isFirst var = false;

  

  @Override

  public void mousePressed(MouseEvent arg )

  canDrag var = true;

  isFirst var = true;

  

  @Override

  public void mouseExited(MouseEvent arg )

  

  @Override

  public void mouseEntered(MouseEvent arg )

  

  @Override

  public void mouseClicked(MouseEvent arg )

  

  )

  jf addWindowListener(new WindowAdapter()

  public void windowIconified(WindowEvent evt)

  AWTUtilities setWindowOpacity(jdmean f)

  

  )

  jtfWord addKeyListener(new KeyListener()

  @Override

  public void keyTyped(KeyEvent e)

  

  @Override

  public void keyReleased(KeyEvent e)

  if( e getKeyCode()==KeyEvent VK_ENTER)

  if((e getModifiersEx() & KeyEvent SHIFT_DOWN_MASK) != )

  jtfWord setText( )

  jtamean setText( )

  Thread t = new Thread(new Runnable()

  @Override

  public void run()

  if(AWTUtilities getWindowOpacity(jdmean)> d)

  double[] ds = ;

  for(int i= ; i<ds length; i++)

  double d = ds[i];

  _sleep( )

  AWTUtilities setWindowOpacity(jdmean (float)d)

  jdmean setBounds(jdmean getX() jdmean getY() (int)(( *i)* ) (int)(( *i)* ))

  

  

  

  )

  t start()

  return;

  

  try

  String url = dict co iciba /api/dictionary php?key=这里需要填Key 你可以到金山词霸Api官网审请 审请到key后 把这段废话去掉 左右大括号也要去掉 然后填入你的key 本人有一个key 但不便放在网上共享&w=

  +jtfWord getText()

  VarByte vb = DictFrame getPage(url)

  String content = new String(vb to_byte() utf )

  String tagBegin = <acceptation> ;

  String tagEnd = </acceptation> ;

  StringBuilder sb = new StringBuilder()

  int cur = ;

  while((cur=content indexOf(tagBegin cur))!= )

  cur += ;

  int curEnd = content indexOf(tagEnd cur)

  sb append(content substring(cur curEnd))

  curEnd += ;

  

  if(sb toString() length()== ) sb append( 抱歉 未查询到词义! )

  jtamean setText(sb toString())

  AWTUtilities setWindowOpacity(jdmean f)

  jdmean setBounds(jdmean getX() jdmean getY() )

   catch (Exception ex)

  jtamean setText;

  AWTUtilities setWindowOpacity(jdmean f)

  jdmean setBounds(jdmean getX() jdmean getY() )

  

  

  

  @Override

  public void keyPressed(KeyEvent arg )

  

  )

  

  public static void _sleep(long m)

  try

  Thread sleep(m)

   catch (InterruptedException e)

  e printStackTrace()

  

  

  public static VarByte getPage (String address) throws Exception

  URL url = new URL(address)

  InputStream inStream = url openStream()

  VarByte page = new VarByte()

  int oneTimeSize = ;

  byte[] b = new byte[oneTimeSize];

  int len;

  while((len=inStream read(b))!= )

  if(len!=oneTimeSize)

  b = pyOf(b len)

  

  page append(b)

  

  if(inStream!=null) inStream close()

  return page;

  

  

  class VarByte

  byte[]  b = new byte[ ];

  int capacity = ;

  int len = ;

  public VarByte append(byte[] ba)

  if(len+ba length>capacity)

  byte[] tmp = new byte[(len+ba length)* ];

  System arraycopy(b tmp len)

  System arraycopy(ba tmp len ba length)

  b = tmp;

  len = len+ba length;

  capacity = len* ;

   else

  System arraycopy(ba b len ba length)

  len = len + ba length;

  

  return this;

  

  public byte[] to_byte()

  byte[] btmp = new byte[len];

  System arraycopy(b btmp len)

  return btmp;

  

  public byte[] to_byte(int start int len)

  byte[] btmp = new byte[len];

  for(int i= ; i<len; i++)

  btmp[i] = b[start+i];

  

  return btmp;

  

  public int size()

  return len;

  

cha138/Article/program/Java/hx/201311/25904

相关参考

知识大全 用java写一个登陆程序,可以与服务器连接,登陆成功后跳转到服务器网站上

用java写一个登陆程序,可以与服务器连接,登陆成功后跳转到服务器网站上楼主,这样的需求,不管如何都要有一个API说明的吧,根据实际的情况写相应的网络程序ftp服务器无法登陆,同一个服务器上的网站可以

知识大全 最好是免费的。

我想下载一个软件。是中英文翻译的,但最好是英音发音的。不要美音的。谢谢!最好是免费的。百度翻译Google在线翻译爱词霸必应翻译有道词典翻译软件大全ki翻译助手Yahoo在线翻译金山快译日语在线翻译金

知识大全 php 进阶:写一个用户在线显示的程序

在开始这篇文章时作者假设读者已能够写出一个用户的登入认证程序记数器可完成访问web页的总次数但却不能得知一个时段中访问量的动态记载下面就来介绍如何写一个各个时段动态显示访问量的方法要记载访问量首先就要

知识大全 让自己学会写的一个在线升级的程序

  voidCUpdateDlg::OnButtonDoupdate()      //读取升级文件  CFileStatusrStatus;  CStringszIniData;  CStringi

知识大全 用java语言编程序:计算1+1/2!+1/3!+1/4,简单语句就好,不要写的太复杂哦,谢谢哦

用java语言编程序:计算1+1/2!+1/3!+1/4,简单语句就好,不要写的太复杂哦,谢谢哦!publicclassTestpublicstaticvoidmain(Stringargs[])in

知识大全 初学Java, 在写在线电影购票,想问下 怎么实现买票选座位的功能?

初学Java,在写在线电影购票,想问下怎么实现买票选座位的功能?  以下文字资料是由(本站网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来

知识大全 根据竟思想写词语形容什么东西都有

根据竟思想写词语形容什么东西都有应有尽有_金山词霸【拼音】:yīngyǒujìnyǒu【解释】:应该有的都有.形容十分齐备.【出处】:《宋书·江智渊传》:“时咨议参军谢庄、府主簿沈怀文并与智渊友善.怀

知识大全 java操作word

  最近在做项目的时候需要这么一个功能客户有一大堆word格式的模板需要我们用程序向模板里面填充一些数据如果是直接重新写一个Word用POI或Itext都可以搞定关键是读取并解析而且Word里有表格图

知识大全 用C#写一个下载程序

用C#写一个下载程序  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!cha138/Arti

知识大全 用Java Swing作一个日历控制程序

用JavaSwing作一个日历控制程序  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  日期是最基