Strange Black rectangle in JPanel

I have created a program that uses 2 classes a driver class and a resource class. However, when I run the driver class, a window comes up with a strange black rectangle. To make things easier to understand, here are my two classes.
Driver Class:
   import javax.swing.JFrame;
   public class ProjectDriver
      public static void main(String[] args)
         JFrame frame = new JFrame("Project");
         frame.setSize(1000, 700);
         frame.setLocation(0, 0);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setContentPane(new ProjectPanelMine());
         frame.setVisible(true);
   }Resource class:
   import javax.swing.*;
   import java.awt.*;
   import javax.swing.event.*;
   import java.awt.image.*;
   import java.awt.event.*;
    public class ProjectPanelMine extends JPanel{
      private int grow = (int)(Math.random() * 4);
      private static final ImageIcon EUCLID = new ImageIcon("euclid.png");
      private BufferedImage myImage;
      private Graphics2D myBuffer;
      private Timer t1,t2,t3;
      private int xpoints[]= {(int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000)};
      private int ypoints[]={(int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000)};
      private int wpoints[]= {(int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000)};
      private int zpoints[]={(int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000),(int)(Math.random()*1000)};
       public ProjectPanelMine(){
         myImage = new BufferedImage(1000,700, BufferedImage.TYPE_INT_RGB);
         myBuffer = (Graphics2D)myImage.getGraphics();
         t1 = new Timer(5, new Listener1());
         t2 = new Timer(3000, new Listener2());
         t2 = new Timer(5000, new Listener3());
         t1.start();
       public class Listener1 implements ActionListener{
          public void actionPerformed(ActionEvent event){
            if (Math.random()>.7){
               grow = (int)(Math.random() * 4);
                         if(Math.random() > .5)
                         grow = -grow;
                         System.out.println(grow);
            myBuffer.setColor(Color.blue);
            myBuffer.drawRect(0,0,1000,700);
            myBuffer.drawImage(EUCLID.getImage(), 10, 10,152,188, null);
            myBuffer.setStroke(new BasicStroke(3.0f));
            xpoints[0] += grow; xpoints[0] += grow; xpoints[1] += grow;
            ypoints[0] += grow; ypoints[0] += grow; ypoints[1] += grow;
            wpoints[0] += grow; wpoints[0] += grow; wpoints[1] += grow; wpoints[2] += grow;
            zpoints[0] += grow; zpoints[0] += grow; zpoints[1] += grow; zpoints[2] += grow;
                myBuffer.drawPolygon(xpoints, ypoints,3);
            myBuffer.drawPolygon(wpoints, zpoints,4);
            repaint();
       public class Listener2 implements ActionListener{
          public void actionPerformed(ActionEvent event){
       public class Listener3 implements ActionListener{
          public void actionPerformed(ActionEvent event){
       public void paintComponent(Graphics g){
         g.drawImage(myImage, 0,0,getWidth(),getHeight(), null);
   }And the result, again, is a frame with a black rectangle filling up most of my screen that I don't want.
So, what is the problem?
Thanks in advance,
Eric

However, when I run the driver class, a window comes up with a strange black rectangleBecause a newly created image starts off as black. The blue color fills in as you consecutively draw polygons.
I would have a thin line of white around the strange black box. Because you did a drawRect instead of a fillRect.

Similar Messages

  • [SOLVED] Opera + Youtube + Flashplugin = Black Rectangle

    Hi guys,
    I just encountered a problem with Youtube, Opera and the Flashplugin.
    I updated my System this afternoon and pacman installed the
    newest version of Opera. Till this point everything was fine. After the
    update the flashplugin seems to work only on channels of youtube users,
    on the normal 'white' youtube layout the flashplayer didn't appear.
    There's just a black rectangle where the player should be.
    Clicking doesn't lead to anything than showing up opera's dialog.
    It seems that the plugin crashed due to the layout of the site?!?
    Here's the /var/log/pacman.log
    [2013-01-30 17:56] starting full system upgrade
    [2013-01-30 18:02] upgraded blender (6:2.65a-4 -> 6:2.65a-5)
    [2013-01-30 18:02] upgraded git (1.8.1.1-1 -> 1.8.1.2-1)
    [2013-01-30 18:02] upgraded gnupg (2.0.19-4 -> 2.0.19-5)
    [2013-01-30 18:02] upgraded libwbclient (3.6.11-3 -> 3.6.11-4)
    [2013-01-30 18:02] upgraded man-pages (3.45-1 -> 3.46-1)
    [2013-01-30 18:02] upgraded mlt (0.8.6-1 -> 0.8.8-1)
    [2013-01-30 18:02] upgraded mlt-python-bindings (0.8.6-1 -> 0.8.8-1)
    [2013-01-30 18:02] upgraded opera (12.12.1707-1 -> 12.13.1734-1)
    [2013-01-30 18:02] upgraded python2-imaging (1.1.7-7 -> 1.1.7-8)
    [2013-01-30 18:02] upgraded reiserfsprogs (3.6.21-4 -> 3.6.22-1)
    [2013-01-30 18:02] upgraded smbclient (3.6.11-3 -> 3.6.11-4)
    The Version of Flashplugin:
    flashplugin-11.2.202.261-1
    I also tried to install firefox and there is no problem at all.
    I deactived the hardware acceleration for opera. I read that this should
    solve the problem, but obviously it didn't ...
    Thank you for any kind of advice
    TK
    Last edited by TK (2013-02-07 16:32:08)

    Hi guys,
    sorry for the last response, I wasn't at home over the weekend and there was no way
    to test the suggestions.
    awbs wrote:Check to make sure when your on YouTube opera is identifying itself as Opera and not another internet browser by right clicking the youtube page > Edit Site Preferences > Network > Browser Identification > "Identify as Opera".
    Checked that, and it's activated.
    There are no extensions which could affect the performance or the behavior of opera.
    And I don't use qtcurve.
    It's strange, it seems that after the update opera broke but there are no
    other post from other users. Installed firefox and it worked, same for dwb.
    Anybody other ideas?
    Thanks for the great support
    Last edited by TK (2013-02-04 15:56:02)

  • When drawing with polygon tool, a solid black rectangle appears??

    When I use the polygon tool to draw, a mysterious black rectangle appears underneath, and grows with my cursor movement, obscurring whatever is underneath. The black shape has nothing to do with the shape I'm creating. I am tracing boundary locations on a map, for example, and the black shape blocks out the lines I'm trying to trace, if my opacity is set at 100%.  It mimics the opacity I'm using to draw.  I never saw this in AA7.  Why would anyone want this function, and is there a way to turn it off?

    Hey leonieDF
    Thanks for your reply. I am exporting edited versions - export seems to work OK when exporting originals. But all my images are edited a bit, even if just simple cropping etc.
    I tried adjusting the color sync profile as you suggested but this didn't help. I also adjusted the gamma and watermark and again, no change.
    It seems like I have some kind of bug or something within Aperture, because it is doing all kind of strange things, like now eny time I edit a photo at all it appears solid black in my "browse" view (but OK when I double click it). Similarly, when I duplicate a photo it does random funky stuff to the photo in browse view (from being solid black, to solid red, to appeairng to have some random color filter, to appearing like static from static TV). These issues are all secondary though from the main issue of not being able to export images, since I have a friends wedding photos I am trying to get out to them!
    Any other ideas of what might be causing this?
    Thanks for your help!

  • Black rectangles after 10.4.5 Upgrade?

    Help! I just did the automatic update to 10.4.5 and now I have black rectangles around many of the field windows, desktop icons, etc. It's especially annoying while using Quark.
    If I open a window box, the black rectangle superimposes itself over my layout.
    Is anyone else having the same problem?
    Can I uninstall 10.4.5 and go back to the former version?
    G5   Mac OS X (10.4.5)  

    katarina,
    Welcome to Apple Discussions.
    Mac OS X 10.4: Computer speaks unexpectedly, or a black box unexpectedly appears around a file, folder, or other item: If a black outline (or box) unexpectedly appears around a file, folder, icon, button, or other item when you click it, VoiceOver is probably enabled. Your computer might also be unexpectedly speaking items that you click on.
    If you don't want VoiceOver on, turn it off in the Universal Access preference pane, or by pressing Command-F5 (or Fn-Command-F5 if you have an iBook or PowerBook).;~)

  • B&W G3 gets Black Rectangle on Boot - Hangs

    My B&W G3 will not boot OS X 10.4 anymore. It worked fine before. Now when it boots I get the Apple logo then I get a solid black rectangle in the middle of the screen and it hanges.
    I put the 10.4 DVD in the drive and pressed C on boot. It starts to boot from the DVD then bang I get the solid black rectangle.
    I took all the cards out except the video card. I droped the RAM to 1 stick (256 MB). No help.
    It is booting from an Apple 6 GB IDE drive.
    It is a revision 1 board.
    I replaced the battery, pressed the CUDA ect.
    I put in OS 9.2 CD and tried to boot from it as well. No luck. It hangs as well.
    No network is connected.
    I tried USB keyboard & Mouse and ADB. No help.
    Why am I getting the solid black rectangle on the screen after the Apple logo?
    Thanks!
    Tony

    Will it boot in Safe Mode? See
    What is Safe Boot, Safe Mode? (Mac OS X)
    http://docs.info.apple.com/article.html?artnum=107392
    Also *Resolve startup issues and perform disk maintenance with Disk Utility and fsck*
    http://docs.info.apple.com/article.html?artnum=106214
     Cheers, Tom

  • Why are iCal alarms coming up with a black rectangle?

    Why are iCal alarms coming up with a black rectangle? I'm running 10.3.9 and iCal v. 1.5.2. This started after I did software updates this week.
    iMac   Mac OS X (10.3.9)  

    I solved it in my case by going to System Preferences>Internet & Network>QuickTime>Advanced, then clicking the checkbox to Enable Flash. I also had to quit and restart iCal.
    I think the Quicktime715 update that recently came out had something to do with it.
    It seems that the black box is supposed to be a movie of a vibrating alarm clock, and apparently that movie uses Flash.
    I hope this fix works for you too.

  • Viewing PDF in preview, black rectangles around links

    I've created a PDF in Microsoft Word 7.0, the PDF looks great in all applications except Preview on a mac. It would seem that all links in the PDF have a black rectangle around them, this only seems to be an issue in Preview, is this a known issue? As near as I can tell, no other applications seem to be interpreting these links as having boxes around them, this would lead me to believe that the problem does not lay with how the PDF was created.

    Hi,
    Can you try any other PDF file in Preview (not the one you created)
    Dimaxum

  • Does anyone know what the black rectangle about the receiver on the 4S is for?  I want to put a screen cover on my phone but don't know if that should be covered or not.

    Does anyone know what the black rectangle about the receiver on the 4S is for?  I want to put a screen cover on my phone but don't know if that should be covered or not.

    Refer to this article under section 4: Verify that the Apple Mobile Device USB Driver is installed
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538

  • Strange Black Blob on the screen

    Hello,
    I have an Ipod Nano 5G. Recently A strange black blob started appearing on my screen. It obscures the screen behind where it is, and it sometimes changes places randomly, but only horizontally. Also, I can make it walk by pressing it lightly, but it doesn't leave the screen. If I watch it from a sharp angle it shines. If the screen is off, there are some strange colors around where it is.
    The warranty is already gone, and it doesn't bother me enough for me to pay to fix it. Also, I would like more to understand what that is than to fix it.

    Since the 5th Generation Nano was released last September how could your 1 year warranty be expired?
    What you are seeing is damage from a broken LCD screen. It was most likely flexed (like sitting down with it in your front pocket) or dropped, or something dropped on it.
    Your warranty is void if it is due to accidental damage.

  • Black rectangle around curser

    Hi,
    Straight after I finished installing the latest updtaes that came to me automatically there appeared on screen a black rectangle outline about 2 inches long by 1 1/2 inches high around my curser. it moves as I move the curser.
    I don't like it as it is distracting but have no idea how it got there and no idea how to get rid if it.
    I do hope someone can help me.
    Thanks
    Patricia
    MacBook    

    Follow the steps listed here:
    http://docs.info.apple.com/article.html?artnum=304496

  • Black rectangle follows cursor

    I just updated to 10.4.8 and when the computer restarted I now have a black rectangle that is centered on my cursor and follows the cursor around the screen. It is just the black outline of a rectangle. Any ideas?

    Hi, kmroxo.
    This is a bug in the Mac OS X 10.4.8 update. For details and the workaround, see my "Black rectangle appears after Mac OS X 10.4.8 Update" FAQ.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X
    Note: The information provided in the link(s) above is freely available. However, because I own The X Lab™, a commercial Web site to which some of these links point, the Apple Discussions Terms of Use require I include the following disclosure statement with this post:
    I may receive some form of compensation, financial or otherwise, from my recommendation or link.

  • Black rectangle on startup

    I removed all the cables from the back of my Blue and White G4 (10.4.11) to do a spot of spring cleaning. On trying to restart I get a chime, the apple logo with spinning ball, then a black rectangle appears and the ball stops spinning
    I have:-
    1. zapped the PRAM
    2. started from the install disc and repaired permissions using Disc Utility
    3. started in Safe Mode and run TechTools Deluxe
    Any help would be much appreciated.
    Thanks
    Tony

    Hi-
    I assume it may also be accompanied by a grayish screen.
    This would be a kernel panic:
    http://support.apple.com/kb/HT1392
    Since you just did some plugging/unplugging, I would remove all cables again, open the tower and reseat the graphics card.
    Reconnect monitor, keyboard and mouse only, and try starting again.
    If still a no go, I would open it once again, and reseat the RAM.
    While you're in there, make sure all other connections are tight.
    Reconnect and try starting.
    If that doesn't do it, you will have to look deeper:
    http://www.thexlab.com/faqs/kernelpanics.html

  • Black rectangle floating with my cursor

    I just installed Mountain Lion and I now have a black rectangle that floats around my cursor. I've check all the accessability settings and nothing is turned on and I can't seem how to make it go away.

    Solution here  https://discussions.apple.com/message/19020521#19020521

  • Black rectangle blocking iPad screen

    Recently when my iPad died and I went to charge it, it had a black rectangle (with a few colourful lines through it) appearing on the screen. The rectangle blocks all of the content behind it. I can still use the iPad but this huge rectangle takes up about 1/3 of the screen, right in the middle. Does anyone know what this could be?

    try triple clicking the home button
    Settings.General>Accessibility

  • Black rectangle

    How can I get rid of the black rectangle that is usually on the back page arrow or right now it is around the apple at the top of the page? Sometimes it will go around half the stuff on the page. If safari is not open it will go around an icon on the desk top. I have tried restoring my defaults on the mouse and in system preferences.

    Hi
    It sounds like you've accidentally turned on the Voiceover feature. Go into System Preferences - Universal Access, and turn off Voiceover if it's on.
    The keyboard shortcut is cmd-F5 so it's not too difficult to hit it by mistake.
    Matt

Maybe you are looking for