Results 1 to 2 of 2
  1. #1
    NoSwing is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default Very new, and very lost

    HI,

    I'm new to Swing and, well, Java too though I'm not new to programming. I know object oriented programming and so am quite familiar with a lot. However, this whole GUI programming thing has blind-sided me and I'm on a deadline. Yes, it's for school so please, let me assure you, I don't want anyone doing my homework. That's not the idea.

    So, I'm using NetBeans 6.9.1 and pretty much understand how to make basic GUIs and program the event handlers. Mostly because I'm letting the IDE do the behind the scenes work. I have a requirement to paint picture, as in JPEGs and such, to the screen. So, I thought I'd start small since this turned out to be harder than I thought it would.

    So, I went to this link and decided to try implementing the code found here: Refining the Design (The Java™ Tutorials > Creating a GUI With JFC/Swing > Performing Custom Painting). I know how important it is for everyone to see code but I don't want to unduly clutter the window. So, basically, what I've done is copy/pasted the code from that and put it into a new project in NetBeans. I made the RedSquare class a separate file, the made my own panel and incorporated it into the Palette in NetBeans and got it into the main JFrame of the app. However, the red square that is supposed to be drawn in the JPanel, which I named MyPanel (original I know), is not painting.

    What am I missing? From some quick debugging, I found that the RedSquare.paintComponent() method is never being called. Why is this?

    Thanks for any help,
    Andy

  2. #2
    NoSwing is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    Well, I'm embarrassed. I can't tell you the number of times I went back to that link I placed in the original post and didn't catch this until just a moment ago. I figured out why the RedSquare.paintSquare() method wasn't being called. (Yes, I know I called it RedSquare.paintComponent() in the original, sorry, that was a mistake on my part.) I really don't know when I deleted the call to that method in the MyPanel.paintComponent() override. Yes, that's right, the method is supposed to look like:

    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawString("This is my custom Panel!",10,20);

    redSquare.paintSquare(g);
    }

    I didn't have the last line. I don't know why I deleted it, but I did. So, the problem was between the keyboard and the chair. I'm especially embarrassed because I was only a few minutes away from finding.

    Andy

Similar Threads

  1. Absolutely lost
    By Heyman in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 01:59 AM
  2. Ok i am lost
    By jaisan72980 in forum New To Java
    Replies: 3
    Last Post: 01-17-2011, 04:20 AM
  3. lost in labyrinth.
    By niu_niu in forum New To Java
    Replies: 3
    Last Post: 06-10-2010, 12:39 AM
  4. I'm lost :(
    By leonardjr in forum New To Java
    Replies: 8
    Last Post: 03-03-2009, 04:18 AM
  5. So Lost
    By kandt in forum New To Java
    Replies: 5
    Last Post: 12-13-2008, 09:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •