I cant get a filled square and a Button to be drawn at the same time!!

Hello!
My problem: When I run this little program the button doesnt show until I hoover over it... and if I resize the window the square isnt drawn anymore?
why?
code:
public class TestJFrame extends JFrame{
     JButton b;
     JPanel jp;
     public TestJFrame() {
          super();
          jp = new JPanel();
          b = new JButton("button");
          jp.add(b);
          this.add(jp);
          setSize(400,400);
          setVisible(true);
     public void paint(Graphics g){
          g.setColor(Color.BLACK);
          g.fillRect(100,100,100,100);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestJFrame t = new TestJFrame();
}

JFrame is application's main window and it is a complex and heavyweight composite container.
You should never override its painting method directly. Use one of its sub containers instead,
or, add your custom drawing panel onto it. Here's an example using JFrame's content pane
sub container and a custom panel.
import javax.swing.*;
import java.awt.*;
public class WassanJFrame extends JFrame{
  JButton b;
  WessanPanel wp;
  public WassanJFrame() {
    super();
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    wp = new WessanPanel();
    b = new JButton("button");
    wp.add(b);
    setContentPane(wp);
    setSize(400,400);
    setVisible(true);
  class WessanPanel extends JPanel{
    public void paintComponent(Graphics g){
      super.paintComponent(g);
      g.setColor(Color.BLACK);
      g.fillRect(100, 100, 100, 100);
  public static void main(String[] args) {
    new WassanJFrame();
}

Similar Messages

  • HT204053 how cant i use find me and see all my 3 iphones at the same time

    how can i use find me and see all my 3 iphones at the same time

    I assume you mean Find My iPhone.
    You must have the Find My iPhone service turned on inside each phone (Settings>iCloud).  Then either log into icloud.com and go to the Find My iPhone page to view a map and list of device, or use the Find My iPhone app on any device.
    "at the same time" - no you only view one map (associated with one phone) at a time.  You can't get all three phones on one map.

  • I have been getting this message " no sim installed " too many times then my phone goes off , its iphone 4S , its really a problem i cant get calls or anything and im not sure how to take the SIM out then insert it again , what to do ??

    i have been getting this message " no sim installed " too many times then my phone goes off , its iphone 4S , its really a problem i cant get calls or anything and im not sure how to take the SIM out then insert it again , what to do ??

    Use the sim tool that came with your phone or a safety pin and just insert it into the hole at the side of the sim tray and push it in and then pull it out.  It is no more difficult than that and then just close it again.

  • Error : Old and new exceptions cannot be used at the same time.

    HI ALL,
    i build a new exception class with message class and i want to replace the
    old exception that i had in the method ,what i did is delete the exception from the method
    signature and add the exception class .
    the problem is that when i try to activate the method i get error :
    Old and new exceptions cannot be used at the same time.
    CALL FUNCTION 'CALCULATE_HASH_FOR_CHAR'
          EXPORTING
            alg            = 'MD5'
            data           = iv_iss
          IMPORTING
            hash           = lv_issu
          EXCEPTIONS
            unknown_alg    = 1
            param_error    = 2
            internal_error = 3
            OTHERS         = 4.
        IF sy-subrc <> 0.
          RAISE EXCEPTION TYPE cx_user_mng EXPORTING
          textid = cx_user_mng=>wrong_isrs.
        ENDIF.
    I want to use the new exception class ,
    how can i avoid this error ?
    Best Regards
    Edited by: Joy Stpr on Jul 22, 2009 2:56 PM
    Edited by: Joy Stpr on Jul 22, 2009 3:16 PM

    Hi Joy,
    Check this link.
    [Old and New Exceptions Cannot be used at same time|Urgent problem, give me a hand;
    Old and new exceptions cannot be used the same time, what does this mean???
    Regards,
    Lakshman.

  • How can I record an Audio Instrument (saxophone) and listen to a reference track at the same time?

    How can I record an Audio Instrument, and listen to a reference track at the same time?

    Are you using an external audio controller or the line-in and headphone jacks on the side of your computer? You shouldn't have an issue using headphones when you're recording through the line-in but you may want to make sure you have monitoring on and it's going to the right place.
    If you're using an external audio controller, try making an aggregate device combining the controller and the "built-in output" into the same device. Go to Applications/Utilities/Audio MIDI Setup, click the "+" sign at the bottom left to make a new device and check the "use" boxes to the left of the physical devices you want to use as part of that aggregate device. That is how I use the computer's speakers or headphones to monitor my input as opposed to only being able to use the output on my audio controller.
    Now that I see some of the questions on the side of this page I realize that the 13" MBPs seem to have only one combined input/output jack... That is an incredibly stupid feature. What on Earth could possibly justify that design decision? I suppose if that's the problem you're having you'll have to buy some sort of splitter (if they even make them) or get an external audio controller like an Apogee Duet or something along those lines. I would be furious if they combined those two jacks on all of the MBPs.

  • Remote and direct update of master data at the same time

    Hello
    Is it possible to do remote and direct update of master data at the same time? If yes where it could be used?
    Thanks

    Hi,
    What do you mean by Remote Update ?
    regards
    Happy Tony

  • How to open and save pictures from 1 folder at the same time?

    Is there a way to open and save pictures from 1 folder at the same time?
    I'm creating a vi that resizes the picture but I want to do it with 1 folder at a time... Is this possible?
    greetings!

    Hi Kway,
    Here you are. I wrote a file a customer times ago & It did what you want!
    Just see the attachements and keep me inform.
    Regards,
    Julien Roland - District Sales Manager
    NI Belgium - Technical Support
    Don't forget to rate a good answer
    Attachments:
    Test existing Files.vi ‏23 KB
    Delete files from array of files (SubVI).vi ‏16 KB

  • Is it possible to connect the iPad to an Infocus and a remote for ppt presentations at the same time?

    I've always used PC and I'm planning on making the transition to Mac.  That's why I'm considering buying an iPad. Today I went to Best Buys and the Mac guy told me that it isn't possible to connect the iPad to an Infocus and a remote for ppt presentations at the same time. Is that true?  I'm a speaker and that was the main reason I was considering buying an iPad, so I didn't have to carry my laptop. Thanks for your help!

    Thanks for your reply. Looks like it can as I have just found this https://www.youtube.com/watch?v=nKp02y4JXVs

  • In windows how do we install and activite multiple versions of tuxedo at the same time ?

    Hi All,
    In windows how do we install and activate multiple versions of tuxedo at the same time ?
    Advance wishes

    You can run different versions of Tuxedo on the same server, as long as they are installed in different directories.
    See PeopleTools 8.53 installation manual Task 3-1: Installing Oracle Tuxedo
    You can install Oracle Tuxedo once for each release on a machine, regardless of the number of PeopleSoft
    applications or databases the server supports. For example, if you are a PeopleSoft 9.1 customer and have
    Oracle Tuxedo 6.5 installed, you may install Oracle Tuxedo 6.5 and Oracle Tuxedo 11gR1 on the same
    machine in separate directories. For example:
    On Windows, you may install into C:\oracle\tuxedo11gR1_VS2010 and C:\tux65.
    On UNIX, you may install into /home/oracle/tuxedo11gR1 and /prod/tuxedo/6.5.
    E-TUX: Can Multiple Versions of Tuxedo Coexist on One Physical UNIX or Linux Server? (Doc ID 607828.1)

  • HT1442 install and run mac os 10.4 at the same time mountain lion 10.8

    nstall and run mac os 10.4 at the same time mountain lion 10.8

    I was able to install Intel Tiger into VMWare Fusion 2.0; I was never successful at installing it in VMWare Fusion 4.
    If you have had success in version 4, please let us know how to do it!  Thanks!

  • I recently bought a 4th generation ipod shuffle.  Am I able to have both music and audio podcasts loaded on it at the same time?

    I have not been able to include both music and audio podcasts on my shuffle at the same time. Is this possible with the shuffle?

    I disabled all my computer's firewalls and sure enough, IT WORKED!! My iPod is updated and just now finishing restoring! Thank you SOOOO SOOO much. : D

  • When im facetiming with someone and im watching a youtube video at the same time, the volume for the youtube video is lowered and the facetime volume stays the same, how can i change that?

    When im facetiming with someone and im watching a youtube video at the same time, the volume for the youtube video is lowered and the facetime volume stays the same, how can i change that?

    Have you ever even used skype on an iphone or ipod?  We tried it and there is no way to type to each other while you are video chatting.  You can do the typing during the video on a COMPUTER, but not on an iphone or ipod.

  • My computer broke and I lost my ipod touch at the same time. Then I put all of my new music on my nano. Then I found my ipod touch. How do I get the music from the ipod touch to the computer and also keep the music I bought for the nano?

    I have an ipod touch and an ipod nano. I also used to have a laptop but, it quit working and I no longer have it. I had all of my music on my laptop. So, I had to buy a new desktop. I lost my ipod touch at around the same time. I had all of my music on the ipod touch that was from my laptop. So in thye meantime I started using my nano more. I bought new songs on my desktop for my nano. Then I found my ipod touch. I would like to be able to keep both the somgs I have now on my ipod touch and the ones that I already bought on the desktop. What do I do?

    No.
    All iTunes content on your iPod Touch should be in your iTunes library on your computer, and your iTunes library on your computer should be included with your computer's backup along with all other important data - stored on an external drive or some other external media used for backup purposes only.
    When music was purchased on a CD, if the CD was lost and you returned to the store where the CD was purchased with your receipt, were you given a replacement CD?
    The same applies here.

  • HP DV7 laptop, cant listen and talk from 2 usb headsets at the same time??

    Hi,
    I am trying to use two usb headsets at the same time as my wife and I are doing an online course, but can onle use either one at onc, not both?? Has anyone got any ideas?
    Thanks, Matt

    Hello Mattynsavvy, welcome to the HP Forums.
    It appears that you're trying to use two headphones from your notebook to do an online course.
    The way that you're trying to do this probably won't work. The notebook itself only has one sound card. This card can only output audio to one device at a time. So if you have both USB headsets into ports. Only one will have sound. Just like how the headset cuts off the speakers. You would need a second sound card, or to be using speakers or another computer.
    The only thing I could think of that may accomplish what you're trying is to use the audio/mic jacks on the notebook specifically with a splitter. This may allow the sound to be direct to two headsets. I can not say for certain if this will work or not.
    I was able to find a few YouTube videos with various ways to achieve what you're trying to do, but as they run with 3rd party software attempting those suggestions would be completely up to you.
    I hope this helps.
    Thank you for posting on the HP Forums.
    I worked on behalf of HP.

  • Reading and Writing from a text file at the same time

    I know who to use the Scanner and PrintWriter to read from and write to a .txt file. But these are limited. How can I read and write at the same time? Such as open a file and change every third character or change every second word to something else and then write it back. I found this [http://java.sun.com/docs/books/tutorial/essential/io/|http://java.sun.com/docs/books/tutorial/essential/io/] but its a little over my head. Is this the only way to do it?

    wrote:
    You are using buffered reads and writes I would assume, right? Also, how do you think most programs handle this sort of thing? I don't believe I'm using buffering.
    My code looks something like this
    //...necessary imports
    //then
    Scanner inFile = new Scanner (new file("filename1.txt"));
    PrintWriter outFile = new PrintWriter ("filename2.txt");
    //then stuff like
    int x = inFile.hasNextInt();
    outFile.println(x);
    camickr wrote:If you are changing the data "in place", that is none of the data in the file is shifted, then you can use a RandomAccessFile.
    Otherwise, you've been given the answer above.What is RandomAccessFile? Is it what I have a link to? Basically what I do is I write a bunch of numbers to a txt file and then change the numbers I don't need anymore to 0. So say I had 0 1 2 3 4 5 6 7 etc. I would like to to open the txt file and change every second one to 0 so then I'd have only odd numbers and 0s.
    I looked at the documentation for RandomAccessFile and it seems like it might be what I need.
    Thankyou both for your help so far. I took a java course in high school and they only taught me one way to get data from text files and that is what I just showed you. So maybe this questions are really stupid. lol
    Edited by: qw3n on Jun 13, 2009 7:46 PM

Maybe you are looking for