猥琐的人生不需要解释http://blog.csdn.net/go12355/article/details/8264568

解决方案 »

  1.   

    分享个搞笑的小程序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();
    } }}
      

  2.   

    去掉网页复制代码前的数字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());
    }}