java编写塔防游戏(多版本)附带源码、注释、简单讲解 猥琐的人生不需要解释http://blog.csdn.net/go12355/article/details/8264568 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 分享个搞笑的小程序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(); } }} 去掉网页复制代码前的数字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()); }} JSCH:如何获得JSCH中channel中的数据流,并将其转化为字符串 这个正则表达式怎么匹配? hibernate 可变条件查询 请教:如何实现一个程序启动界面 相同的代码,不同的结果,大家帮忙看看为什么 top的问题 JNDI资源绑定 想学java,有什么好用的编程软件吗? 请问,在Jbuilder8中运行时出现以下信息是什么原因?怎样解决?在线等待 请问IBM Visual Age Java里面,如何调用处在Default Package ...里面的Class? 关于java中的闭包和回调的问题 怎么在java程序里调用cmd 执行java指令?
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();
} }}
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());
}}