java编写塔防游戏(多版本)附带源码、注释、简单讲解

小双 2012-12-06 04:18:31
猥琐的人生不需要解释

http://blog.csdn.net/go12355/article/details/8264568
...全文
542 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
小双 2012-12-07
  • 打赏
  • 举报
回复
分享个搞笑的小程序

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;

public class BaseFrame extends JFrame implements Runnable {

	private int w;

	private int h;
	
	private int x;
	
	private int y;

	private BufferedImage image;

	private Robot robot;

	private Rectangle rt;

	private Graphics g;

	public BaseFrame() {
		init();
		this.setBounds(x, y, w, h);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		Thread thread = new Thread(this);
		thread.start();
	}

	private void init() {
		try {
			int tookW = (int) Toolkit.getDefaultToolkit().getScreenSize()
					.getWidth();
			int tookH = (int) Toolkit.getDefaultToolkit().getScreenSize()
					.getHeight();
			x = 150;
			y = 100;
			w = tookW-300;
			h = tookH-200;
			robot = new Robot();
			rt = new Rectangle(0, 0, tookW, tookH);
			image = new BufferedImage(tookW, tookH,
					BufferedImage.TYPE_3BYTE_BGR);
			g = image.getGraphics();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 绘制方法
	 */
	public void paint(Graphics gr) {
		BufferedImage img = robot.createScreenCapture(rt);
		g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
		gr.drawImage(image, 0, 0, this); 
	}

	public static void main(String[] args) {
		new BaseFrame();
	}

	public void run() {
		try {
			while (true) {
				repaint();
				Thread.sleep(100);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
ylb2151 2012-12-07
  • 打赏
  • 举报
回复
喝前摇一摇
小双 2012-12-07
  • 打赏
  • 举报
回复
去掉网页复制代码前的数字

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Test extends JFrame implements ActionListener {

	JTextArea ta = new JTextArea();

	JButton bu = new JButton("cut");

	public Test() {
		this.setBounds(100, 100, 500, 600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new BorderLayout());
		JScrollPane jsp = new JScrollPane(ta);
		this.add(jsp, BorderLayout.CENTER);
		bu.addActionListener(this);
		this.add(bu, BorderLayout.SOUTH);
		this.setVisible(true);
	}

	public static void main(String[] args) {
		new Test();
	}

	public void actionPerformed(ActionEvent e) {
		String s = ta.getText();
		String[] str = s.split(" [0-9]+\\.");
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < str.length; i++) {
			sb.append(str[i]);
		}
		ta.setText(sb.toString());
	}

}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧