java

位置:IT落伍者 >> java >> 浏览文章

用Java写一个在线金山词霸程序


发布日期:2021年06月03日
 
用Java写一个在线金山词霸程序

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

import javaawtAWTEvent;

import javaawtAWTException;

import javaawtColor;

import javaawtImage;

import javaawtMenuItem;

import javaawtPopupMenu;

import javaawtSystemTray;

import javaawtToolkit;

import javaawtTrayIcon;

import javaawteventAWTEventListener;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaawteventKeyEvent;

import javaawteventKeyListener;

import javaawteventMouseAdapter;

import javaawteventMouseEvent;

import javaawteventMouseListener;

import javaawteventMouseMotionListener;

import javaawteventWindowAdapter;

import javaawteventWindowEvent;

import javaioInputStream;

import URL;

import javautilArrays;

import javaxswingJDialog;

import javaxswingJFrame;

import javaxswingJPanel;

import javaxswingJScrollPane;

import javaxswingJTextArea;

import javaxswingJTextField;

import javaxswingUIManager;

import comsunawtAWTUtilities;

class RefBoolean {public boolean var = false;}

class RefInt {public int var = ;}

public class DictFrame {

public static void main(String[] args) {

try {UIManagersetLookAndFeel(comsunjavaswingplafwindowsWindowsLookAndFeel}

catch (Exception e) { Systemoutprintln(e) }

Toolkit tk = ToolkitgetDefaultToolkit()

final RefBoolean canDrag = new RefBoolean()

final RefBoolean isFirst = new RefBoolean()

final RefInt oldX = new RefInt()

final RefInt oldY = new RefInt()

isFirstvar = 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 = tkgetImage(c:/icojpg //一张*的图片

jfsetAlwaysOnTop(true)

jfsetIconImage(image)

jdmeansetBounds((int)(tkgetScreenSize()getWidth() (int)(tkgetScreenSize()getHeight())+

jdmeansetUndecorated(true)

jdmeansetAlwaysOnTop(true)

jtameansetLineWrap(true)

jdmeanadd(jScmean)

jdmeansetVisible(true)

AWTUtilitiessetWindowOpacity(jff)

AWTUtilitiessetWindowOpacity(jdmeanf)

jtfWordsetBounds(

jpsetLayout(null)

jpadd(jtfWord)

jpsetBackground(ColorGRAY)

jfsetContentPane(jp)

jfsetBounds((int)(tkgetScreenSize()getWidth() (int)(tkgetScreenSize()getHeight()

jfsetDefaultCloseOperation(JFrameEXIT_ON_CLOSE)

jfsetUndecorated(true)

jpvalidate()

jfsetVisible(true)

try {

if(SystemTrayisSupported()) {

SystemTray st = SystemTraygetSystemTray()

TrayIcon ti = new TrayIcon(image)

tisetToolTip(dict

PopupMenu popupMenu = new PopupMenu()

MenuItem menuItem = new MenuItem()

tisetPopupMenu(popupMenu

tiaddMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (egetClickCount() == ) {

jfsetVisible(true)

}

}

})

stadd(ti)

popupMenusetLabel(dict

menuItemsetLabel(退出

menuItemaddActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {

Systemexit(

}

})

popupMenuadd(menuItem

}

} catch (AWTException e) {

eprintStackTrace()

}

jfaddWindowListener(new WindowAdapter() {

public void windowIconified(WindowEvent evt) {

}

})

tkaddAWTEventListener(new AWTEventListener() {

@Override

public void eventDispatched(AWTEvent event) {

if(((KeyEvent) event)getID() == KeyEventKEY_PRESSED) {

if(((KeyEvent) event)getKeyCode()==KeyEventVK_F) {

Systemexit(

}else if( ((KeyEvent) event)getKeyCode()==KeyEventVK_ESCAPE) {

jfsetVisible(false)

if(AWTUtilitiesgetWindowOpacity(jdmean)>d) {

double[] ds = { };

for(double d:ds) {

_sleep(

AWTUtilitiessetWindowOpacity(jdmean(float)d)

}

}

} else if( ((KeyEvent) event)getKeyCode()==KeyEventVK_F) {

jfsetVisible(true)

jtfWordrequestFocus()

}

}

}

} AWTEventKEY_EVENT_MASK)

jpaddMouseMotionListener(new MouseMotionListener() {

@Override

public void mouseMoved(MouseEvent arg) {

}

@Override

public void mouseDragged(MouseEvent arg) {

int x = arggetX() + jfgetX()

int y = arggetY() + jfgetY()

if(isFirstvar) {

oldXvar = x;

oldYvar = y;

isFirstvar = false;

}

int detaX = xoldXvar;

int detaY = yoldYvar;

jfsetBounds(jfgetX()+detaX jfgetY()+detaY

jdmeansetBounds(jfgetX()+detaX jfgetY()+detaY+

oldXvar = x;

oldYvar = y;

}

})

jpaddMouseListener(new MouseListener() {

@Override

public void mouseReleased(MouseEvent arg) {

canDragvar = false;

isFirstvar = false;

}

@Override

public void mousePressed(MouseEvent arg) {

canDragvar = true;

isFirstvar = true;

}

@Override

public void mouseExited(MouseEvent arg) {

}

@Override

public void mouseEntered(MouseEvent arg) {

}

@Override

public void mouseClicked(MouseEvent arg) {

}

})

jfaddWindowListener(new WindowAdapter() {

public void windowIconified(WindowEvent evt) {

AWTUtilitiessetWindowOpacity(jdmeanf)

}

})

jtfWordaddKeyListener(new KeyListener() {

@Override

public void keyTyped(KeyEvent e) {

}

@Override

public void keyReleased(KeyEvent e) {

if( egetKeyCode()==KeyEventVK_ENTER) {

if((egetModifiersEx() & KeyEventSHIFT_DOWN_MASK) != ) {

jtfWordsetText(

jtameansetText(

Thread t = new Thread(new Runnable() {

@Override

public void run() {

if(AWTUtilitiesgetWindowOpacity(jdmean)>d) {

double[] ds = { };

for(int i=; i<dslength; i++) {

double d = ds[i];

_sleep(

AWTUtilitiessetWindowOpacity(jdmean(float)d)

jdmeansetBounds(jdmeangetX() jdmeangetY() (int)((*i)* (int)((*i)*))

}

}

}

})

tstart()

return;

}

try {

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

+jtfWordgetText()

VarByte vb = DictFramegetPage(url)

String content = new String(vbto_byte() utf

String tagBegin = <acceptation>;

String tagEnd = </acceptation>;

StringBuilder sb = new StringBuilder()

int cur = ;

while((cur=contentindexOf(tagBegin cur))!=) {

cur += ;

int curEnd = contentindexOf(tagEnd cur)

sbappend(contentsubstring(cur curEnd))

curEnd += ;

}

if(sbtoString()length()==) sbappend(抱歉 未查询到词义!

jtameansetText(sbtoString())

AWTUtilitiessetWindowOpacity(jdmeanf)

jdmeansetBounds(jdmeangetX() jdmeangetY()

} catch (Exception ex) {

jtameansetText;

AWTUtilitiessetWindowOpacity(jdmeanf)

jdmeansetBounds(jdmeangetX() jdmeangetY()

}

}

}

@Override

public void keyPressed(KeyEvent arg) {

}

})

}

public static void _sleep(long m) {

try {

Threadsleep(m)

} catch (InterruptedException e) {

eprintStackTrace()

}

}

public static VarByte getPage (String address) throws Exception {

URL url = new URL(address)

InputStream inStream = urlopenStream()

VarByte page = new VarByte()

int oneTimeSize = ;

byte[] b = new byte[oneTimeSize];

int len;

while((len=inStreamread(b))!=) {

if(len!=oneTimeSize) {

b = pyOf(b len)

}

pageappend(b)

}

if(inStream!=null) inStreamclose()

return page;

}

}

class VarByte {

byte[] b = new byte[];

int capacity = ;

int len = ;

public VarByte append(byte[] ba) {

if(len+balength>capacity) {

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

Systemarraycopy(b tmp len)

Systemarraycopy(ba tmp len balength)

b = tmp;

len = len+balength;

capacity = len*;

} else {

Systemarraycopy(ba b len balength)

len = len + balength;

}

return this;

}

public byte[] to_byte() {

byte[] btmp = new byte[len];

Systemarraycopy(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;

}

}

               

上一篇:Java网络编程基础(四) ServerSocket类使用

下一篇:Java连接数据库的使用步骤