當前位置:編程學習大全網 - 編程語言 - 救救救!!Java大神,編程大神幫幫忙

救救救!!Java大神,編程大神幫幫忙

package?image;

import?java.awt.Dimension;

import?java.awt.Graphics;

import?java.awt.Graphics2D;

import?java.awt.Image;

import?java.awt.image.BufferedImage;

import?java.io.IOException;

import?java.net.URL;

import?javax.imageio.ImageIO;

import?javax.swing.Icon;

import?javax.swing.ImageIcon;

import?javax.swing.JButton;

import?javax.swing.JFrame;

import?javax.swing.JPanel;

public?class?GameJFrame?extends?JPanel

{

private?static?final?long?serialVersionUID?=?1L;

protected?Image?bufferedImage?=?null;

Image?img?=?GameJFrame.getImage?("image/wood.jpg");

@Override

public?void?paint?(?Graphics?g?)

{

super.paint?(g);

g.drawImage?(img,?0,?0,?null);

g.dispose?();

}

public?void?launchJFrame?()

{

JFrame?jf?=?new?JFrame?();

this.setDoubleBuffered?(true);

BufferedImage?bi?=?new?BufferedImage?(img.getWidth?(null),?img.getHeight?(null),?BufferedImage.TYPE_INT_BGR);

Graphics2D?graphics2d?=?bi.createGraphics?();

graphics2d.drawImage?(img,?0,?0,?null);

int?deltaX?=?6,?deltaY?=?62;

int?width?=?img.getWidth?(null)?-?2?*?deltaX?-?1,?height?=?img.getHeight?(null)?-?deltaY?-?16;

Icon?icon?=?new?ImageIcon?(bi.getSubimage?(deltaX,?deltaY,?width,?height),?"截圖按鈕");

graphics2d.dispose?();

JButton?button?=?new?JButton?(icon);

button.setPreferredSize?(new?Dimension?(width,?height));

this.add?(button);

jf.add?(this);

jf.setSize?(800,?600);

jf.setLocationRelativeTo?(null);

jf.setDefaultCloseOperation?(JFrame.EXIT_ON_CLOSE);

jf.setVisible?(true);

}

public?static?void?main?(?String[]?args?)

{

GameJFrame?gjf?=?new?GameJFrame?();

gjf.launchJFrame?();

}

public?static?Image?getImage?(?String?path?)

{

URL?u?=?GameJFrame.class.getClassLoader?().getResource?(path);

BufferedImage?img?=?null;

try

{

img?=?ImageIO.read?(u);

}

catch?(IOException?e)

{

e.printStackTrace?();

}

return?img;

}

}

  • 上一篇:AI軟件怎麽畫瓶子形狀?如何用AI畫瓶子?
  • 下一篇:如何設計培訓需求問卷?
  • copyright 2024編程學習大全網