Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: codeing help random pixels

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default codeing help random pixels

    Display.java

    import java.awt.Canvas;
    import java.awt.Graphics;
    import java.awt.image.BufferStrategy;
    import java.awt.image.BufferedImage;
    import java.awt.image.DataBufferInt;
    import javax.swing.JFrame;
    import com.mime.soilderattack.graphics.Render;
    import com.mime.soilderattack.graphics.Screen;
    import java.awt.Toolkit;

    public class Display extends Canvas implements Runnable {
    private static final long serialVersionUID = 1L;

    public static final int width = 800;
    public static final int height = 600;
    public static final String TITLE = "Soilder Attack Pre-Alpha 0.01";

    private Thread thread;
    private Screen screen;
    private BufferedImage img;
    private Render render;
    private boolean running = false;
    private int[] pixels;

    public Display() {
    screen = new Screen(WIDTH, HEIGHT);
    img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).g etData();
    }

    private void start() {
    if (running)
    return;
    running = true;
    thread = new Thread(this);
    thread.start();

    }

    private void stop() {
    if (!running)
    return;
    running = false;
    try {
    thread.join();
    } catch (Exception e) {
    e.printStackTrace();
    System.exit(0);
    }
    }

    public void run() {
    while (running) {
    tick();
    render();

    }
    }


    private void tick() {

    }

    private void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
    createBufferStrategy(3);
    return;

    }

    //screen.render();

    for (int i = 0; i<WIDTH * HEIGHT; i++) {
    pixels[i] = screen.pixels[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(img, 0, 0, WIDTH, HEIGHT, null);
    g.dispose();
    bs.show();}



    public static void main(String[] args) {
    Display game = new Display();
    JFrame frame = new JFrame();
    frame.add(game);
    frame.pack();
    frame.setTitle(TITLE);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(width, height);
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setVisible(true);

    System.out.println("Running...");

    game.start();
    }

    }

    Render.java

    package com.mime.soilderattack.graphics;

    public class Render {
    public final int width;
    public final int height;
    public final int[] pixels;

    public Render(int width, int height) {
    this.width = width;
    this.height = height;
    pixels = new int[width = height];
    }

    public void draw(Render render, int xOffset, int yOffset) {
    for (int y = 0; y < render.height; y++) {
    int yPix = y + yOffset;
    for (int x = 0; x < render.width; x++) {
    int xPix = x + xOffset;

    pixels[xPix + yPix * width] = render.pixels[x + y * render.width];
    }
    }

    }
    }

    screen.java


    public class Screen extends Render {
    private Render test;

    public Screen(int width, int height) {
    super(width, height);
    Random random = new Random();
    test = new Render(256, 256);
    for (int i = 0; i <256*256; i++); {
    //test.pixels[i] = random.nextInt();
    }

    }

    public void render() {
    for (int i = 0; i < width * height; i++) {
    pixels[i] = 0;
    }

    for (int i = 0; i < 200; i++) {

    }
    }
    }

    can you tell me what to do and where to put it i am new to this coding


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: codeing help random pixels

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    tell me what to do and where to put it
    Can you explain what the problem is? What are you trying to do? What does the program do that you want to change?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Mirroring pixels
    By lovely92 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 20th, 2012, 07:06 AM
  2. access the encrypted folder from java codeing
    By bala03ram in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 12th, 2012, 06:14 AM
  3. Getting pixels from an image, and saving them in an array?
    By jtvd78 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 14th, 2011, 08:48 PM
  4. [SOLVED] Coloring Pixels
    By Javajava in forum Java SE APIs
    Replies: 2
    Last Post: July 7th, 2010, 04:02 PM
  5. Obtaining straightline pixels
    By base2coder in forum Java Theory & Questions
    Replies: 4
    Last Post: September 11th, 2009, 01:58 AM

Tags for this Thread