Results 1 to 5 of 5

Thread: error in code ...

  1. #1

    Thread Starter
    Lively Member fundean's Avatar
    Join Date
    Apr 2001
    Posts
    98

    error in code ...

    The following code:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class HelloBa {
    HelloBa () {
    JFrame f = new JFrame("Hello Ba ");
    f.setSize(300,300);
    f.getContentPane().add(this);
    f.setVisible(true);
    }
    public void paintComponent(Graphics g) {
    g.drawString("What up Ba!",125,90);
    }

    public static void main(String[] args) {
    new HelloBa ();
    }
    }


    gives me the error: "cannot resolve symbol method add (HelloBa)". Does anyone have a solution to this problem?
    Thanks

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    I think if you leave out this line it will work..

    f.getContentPane().add(this);

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes, but it won't do anything.

    You need to derive from some class, probably JPanel.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    sample
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class HelloBa extends JPanel{
        public HelloBa(){
            JFrame f=new JFrame("Hello Ba");
            f.setSize(300,300);
            f.getContentPane().add(this);
            f.setVisible(true);
        }
        public static void main(String[] args){
            new HelloBa();
        }
    }

  5. #5

Posting Permissions

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



Click Here to Expand Forum to Full Width