Simulations, pixels and repainting

Currently im trying to simulate a model of a few thousand objects (existing as species) and moving hunting etc as defined by code that i've already tested to work fine. My problem however comes to the GUI side of things, how for instance do you draw just 1 pixel? Does this become a Rectangle I need to fill which is 1*1 pixel in size? Or is there some kind of functionality to paint just one single pixel.
Following from this is my use of the repaint method. How can I go about 'repainting' a window without having to make it invisible and just draw a whole new one? I read the API referring to how JLabel's inherit repaint from about 30 different locations and decided to test out the simplest one where I pass the label.repaint(label), after having change the foreground, background, etc but it doesn't actually repaint it.
If someone could literally give me the code to draw a dot and then show me how they would move the dot to the right for instance (covering up the dot's tracks with the background colour) it would be massively appreciated.

Here's a short sample app that will show you the basics of one way to do this.
package com.sun.java.forums;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class LifePanel extends JPanel
     List<Point> pointsToPaint;
     public LifePanel()
          super();
          pointsToPaint = new Vector<Point>();
     public void setPoints(List<Point> points)
          this.pointsToPaint = points;
     @Override
     protected void paintComponent(Graphics g)
          Graphics2D g2d = (Graphics2D)g;
          // fill in the background
          g2d.setColor(getBackground());
          g2d.fill(g2d.getClip());
          // fill in the pixels
          g2d.setColor(getForeground());
          for (Point p: pointsToPaint)
               g2d.fillRect(p.x, p.y, 1, 1);
     public static void main(String args[])
          JFrame f = new JFrame();
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setLayout(new BorderLayout());
          final LifePanel lp = new LifePanel();
          lp.setBackground(Color.WHITE);
          lp.setForeground(Color.BLACK);
          final Point singlePoint = new Point(0,0);
          List<Point> points = new Vector<Point>();
          points.add(singlePoint);
          lp.setPoints(points);
          f.add(lp,BorderLayout.CENTER);
          f.setSize(400,400);
          f.setVisible(true);
          // move the point every second
          Timer timer = new Timer(250,new ActionListener()
               public void actionPerformed(ActionEvent ae)
                    // move the point 1 to the right and 1 down
                    singlePoint.translate(1, 1);
                    lp.repaint();
          timer.setRepeats(true);
          timer.start();
}This will create a 400 by 400 white area with a little black pixel on it. 4 times per second, the pixel will move to the southeast.
Your app will have much more interesting motion of points, I hope.

Similar Messages

  • I've been using Aperture now for the past 7 months and really happy with it, however in the past two days any photos I download are heavily pixelated and blurry. When I download the same shots to any other program they are fine.

    Hi,
    I've been using Aperture now for several months without any issues except for the last couple of days...when I now download my shots from the memory card the photos are heavily pixelated and blurry but when loaded to iPhoto they are fine.
    Can someone tell me what the problem could be and how to fix it.

    Is Aperture doing any processing?  ("Window→Show Activity" -- anything there?)
    Are the Images pixilated/degraded when shown in the Viewer as well as in the Browser?  (Double-click an Image to open it in the Viewer.)
    How 'bout at 100%? (In the Viewer, press "z" to zoom to 100%.  The "z" key toggles the zoom.)
    Does generating a new Preview remove the pixilation?  (Select an Image in the Browser, hold down "{Option}" and click "Photos→Generate Preview".)

  • Question about drawLIne(x1,y1,x2,y2) and repaint()

    i am doing this project, which i suppose to use drawLine and repaint() to generate graphs. my problem is, every time i hit a new button it will call the repaint() then my old graph is gone, only the new graph is left.
    for example
    i have 4 buttons. movesouth() movenorth() moveeast() movewest()
    when i hit movesouth two times there should be a staight line, when i hit movewest() my old graph is gone() it only left me with 1 unit to west cuz i have repaint() inside my actionPerformed function, my question is: is there a way that i can redraw these line without calling repaint () ? cuz repaint is kinda like redraw the new stuff and forget about the old ones, however i would like to keep the old one while adding the new graph to it.
    your suggestions would be great appreciated.

    well of course, your Graphics-Object is of the type Graphics2D, you just need a cast so that the compiler is happy ;-)
    Its the same Graphics2D object/instance as withought the cast...
    lg Clemens

  • When i open my computer I get the white screen with apple symbol and there are vertical lines all over the screen with green pixels and after a few minutes the screen gets grey and I get message to restart my computer what happens

    3 years ago I bought an IMac Desktop that I am using for a lot of things but the most important for dvd montage in Imovies and Idvd.
    Now today when I opened my computer I get as usual the white screen with the Apple symbol but there were all over the screen vertical lines with green pixels and after a while the screen gets grey and I get message to restart my computer using the power button or the restart button and when I do so each time the same is happening somebody can tell me what is happening and what caused this. This computer is my work and now I have no income anymore.
    On the Apple support site they are asking to enter the serial number and when I do so I get message it is wrong but it is the only one I have and I buy this computer in Cairo Egypt. I am living in Hurghada in Egypt for the moment. When I call the technical support of the shop where I buy it they are telling me that it is the hard disk or ram and that I probably lost everything on it and they are asking a big amount to repair.
    Can somebody advise me on this matter. Thanks in advance

    You can find the serial number either in About this Mc in the Menu bar under the , or it should be on a sticker under the foot of the machine.
    If you have the install discs, try booting from them, holding down the c key and then using Disk Utility to check the drive. 
    You can also boot into Safe mode
    To start up into Safe Mode (to "Safe Boot"), do this:
       1. Be sure the computer is shut down.
       2. Press the power button.
       3. Immediately after you hear the startup tone, press and hold the Shift key.
          Tip: The Shift key should be held as soon as possible after the startup tone but not before.
       4. Release the Shift key when you see the gray Apple and progress indicator (looks like a spinning gear).
    During the startup in Mac OS X 10.2 through 10.3.9, you will see "Safe Boot" on the Mac OS X startup screen.
    During the startup in Mac OS X 10.4 or later, you will see "Safe Boot" on the login window, which appears even if you normally log in automatically.
    Please post back with results,
    To leave Safe Mode in any version of Mac OS X, restart the computer normally, without holding any keys during startup.

  • Will warranty cover 1 dead pixel and an incredibly annoying screen flicker?

    Problems:
    1) I have 1 dead pixel on my iPod Touch and it's very annoying as it sticks out because the entire screen is black, and there is just this dot of light
    2) I sometimes use my iPod Touch in the dark, so this means that I keep the contrast at the lowest level, as it being too bright hurts my eyes. The problem with this is that the screen flickers between contrasts slightly and it ends up making me feel dizzy.
    I've tried turning the auto brightness option to off to prevent the above, but it doesn't make any difference. I've also tried turning the contrast slightly up too, but still it flickers slightly.
    Any advice?
    Thanks

    The warranty will cover a dead pixel and the flickering screen. But before we get drastic, let's do some troubleshooting. Try a hard reset by holding the home and sleep/wake button at the same time until the Apple logo appears on screen. Skip the slide to power off screen.

  • Exporting sequence from Final Cut Pro 7, some clips are pixellated and bad quality, does this have anything to do with the fact that I changed those clips speed?

    Hello,
    Bit of a beginner using Final Cut Pro 7
    Am currently trying to export a sequence using quicktime conversion.  Sequence has various filters and effects over it and when I export it some of the clips are pixellated and appear to have not exported correctly.  From what I can gather the affected clips have either been slowed down or made faster.  I am wondering whether this is the reason they have not exported correctly
    Any help would be appreciated
    Cheers

    More information needed.
    Codec of material?
    Sequence settings? (codec)
    fwiw - do not use quicktime conversion. Use Export Quicktime with Current Settings enabled then do any format conversions in Compressor.
    x

  • My refurbished rMBP 15" has a stuck (white) pixel and is still under the 1 year limited warranty, can/will Apple repair it if I go to an Apple Store?

    Hi, my refurbished rMBP 15" has a stuck (white) pixel and is still under the 1 year limited warranty, can/will Apple repair it if I go to an Apple Store?
    I just discovered today that my MacBook has a "stuck" pixel. I read that the display has to have at least 5 dead/stuck pixels else Apple is not going to repair it, is it true? My warranty expires in 1 month so I can't really wait for 4 more pixels to die or get stuck.
    Temporary fix:
    I know that this is something I can't really repair myself, but I tried some things such as changing the display resolution to it's "Full" 2880x1800 resolution and It actually reduced the size of the stuck pixel.
    Thank You,
    Etienne
    MacBook Pro 15-inch (Mid 2012) with Retina display (2.3Ghz Intel Core i7, 8GB RAM, 256GB SSD, GT650M)
    Running Mac OS X 10.10

    Hello etienne255,
    After reviewing your post, I have located an article that can help with questions concerning pixel anomalies:
    About LCD display pixel anomalies for Apple products released before 2010 - Apple Support
    If you suspect your display contains a high number of pixel anomalies, take your Apple product to an Apple Authorized Service Provider for closer examination.
    Thank you for contributing to Apple Support Communities.
    Cheers,
    BobbyD

  • My iphone 4s suddenly displays images from Yahoo, Google, and Flickr at low resolution. The camera on my phone works fine, but any web related photo content is now pixelated and low res, what's the deal?

    My iphone 4s suddenly displays images from Yahoo, Google, and Flickr at a low resolution. I have IOS 7.0.4. My phone camera works fine, but any web based photo content from Safari, Yahoo images, Google images, and Flickr all come in pixelated and low res. What's the deal?

    It happened to me but later I figured out that cellular signal was not that great and so the Internet was very slow. It took me about 2 minutes to get the full resolution picuture on either of the app you've described. Try to get faster internet either by wifi or good signal and then check.

  • Why is everything pixelated and blurry in CS6?

    Hi,
    A few months ago I installed the trial versions of Adobe Indesign, Illustrator and Photoshop on my MacBookPro.  After they expired I purchased the standard student edition and used the provided key number to unlock the full versions.  However, everything (including the sample fonts list, icons and opening menu) are pixelated and blurry.  As a design student, it is incredibly distracting to see font that isn't smooth like it should be on a retina display...
    I've updated Indesign to version 8.0.1 but to no avail.  What could be wrong and how might I solve this problem?
    Thank you,
    Cuong

    @Tereyn "Since the originator has not stated that the software was tested on a non-retina display how can he/she or you be sure the display is the origin of the problem?"
    Yes he does say that he is using a retina display.. Did you even read the post.
    "As a design student, it is incredibly distracting to see font that isn't smooth like it should be on a retina display..."
    If you have another problem why don't you create your own post?
    It's still annoying for me that there isn't a retina fix yet and it's been a few years now. It's just a few menu icons. Fix the retina issue please!

  • PRE 9 - Photos - recommendation for pixel and resolution setting

    I would like to integrate photos in between video segments, as well as on the actual video.  Before bringing these photos into PRE 9, what should I resize the photos to (pixels and resolution). I will be using Premiere Elements to resize the photos.   I'm burning a HD DVD at 1920x1080 pixels.
    Thank you.

    I agree with Neale. Scaling the images in PS/PSE, to just the pixel x pixel dimensions that you need will do two things for you: get you the best quality, and eliminate excess overhead, when pushing a bunch of unused pixels around. This ARTICLE will give you more. Note: it was started, before HD took over the market, so just read all of the 720 x 480 dimensions as 1920 x 1080 (in your case). I went on to add comments on HD, but some get confused, when they see the 720 x 480 in the beginning.
    Good luck,
    Hunt

  • Ichat Video Quality pixelated and very delayed with friend on a Dell

    I am on a Imac and have Airport express, but when I chat with my friend on a Dell, my video is pixelated and delayed. I talk with other friends on PC's and the quality is fine.

    Add me to this problem. My powerbook G4 (10.4.10) can initiate with a mini G4 with isight (10.5.2) and be perfect in sync with video and audio. But if the mini initiates the chat a very long delay happens between voice and video. I also have an Ibook with 10.4.11 and when chatting with PB G4 are perfect, this applies to an intel imac with 10.5 only, ichat works fine. I think Ichat got affected with 10.5.1 or 10.5.2. I did noticed that if I open QT pro and make a recording(on mini), the actual caption is delayed but play back is ok. I have been playing with the QT preferences but does not seem to work. I saw there is a new update 10.5.3, and it includes so ichats update. Will keep posting. Pedro PS this is all in my home network. TWCNYC with 9600 kbps download and 488 kbps upload.

  • IDVD Burning Problem...Pixels and Vibrating Image!!!!!

    I have a 104 minute project that I'm burning in iDVD (exported from FCP Pro). Every time I play it back after burning, I notice the same scene (about midway through the project) is pixelated and the picture "vibrates" like crazy. I've already re-burned it about 5 different times, and the same thing happens with each disc.
    Then, I've isolated the problem by only burning that particular scene onto a disc...no pixels, no "vibrating".
    I then went back and re-burned the entire film again...same pixels, same problem in the same scene. What's going on?
    I'm using Taiyo Yuden 8x DVD-R discs...I've set the burning speed to Professional Quality and the burn speed to 8x...I've chosen a 6.0 them (Road Trip)...and, Im burning directly to the DVD-R disc.
    Why am I getting this strange problem? Please help!!!!

    Well, you're using highly regarded DVD-Rs. I would create a disk image and burn it at 4X or slower. You can test the disk image to see if the problems exist before burning.
    Suggest you create a disc image and then burn the DVD. File/Save as Disc Image...
    This will isolate any encoding/burning issues you may encounter. Once the disc image is created, double-click the .img and burn the virtual disc that should appear on your desktop, using Toast to burn the DVD. Disk Utility to burn the .img file. Usually, you can select a burning speed in Disk Utility.
    There are variations to this process based on which OS X you are using...
    Open Disk Utility (in Utilities folder in Applications folder), click on the virtual disc (maybe the .img) in the left-hand window. Click the Burn icon. A new window should drop down and your SuperDrive tray will open after clicking the Burn icon. Insert a recordable DVD. (Verbatim DVD-R preferred by me.) Click the Close button. Wait. Select a burn speed. If you hold your mouse cursor over the pop-up it says: "Select a slower speed to work around burn failures," so select 4x or slower for best results. Then click the Burn button.
    -->If the virtual disk selection won't allow you to click the Burn icon, use the .img file instead. This may have changed in 10.3.9 and did change in Tiger.
    Also, you can use DVD Player to play the virtual disk to check your iDVD project before burning to DVD. Launch DVD Player. File/Open VIDEO_TS (Open DVD Media... in Player 4.6). Find the VIDEO_TS folder and open that. (The audio folder is for DVD-Audio disks.)
    http://docs.info.apple.com/article.html?artnum=93006

  • Export via Quick Time ends up being pixelated and poor quality

    I shoot my student film on an Arri S camera with 16mm color stock. I got my film back to me from the school on a DV tape and imported it into FCP HD on my camcorder. When I went to export it onto a DVD for my actors, the film looks horrible! The blacks are really pixelated and the colors aren't as crisp as they were on film. I was told that it should look the same because we made the movie on better equipment and FCP won't lessen that, but at the same time FCP can't make poor quality work any better. Can someone tell me how to export my film without losing the 16mm quality. I don't want it to look digital, I spent a lot to get the real film stock. Thanks!

    1- The film is 6 minutes long
    2- I don't know where to find out about the bit rates
    3- The audio is simple, just 48 khz stereo.
    When using DV format, what's the difference in DV, DVPRO, etc.?
    The movie was filmed 24 fps, but then put onto a dv tape for me, so I assume they transferred it at 29.97 fps. Should I now use NTSC or stick to PAL? Basically, anymore compression makes the film look really bad and unusable for festivals, which ultimately was the whole purpose of my blood, sweat, and tears behind this film.
    Thanks for all your help and any more questions you need answered to solve this problem I'd be more than happy to answer.

  • Displaying both pixel and inch dimesnsion in the Info Panel

    Anybody else constantly switching the Info Panel from displaying inches to pixels and vice versa?
    How to avoid having to do this? I either want to see one or the other, somtimes being able to see both simultaneously would be nice. While dragging out Rectangular Marquees, doing Transforms, etc.

    I actually installed the trial of Flash Builder but did not get far before it expired, so I can only share Silkrooster’s suspicion that it may be possible.
    Maybe you should ask over at
    http://forums.adobe.com/community/flash_builder

  • What's the best way to convert between pixels and device-independent units?

    WHAT I HAVE:
    Visual Basic 2010, .NET 4.0, WinForms
    WHAT I NEED:
    I need a way to convert back and forth between device-dependent units (i.e., pixels) and
    device-independent units (i.e., inches, centimeters, points). The VB6Compatibility namespace has TwipsPerPixel methods, but I figure there's got to be a more elegant way (especially since my program didn't start in VB6).
    Robert Gustafson

    "Dots-per-inch" means "pixels-per-inch", right? If I'm right, then
    XPixels = Graphics.DpiX * XInches : YPixels = Graphics.DpiY * YInches
    and, conversely,
    XInches = XPixels / Graphics.DpiX : YInches = YPixels / Graphics.DpiY
    Is that correct?
    (PS. Why not just tell me about the DpiX and DpiY properties, rather than making me click a link?)
    Robert Gustafson

Maybe you are looking for