public class Vehicles {
10年積累的成都網(wǎng)站建設(shè)、做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有吉林免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
private String brand;
private String color;
//構(gòu)造方法
public Vehicles(String brand, String color) {
this.brand = brand;
this.color = color;
}
public void run() {
System.out.println("我已經(jīng)開動了");
}
public void showinfo() {
System.out.println("商標(biāo): " + brand);
System.out.println("顏色: " + color);
}
}
保存為Vehicles.java
/////////////////////////////////////////////////////////////
public class Car extends Vehicles {
private int seats;
//構(gòu)造方法
public Car(String brand, String color, int seats) {
super(brand, color);
this.seats = seats;
}
public void showCar() {
super.showinfo();
System.out.println("座位: " + seats + " 個");
}
}
保存為 Car.java
//////////////////////////////////////////////////////////////////////////////
public class Truck extends Vehicles {
private float load;
public Truck(String brand, String color, float load) {
super(brand, color);
this.load = load;
}
public void showTruck() {
super.showinfo();
System.out.println("載重 :" + load + "噸");
}
}
保存為Truck.java
//////////////////////////////////////////////////////////////////////////////
public class Test {
public static void main(String[] args) {
Vehicles vehicle = new Vehicles("奧迪", "黑色");
vehicle.showinfo();
Car car = new Car("桑塔納", "紅色", 5);
car.showCar();
Truck truck = new Truck("解放", "藍(lán)色", 10);
truck.showTruck();
}
}
絕對是有用的,很大用出。
代碼就是這樣,你只有敲得多了才會慢慢學(xué)好。
不要怕累,多聯(lián)系會好的。
如有幫助請采納謝謝
以下的代碼就可以,lz自己在*的地方填入星星的圖片就可以了
body bgcolor=#ee3300
style
.drop { position: absolute; width: 3; filter: flipV(), flipH(); font-size: 40; color: #ffffff }
/style
script language="javascript"
snow = false; // false-rain; true-snow
snowsym = " * " are the symbols for each
rainsym = " * " can put images here.
howmany = 20 many drops/snowflakes?
/**************Do not need to change anything below***********/
if(snow){sym = snowsym; speed=1; angle=10; drops=howmany}
else{sym = rainsym; speed=30; drops=howmany; angle=6}
movex = -speed/angle; movey = speed; count = 0;
function moverain(){
for(move = 0; move drops; move++){
xx[move]+=movex; yy[move]+=mv[move];
hmm = Math.round(Math.random()*1);
if(xx[move] 0){xx[move] = maxx+10;}
if(yy[move] maxy){yy[move] = 10;}
drop[move].left = xx[move]
drop[move].top = yy[move]+document.body.scrollTop;
}setTimeout('moverain()','1')}
/script
script language="javascript"
if (document.all){
drop = new Array(); xx = new Array(); yy = new Array(); mv = new Array()
ly = "document.all[\'"; st = "\'].style"
for(make = 0; make drops; make++){
document.write('div id="drop'+make+'" class=drop'+sym+'/div');
drop[make] = eval(ly+'drop'+make+st);
maxx = document.body.clientWidth-40
maxy = document.body.clientHeight-40
xx[make] = Math.random()*maxx;
yy[make] = -100-Math.random()*maxy;
drop[make].left = xx[make]
drop[make].top = yy[make]
mv[make] = (Math.random()*5)+speed/16;
drop[make].fontSize = (Math.random()*10)+20;
if(snow){col = 'white'}else{col = 'white'}
drop[make].color = col;
}
window.onload=moverain
}
/script
/body
監(jiān)聽鼠標(biāo)動作,
然后控制子彈圖片移動。
然后跟目標(biāo)做碰撞檢測。
java 事件 消息傳遞機制 實際上是
1、用戶點擊鼠標(biāo)左鍵。
2、操作系統(tǒng)觸發(fā)一個事件傳遞個java程序。
3、java程序再去觸發(fā)你代碼里相關(guān)控件的ui響應(yīng)或者你自己定義的Listener。
我認(rèn)為想要實現(xiàn)你的需求的話,忽略1,在2處模擬操作系統(tǒng)同,傳遞一個事件給java程序了,這只是我的一個想法。
唉,給你看看小Case的,自己運行一下
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class TranslucentButton extends JButton {
BufferedImage buttonImage = null;
/** Creates a new instance of TranslucentButton */
public TranslucentButton(String label) {
super(label);
setOpaque(false);
}
public void paint(Graphics g) {
// Create an image for the button graphics if necessary
if (buttonImage == null || buttonImage.getWidth() != getWidth() ||
buttonImage.getHeight() != getHeight()) {
buttonImage = getGraphicsConfiguration().
createCompatibleImage(getWidth(), getHeight());//返回一個數(shù)據(jù)布局和顏色模型與此 GraphicsConfiguration 兼容的 BufferedImage
}
Graphics gButton = buttonImage.getGraphics();
gButton.setClip(g.getClip());//設(shè)置獲取的當(dāng)前的剪貼區(qū)域
// Have the superclass render the button for us
super.paint(gButton);
// Make the graphics object sent to this paint() method translucent
Graphics2D g2d = (Graphics2D)g;
AlphaComposite newComposite =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
g2d.setComposite(newComposite);
// Copy the button's image to the destination graphics, translucently
g2d.drawImage(buttonImage, 0, 0, null);
}
private static void createAndShowGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 300);
JPanel checkerboard = new Checkerboard();
checkerboard.add(new TranslucentButton("Translucent Button"));
f.add(checkerboard);
f.setVisible(true);
}
public static void main(String args[]) {
Runnable doCreateAndShowGUI = new Runnable() {
public void run() {
createAndShowGUI();
}
};
SwingUtilities.invokeLater(doCreateAndShowGUI);//swing線程
}
private static class Checkerboard extends JPanel {
static final int CHECKER_SIZE = 60;
public void paintComponent(Graphics g) {
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
for (int stripeX = 0; stripeX getWidth(); stripeX += CHECKER_SIZE) {
for (int y = 0, row = 0; y getHeight(); y += CHECKER_SIZE/2, ++row) {
int x = (row % 2 == 0) ? stripeX : (stripeX + CHECKER_SIZE/2);
g.fillRect(x, y, CHECKER_SIZE/2, CHECKER_SIZE/2);
}
}
}
}
}
代碼有點多, 實現(xiàn)思路, 實現(xiàn)鍵盤事件監(jiān)聽機制, 在監(jiān)聽函數(shù)中判斷 按了什么鍵,比如按J就發(fā)送子彈. 然后啟動子彈線程. 定義一個子彈類線程, 定義出子彈的所在屬性和方法.
寫個方法,判斷子彈是否擊中目標(biāo),以XY坐標(biāo)相交來判斷