public class Vehicles {
private String brand;
private String color;
//构造方法
public Vehicles(String brand, String color) {
this.brand = brand;
this.color = color;
}
public void run() {
System.out.println("我已经开动了");
public void showinfo() {
System.out.println("商标: " + brand);
System.out.println("颜色: " + color);
保存为Vehicles.java
/////////////////////////////////////////////////////////////
public class Car extends Vehicles {
private int seats;
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) {
this.load = load;
public void showTruck() {
System.out.println("载重 :" + load + "吨");
保存为Truck.java
public class Test {
public static void main(String[] args) {
Vehicles vehicle = new Vehicles("奥迪", "黑色");
vehicle.showinfo();
car.showCar();
Truck truck = new Truck("解放", "蓝色", 10);
truck.showTruck();
绝对是有用的,很大用出.
代码就是这样,你只有敲得多了才会慢慢学好.
不要怕累,多联系会好的.
如有帮助请采纳谢谢
以下的代码就可以,lz自己在*的地方填入星星的图片就可以了
style
/style
script language="javascript"
snow = false; // false-rain; true-snow
snowsym = " * " are the symbols for each
rainsym = " * " can put images here.
/**************Do not need to change anything below***********/
if(snow){sym = snowsym; speed=1; angle=10; drops=howmany}
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
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++){
drop[make] = eval(ly+'drop'+make+st);
xx[make] = Math.random()*maxx;
yy[make] = -100-Math.random()*maxy;
drop[make].left = xx[make]
drop[make].top = yy[make]
if(snow){col = 'white'}else{col = 'white'}
drop[make].color = col;
window.onload=moverain
/body
监听鼠标动作,
然后控制子弹图片移动.
然后跟目标做碰撞检测.
java 事件 消息传递机制 实际上是
唉,给你看看小Case的,自己运行一下
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
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());//返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容的 BufferedImage
Graphics gButton = buttonImage.getGraphics();
gButton.setClip(g.getClip());//设置获取的当前的剪贴区域
// Have the superclass render the button for us
super.paint(gButton);
// Make the graphics object sent to this paint() method translucent
AlphaComposite newComposite =
// Copy the button's image to the destination graphics, translucently
private static void createAndShowGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
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() {
createAndShowGUI();
};
SwingUtilities.invokeLater(doCreateAndShowGUI);//swing线程
private static class Checkerboard extends JPanel {
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) {
代码有点多, 实现思路, 实现键盘事件监听机制, 在监听函数中判断 按了什么键,比如按J就发送子弹. 然后启动子弹线程. 定义一个子弹类线程, 定义出子弹的所在属性和方法.
写个方法,判断子弹是否击中目标,以XY坐标相交来判断
以上就是土嘎嘎小编为大家整理的java敲代码爆炸特效相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!