Weird Graphics2D situation encountered!!! please try to see this

hello all! i've been doing an application which will display a window and is supposedly to paint its background with the GradientPaint method. i tried putting the method in a thread because i'm planning to display a moving text using the drawString in the future.
i've encountered this wierd problem: there are times when the frame gets painted and there are times when it's not. it's more often that the frame isn't painted. and not all of the time when it is painted that the whole frame is filled with the GradientPaint.
whenever the frame isn't painted "&&&&&&&&&&&&" from System.out.println("&&&&&&&&&&&&"); doesn't show up.
here's my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.border.*;
import java.awt.geom.*;
public class Test implements ActionListener {
public static void main(String[] args) {
f = new TestFrame();
f.show();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
     FlowLayout fl = new FlowLayout(0,30,30);
jd.setBounds(400,250,300,200);
jd.setResizable(false);
jd.getContentPane().setLayout(new FlowLayout(0,30,30));
l.setFont(new Font("Serif", Font.PLAIN, 18));
l.setLocation(0,0);
l.setFocusable(false);
jd.getContentPane().add(l);
     yes.setPreferredSize(new Dimension(100,50));
yes.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
yes.setFont(new Font("Serif", Font.PLAIN, 18));
yes.addKeyListener(new KeyHandler());
yes.addActionListener(mp);
InputMap map = yes.getInputMap();
if (map != null){
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,false), "pressed");
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,true), "released");
jd.getContentPane().add(yes);
no.setPreferredSize(new Dimension(100,50));
no.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
no.setFont(new Font("Serif", Font.PLAIN, 18));
no.addKeyListener(new KeyHandler());
no.addActionListener(mp);
InputMap map1 = no.getInputMap();
if (map1 != null){
map1.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,false), "pressed");
map1.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,true), "released");
jd.getContentPane().add(no);
     jd.show();
public void actionPerformed(ActionEvent e) {
String bname = e.getActionCommand();
if(bname=="Yes") {
System.exit(0);
jd.dispose();
static class KeyHandler extends KeyAdapter {
public void keyReleased(KeyEvent e) {     
int keycode = e.getKeyCode();
if(keycode==10 && yes.hasFocus()==true) {
System.exit(0);
static JFrame f;
static Test t = new Test();
static JDialog jd = new JDialog(f,"TEST");
static JLabel l = new JLabel("Would you like to close TEST?");
static JButton yes = new JButton("Yes");
static JButton no = new JButton("No");
class TestFrame extends JFrame {
public TestFrame() {
setBounds(wndSize.width/4,wndSize.height/4,wndSize.width/2,wndSize.height/2);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
setResizable(false);
setTitle("test");
canvas = new JPanel();
getContentPane().add(canvas, "Center");
MoveThread mt = new MoveThread(canvas);
mt.start();
Toolkit theKit = getToolkit();
Dimension wndSize = theKit.getScreenSize();
Area area = new Area(new Rectangle2D.Double(0,0,510,345));
private JPanel canvas;
class MoveThread extends Thread {
public MoveThread(JPanel canvas) {
c = canvas;
public void paintComponent() {
Graphics2D g2 = (Graphics2D)c.getGraphics();
g2.setPaint(new GradientPaint(0,0,Color.green,510,345,Color.white));
System.out.println("&&&&&&&&&&&&");
g2.fill(area);
g2.dispose();
public void run() {
try {
paintComponent();
sleep(5);
} catch(Exception e) { }
private JPanel c = new JPanel();
Area area = new Area(new Rectangle2D.Double(0,0,510,345));
thanks for taking some time to look at this problem!
cheers, deo

Hi,
First, if you expect your paintComponent() method to get called by Swing then it should have a Graphics argument.
Second, it is normally a bad idea to get a Graphics from a component. You should use the one provided by the paintComponent() method.
Third, it is normally a bad idea to update anything in the GUI in a separate thread. Update your model but use the SwingUtilities.invokeLater() function to update your view of the data.
Forth, consider double buffering - draw your graphics onto an image and then use the paintComponent(Graphics g) to paint the image to the display.
Roger

Similar Messages

  • Firefox 3.6.3 wont play embedded youtube videos. It comes up with "an error occured please try again later. this happens all the time

    Firefox 3.6.3 wont play embedded youtube videos. It comes up with "an error occurred please try again later. this happens all the time. If you click to go to youtube the clip plays.
    == This happened ==
    Every time Firefox opened

    I was having the same issue up until I found a solution myself a few minutes ago. If you have "Accept Third Party Cookies" un-checked it will not allow the embedded "Third party" youtube videos to load. You can either Check the box to allow third party cookies or add an exception to allow youtube.com WITHOUT the www. You just want it to be Youtube.Com.
    To do so just go to Tools: Options: Privacy: Exceptions: Type in Youtube.com and click Allow. Then click Close and OK. It should start working immediately.

  • HT1551 When I am trying to access radio stations under "computer" I am now receiving a message that "an error occurred", please try later.  This is now true for all of the listed stations.  how can i fix this?

    When I try to use the radio feature under "computer" I am now receiving a message that "an error occurred, please try later".  This is now affecting all of the stations and does not go away when I try later.  I have reset the password but am still getting the message.  Any suggestions?

    From the Safari menu bar, select
    Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data
    and confirm. Test.

  • Hello. I try instal iTunes 10.5.0.142. Wehn I try I see this ,, There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Concat your support personnel or package vendor." What I have to do ?

    Hello. I try instal iTunes 10.5.0.142. Wehn I try I see this ,, There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Concat your support personnel or package vendor." What I have to do ?

    Hi
    You will need to uninstall all traces of previous iTunes installations any all associated items such as bonjour, mobile device thingy, apple software updated etc.
    Bonjour and iTunes can be uninstalled using the windows program uninstalled but for everything else best to use a separate installer program that also checks the registry for associated components as you will need to remove these too.
    Once you have removed all tracesofeverything apple related ( doesn't seem to matter about QuickTime) you can try to reinstall iTunes 10.5 and hopefully it should install without any problems. I had the same problem as you and once I did all this every went through fine, seems that there is something in the old versions, the software updated part I think which seems to be blocking certain items in the latest version.
    Good luck

  • I'm unable to send crash reports to Apple.  Message says "Submission failed Please try again later"  This has been happening for about 3 weeks.

    I'm unable to send crash reports to Apple. 
    Message says "Submission failed Please try again later" 
    This has been happening for about 3 weeks. 
    How do I send crash reports?

    If you're actually using Mac OS X v10.5.8, as your profile says, you're wasting your time trying to submit crash reports to Apple.

  • TS1702 Has any one had trouble getting or giving lives in candy crush...I keep getting a message that says an error has occurred, please try later.  This has been going on for two days! Can't move cause I need to be unlocked, can't ask friends  because of

    Keep getting message"error has occurred, please try again later". When i try to send lives or ask friends for lives.  Can't play cause I need to be unlocked.  Help!

    Simple...
    http://www.apple.com/uk/support/mac/app-store/contact/

  • HT203425 the recent update for IPhoto (9.5.1) will not install on my Air. The error message comes back and says there is a problem with the App store. Please try later.  This has gone on for several days.  The update installed fine on my IMac.

    I have tried installing from the App sotre updates and also the softwarre updates  - I receive the same message.

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Select
    /var/log ▹ install.log
    from the hierarchical list on the left. If you don't see that list, select
    View ▹ Show Log List
    from the menu bar. Then select the messages from the last installation or update attempt, starting from the time when you initiated it. If you're not sure when that was, start over and note the time. Copy them to the Clipboard by pressing the key combination command-C. Paste into a reply to this message (command-V).
    If there are runs of repeated messages, post only one example of each. Don’t post many repetitions of the same message.
    When posting a log extract, be selective. Don't post more than is requested.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Edit it out by search-and-replace in a text editor before posting.

  • TouchSmart Web App is not Responding - Please Try Again Later - THIS FORUM DOES NOT RESPOND EITHER

    I have posted this issue before.
    The Web Apps services DOES NOT WORK on the HP Envy printer.
    Nobody at HP s bothered or concerned about this!!!!!
    I have just spent £250.00 on a printer that does not work correctly.
    Everything else works i.e. airprint, wireless printing, email printing SO DO NOT ASK METO DISABLE/RE-ENABLE SERVICES.
    I wonder how many times it will take for me to post this to get a response.
    Not Happy HP.
    This question was solved.
    View Solution.

    Hello annesley,
    I apologize that no one has gotten back to you but I'd like to explore your issue a little mroe to see if we cannot get this problem resolved for you.
    If you could provide me with a few bits of information, I'd greatly appreciate it.
    1. Please print a printer status report from the front panel of the Printer. To do this, on the front panel, press the Tools button (looks like a wrench) > then Printer Status Report. Once this page prints out, underneath the Product Information Header, there should be a field for Firmware Version. Please report to us which version you have.
    2. If you could inform us as to who you used for your Internet Service, we'd greatlly appreciate it. An ISP is somebody like Qwest, Comcast, CableOne, Timewarner, Cox, and etc.
    3. Also your router make and model would help as well.
    This will help narrow down some possible reasons for your problem with the Web Apps portion of our Web Services.
    M. Moss
    Click on the BLUE KUDOS button on the left to say "Thanks"
    If my reply solves your issue, please mark it as solved to help fellow users fix their similar issues!
    Though I am an HP Employee, ALL of my posts express MY opinion, and not of HP, whatsoever.

  • Keep getting msg "Cannot start Mobile Hotspot due to temporary network problem. Please try again later"  This has been happening for the last 3 days!

    Has anyone seen this problem?  I need to have this function working as part of my job and I'm going to be out of reach of hotspots starting tomorrow.  It's critical I get this working asap.
    Thanks

        WCBM,
    We want to make sure your Mobile hotspot is fully functional! Are you having any other data issues with your device? Make sure your data services are on by going to options>Network and Connections>Mobile Network>Data Services (ON).
    LindseyT_VZW
    Follow us on Twitter @VZWSupport

  • HT201407 iMessage "unable to activate, please try again".    Whenever I go to activate imessage is says waiting for activation and then about 5 mins later says activation unsuccessful, please try again. This is driving me mad! It's been 2 days now!!

    Lease help me to activate imessage. I now have iPhone 5s and can't activate imessage. I've tried all the normal stuff but nothing is working

    i had this problem with my iphone 5c and sorted it contacting apple.
    have you tried resetting the network settings? it doesnt delete anything and should work. if it then changes to "waiting for activation", instead of the error message, then leave it for 24 hours (leaving your phone and wifi on) and it should activate and work.
    for me, this didnt work after 24 hours. i then backed up my phone and reset it and set it up as a new iphone then restored it using my backup from the computer and it now works

  • Getting error message " Sync encountered an error while connecting. Missing account name. please try again.

    When trying sync I am getting error message " Sync encountered an error while connecting, Missing account name. Please try again"

    See [[forums/contributors/707663]]

  • Blackberry app world keeps saying 'AN ERROR HAS OCCURED. PLEASE TRY AGAIN LATER'

    Hi there
    I have a blackberry 8520 and everytime I try and download something from the app world it keeps giving me the error message of ' an error has occured. Please try again later' this started happening when I upgraded my app world.
    I have rebooted my phone, restarted it and made sure its fully charged. This has been going on since saturday (when I upgraded my app world)
    I cannot download any apps because of this problem. And when I try I keep getting the Error msg!!!!!
    Please help as I really enjoy the phone I just can't download any apps!!!!!!
    Thanx

    Hi there!
    I suggest the following steps, in order, even if they seem redundant to what you have already tried (steps 1 and 2 each should result in a message coming to your BB):
    1) Register HRTHomescreen > Options > Advanced Options > Host Routing Table > (it does not matter which line is current) > Register Now
    2) Resend Service BooksKB02830 Send the service books for the BlackBerry Internet Service
    3) Batt Pull RebootAnytime random strange behavior or sluggishness creeps in, the first thing to do is a battery pop reboot. With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes. See if things have returned to good operation. Like all computing devices, BB's suffer from memory leaks and such...with a hard reboot being the best cure.
    Hopefully that will get things going again for you! Good luck and let us know! 

  • TS3297 "itunes store is temporarily unavailable.  please try again later"  I have gotton this erroe since yesterday and no matter what steps I follow, same error shows up.  what to do ???????

    "Itunes store is temporarily unavailable.  Please try agin later"  This is all I am getting since yesterday.  All I am trying to do is buy a song.  Tried different stops to no avail. 

    Hello fedupwiththisgovno,
    I found a couple of articles that might help with the issue you are experiencing with the iTunes Store.
    If you are getting a white screen when accessing the iTunes Store, I recommend reviewing this article:
    Apple software on Windows: May see performance issues and blank iTunes Store
    http://support.apple.com/kb/TS4123
    If you are still not able to access the store or are getting a different error than just a white screen, I recommend the following article:
    Can't connect to the iTunes Store
    http://support.apple.com/kb/TS1368
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Javax.mail.MessagingException: 451 4.3.2 Please try again later

    Hi,
    Can any one help out to fix following problem.
    exception occurred :Sending failed;
    nested exception is:
         javax.mail.MessagingException: 451 4.3.2 Please try again later

    If this is generated by the server at random, I do not think javamail can not do anything about it. You can add retry logic in your code or figure out why server is giving this error (configuration issue? need to increase any parameters on the server side?).

  • The server was unable to save the form at this time. Please try again

    Having created a new custom list (even with only a text field) I am unable add new items to the list - the error message is Unexpected
    response from server. The status code of response is '0'. The status text of response is ''. when in 'quick edit'.
    If I try to add or modify an item in the list by clicking 'add new item' I get "The
    server was unable to save the form at this time. Please try again."
    I have restarted the Sharepoint Search Host Controller server but to no avail. I have 24Gb RAM for this server so it's not a
    memory issue (8Gb available). I have also tried from various browsers including Chrome and Safari - still the same error message.
    This error only occurs on lists. I can edit document properties in a library and have no problems with calendar entries.
    There are no entries in the event viewer, so where do I need to begin looking to find out what is (or rather is not) happening?

    One thing I noticed in SP 2013 is that if your list has unique permissions and a user/group has permissions only on that list and has limited or no access at the site level, then you run into this error: "The server was unable to save the form at this time.
    Please try again."
    This can be resolved by either giving that user/group atleast read access at the site level or in my case I had to create a new permission set (since we cant update limited access permission set) which is same as limited access but with the additional permission
    of "Use Remote Interfaces  -  Use SOAP, Web DAV, the Client Object Model or SharePoint Designer interfaces to access the Web site."
    I am not sure if this is a bug or as per design, but not allowing a user who has needed permissions at the list level but limited access at site level doesnt seem right. Never ran into this issue in prior version of SharePoint. I tested and this additional
    permission doesnt seem to violate any security at site level. But implement this at your risk. No guarantees provided and not responsible for any issues with this implementation if any.

Maybe you are looking for

  • Help on program

    SQL> create or replace package bulk_transfer is 2 type product is table of emp % rowtype index by binary_integer; 3 procedure bulk_proc(p_product in out product, p_product2 varchar2); 4 end; 5 / Package created. SQL> create or replace package body bu

  • If payment differcence exeeds tolerance limits

    Dear experts can u help me in one problem as i created vendor invoice Rs 1000/ there is no open items for this vendor except this invoice line NOW i am going to vendor payment F-53. Rs 1500. this customer having 1% discount ok . in this condition wha

  • Database installation in Guest OS.

    Hi, We have installed OVM 3.1 and created the guests using ISO RHEL 5.7 Upon creation of the guest, we are trying to install single instance oracle database by copying the software into the guest host. When we try to invoke the runInstaller, the scre

  • Premiere 12 wont change the program from trial when i enter the serial number

    I have bought adobe premiere elements and Photoshop 12 . When i install the software i ad the serial number and it installs. However when i start using the program it says its in trial mode and i need to enter a serial number?

  • Sort priority of merged folders and worksets

    Hi Forum! I have a challenge, which I hope some of you can contribute to solving: I'm trying to merge several roles, which have different structures, but I can't get the sorting to work. Here goes : Structure of my different roles: 1 : Role -> Folder