1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* This code was generated using CloudGarden's Jigloo SWT/Swing GUI Builder,
* which is free for non-commercial use. If Jigloo is being used commercially
* (ie, by a corporation, company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo. Please visit
* www.cloudgarden.com for details. Use of Jigloo implies acceptance of these
* licensing terms. ************************************* A COMMERCIAL LICENSE
* HAS NOT BEEN PURCHASED for this machine, so Jigloo or this code cannot be
* used legally for any corporate or commercial purpose.
* *************************************
*/
public class NewJPanel extends javax.swing.JPanel {
/**
* Auto-generated main method to display this JPanel inside a new JFrame.
*/
private Image img;
private BufferedImage bimg;
private int width;
private int height;
public NewJPanel() {
super();
//img = Toolkit.getDefaultToolkit().createImage("test.jpg");
// bimg = new BufferedImage(200,200,BufferedImage.TYPE_4BYTE_ABGR);
try {
bimg = ImageIO.read(new File("test.jpg"));
width = bimg.getWidth();
height = bimg.getHeight();
} catch (IOException e) {
e.printStackTrace();
}
initGUI();
}
public void scroll() {
int col;
int xpos,ypos;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
if(i>=width-1) {
xpos=1;
} else {
xpos=i+1;
}
col = bimg.getRGB(xpos, j);
bimg.setRGB(i, j, col);
}
}
repaint();
}
private void initGUI() {
try {
setPreferredSize(new Dimension(bimg.getWidth(), bimg.getHeight()));
} catch (Exception e) {
e.printStackTrace();
}
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
super.paint(g);
g2.drawImage(bimg,0,0,null);
}
} |
Partager