① 怎麼編寫java程序實現圖片的移動(最好有例子)
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
public class DrawTest extends JFrame {
private int x = 50;
private int y = 50;
private Image offScreenImage = null;
@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.BLACK);
g.fillOval(x, y, 30, 30);
g.setColor(c);
}
public void update(Graphics g) {
if (offScreenImage == null) {
offScreenImage = this.createImage(500, 500);
}
Graphics gOffScreen = offScreenImage.getGraphics();
Color c = gOffScreen.getColor();
gOffScreen.setColor(Color.GREEN);
gOffScreen.fillRect(0, 0, 500, 500);
gOffScreen.setColor(c);
paint(gOffScreen);
g.drawImage(offScreenImage, 0, 0, null);
}
public static void main(String[] args) {
DrawTest d = new DrawTest();
}
public DrawTest() {
init();
addKeyListener(new KeyAdapter() {
public void keyPressed(final KeyEvent e) {
int code = e.getKeyCode();
switch (code) {
case KeyEvent.VK_UP:
y -= 5;
break;
case KeyEvent.VK_RIGHT:
x += 5;
break;
case KeyEvent.VK_DOWN:
y += 5;
break;
case KeyEvent.VK_LEFT:
x -= 5;
break;
}
}
});
}
public void init() {
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setBackground(Color.GREEN);
this.setResizable(false);
this.setBounds(140, 140, 500, 500);
this.setVisible(true);
MyThread mt = new MyThread();
new Thread(mt).start();
}
class MyThread implements Runnable {
public void run() {
while (true) {
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
以上
② java讀取pdf判斷文字旋轉方向
嗯……關於java讀取pdf的話,推薦閣下試試pdfbox這個工具,能夠支持中文,但是缺點在於不能讀取圖片形式的pdf,比如將一篇文章照下來,存成圖片,做的pdf識別不了。如果閣下想要做圖像方面的文字識別的話,可以考慮使用tesseract這個工具,同樣識別中文!關於文字的旋轉方向……在下的思路是每次將文字進行九十度旋轉,並進行識別,能識別出來的時候,計算出旋轉角度即可!思路僅供參考,祝閣下學習愉快!