Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///// Main.class \\\\\
- package mapMaker;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Main {
- private static void createAndShowGUI() {
- JFrame frame = new JFrame("myGame - Main Form");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JButton cmd = new JButton("Button 1");
- cmd.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.out.println("You clicked the button!");
- }
- });
- frame.getContentPane().add(cmd);
- frame.getContentPane().setLayout(new FlowLayout());
- frame.pack();
- frame.setVisible(true);
- DataBank sideForm = new DataBank("Side Form");
- sideForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- sideForm.pack();
- sideForm.setVisible(true);
- System.out.print("main() main form");
- }
- public static void main(String[] args) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
- ///// DataBank.class \\\\\
- package mapMaker;
- import java.awt.*;
- import java.awt.image.*;
- import java.io.*;
- import java.net.*;
- import javax.imageio.*;
- import javax.swing.*;
- public class DataBank extends JFrame {
- BufferedImage bground = loadImage("C:/Users/mc_teo/Desktop/pokemon_sprites.jpg");
- // BufferedImage bground = loadOnlineImage("http://www.freewebs.com/pokemontopazproject/pokemon%20sprites%201111112222233333444445555566666677777888889999900000.bmp");
- BufferedImage db[];
- int tilew = 17; // pixels per tile (including whitespace)
- int tileh = 17; // pixels per tile (including whitespace)
- int realw = 16; // pixels per tile (not including whitespace)
- int realh = 16; // pixels per tile (not including whitespace)
- public DataBank(String string) {
- setTitle(string);
- }
- public void prepim() {
- int cols = bground.getWidth()/tilew;
- int rows = bground.getHeight()/tileh;
- int num = 0;
- db = new BufferedImage[rows*cols];
- for(int y = 0; y < rows; y++) {
- for(int x = 0; x < cols; x++) {
- db[num] = new BufferedImage(realw, realh, bground.getType());
- // Tell the graphics to draw only one block of the image
- Graphics2D g = db[num].createGraphics();
- // g.drawImage(bground, 0, 0, realw, realh, (tilew*x), (tileh*y), ((tilew*x)+realw), ((tileh*y)+realh), null);
- g.drawImage(bground, 0, 0, realw, realh, (tilew*x), (tileh*y), ((tilew*x)+realw), ((tileh*y)+realh), null);
- System.out.print("x: " + tilew*x + " y: " + tileh*y + " h: " + ((tileh*y)+realh) + " w: " + ((tilew*x)+realw) + '\n');
- // System.out.print("");
- g.dispose();
- num++;
- }
- }
- }
- public void init() {
- // setSize(bground.getWidth(), bground.getHeight());
- setSize(500, 500);
- prepim();
- // javax.swing.SwingUtilities.invokeLater(new Runnable() {
- }
- public void main() {
- // repaint();
- }
- public void paint(Graphics g) {
- int num = 0;
- for(int y = 0; y < bground.getHeight()/tileh; y++){
- for(int x = 0; x < bground.getWidth()/tilew; x++){
- g.drawImage(db[num], x*realh, y*realh, null);
- // System.out.print("height: " + bground.getHeight() + " width: " + bground.getWidth() + '\n');
- // System.out.print("x: " + x + " y: " + y + " x*y: " + (x*y) + '\n');
- num++;
- }
- }
- }
- public static BufferedImage loadImage(String ref) {
- BufferedImage bimg = null;
- try {
- bimg = ImageIO.read(new File(ref));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return bimg;
- }
- public static BufferedImage loadOnlineImage(String ref) {
- BufferedImage bimg = null;
- try {
- bimg = ImageIO.read(new URL(ref));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return bimg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement