真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java圖片移動(dòng)代碼 java怎么調(diào)用圖片到代碼運(yùn)行

java 中移動(dòng)圖片,并且在按鍵盤的“回車”時(shí),切換到另外一張圖片?。≌?qǐng)?jiān)谖蚁旅娴拇a改進(jìn)?。?!謝謝!!

你好,按照你的要求代碼如下,修改了三處

創(chuàng)新互聯(lián)建站,為您提供成都網(wǎng)站建設(shè)網(wǎng)站制作、網(wǎng)站營(yíng)銷推廣、網(wǎng)站開發(fā)設(shè)計(jì),對(duì)服務(wù)成都木制涼亭等多個(gè)行業(yè)擁有豐富的網(wǎng)站建設(shè)及推廣經(jīng)驗(yàn)。創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)公司成立于2013年,提供專業(yè)網(wǎng)站制作報(bào)價(jià)服務(wù),我們深知市場(chǎng)的競(jìng)爭(zhēng)激烈,認(rèn)真對(duì)待每位客戶,為客戶提供賞心悅目的作品。 與客戶共同發(fā)展進(jìn)步,是我們永遠(yuǎn)的責(zé)任!

簡(jiǎn)單說(shuō)明一下,就是加了一個(gè)標(biāo)識(shí)boolean,用true/false來(lái)表示顯示第一張/第二張圖片

import java.awt.*;

import java.awt.event.*;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import javax.swing.*;

public class zhandou extends JFrame implements KeyListener {

Image roleImage, Image1;

int x, y;

public zhandou() {

super("MOVE");

Container c = getContentPane();

setSize(320, 240);

setVisible(true);

loadImage();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// setFocusable(true);

addKeyListener(this);

}

boolean key = true;// 加這樣一個(gè)標(biāo)識(shí),true是第一張圖片,false為第二張圖片

public void paint(Graphics g) {

super.paint(g);

// drawRole(g);

if (key) {// 根據(jù)標(biāo)識(shí)判斷需要顯示的圖片

g.drawImage(roleImage, x, y, this);

} else {

g.drawImage(Image1, x, y, this);

}

}

public void loadImage() {

ImageIcon icon = new ImageIcon("tupian/草地.jpg");

roleImage = icon.getImage();

ImageIcon ic = new ImageIcon("tupian/right.gif");

Image1 = ic.getImage();

}

class Thread1 extends Thread {

}

/*

* private void drawRole(Graphics g) { g.drawImage(roleImage,100,100,this);

* }

*/

public void keyPressed(KeyEvent e) {

if (e.getKeyCode() == KeyEvent.VK_UP)

y = y - 5;

else if (e.getKeyCode() == KeyEvent.VK_DOWN)

y = y + 5;

else if (e.getKeyCode() == KeyEvent.VK_RIGHT)

x = x + 5;

else if (e.getKeyCode() == KeyEvent.VK_LEFT)

x = x - 5;

else if (e.getKeyCode() == KeyEvent.VK_ENTER)

key = !key;// 切換標(biāo)識(shí)狀態(tài)

repaint();

}

public void keyReleased(KeyEvent e) {

}

public void keyTyped(KeyEvent e) {

}

public static void main(String args[]) {

new zhandou();

}

}

java語(yǔ)言里怎么讓圖象移動(dòng)到指定位置啊,最好用一小段代碼說(shuō)明.

改變規(guī)制時(shí)候的X Y就行了.偽代碼如下.

int x =0,y=0,;

x++; y++;

g.drawImage( "圖片信息" , x, y,錨點(diǎn));

大概就這樣圖片就動(dòng)了.你想移動(dòng)到哪加個(gè)判斷就行了.

求Java 實(shí)現(xiàn)繪制圖形并移動(dòng)代碼

代碼如下:import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Graphics;import javax.microedition.midlet.MIDlet;import javax.microedition.midlet.MIDletStateChangeException;public class Zfx extends MIDlet { private Display display; public Zfx() { display=Display.getDisplay(this); Zfxc qs=new Zfxc(); display.setCurrent(qs); } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { }}class Zfxc extends Canvas implements Runnable{ private int x,y,x1,y1,i; private boolean flag; Zfxc(){ init(); } private void init(){ Thread thread=new Thread(this); thread.start(); } protected void paint(Graphics g) { g.setColor(255,255,255); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.setColor(0); g.fillRect(x, y, 10, 10); } private void logic(){ if(x=this.getWidth()-10){ x1=2; } if(x1==1){ x+=3; }else if(x1==2){ x-=3; } if(y=this.getHeight()-10){ y1=2; } if(y1==1){ y+=3; }else if(y1==2){ y-=3; } } protected void keyPressed(int keyCode) { if(keyCode==-5){ if(i==0){ flag=true; i=1; }else if(i==1){ flag=false; i=0; } } } public void run() { while(true){ if(flag){ logic(); } repaint(); try { Thread.sleep(80); } catch (InterruptedException e) { e.printStackTrace(); } } }}求Java 實(shí)現(xiàn)繪制圖形并移動(dòng)代碼

怎么編寫java程序?qū)崿F(xiàn)圖片的移動(dòng)(最好有例子)

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圖片移動(dòng)代碼 java怎么調(diào)用圖片到代碼運(yùn)行
新聞來(lái)源:http://weahome.cn/article/doppicp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部