|
-
Sep 14th, 2004, 11:17 AM
#1
Thread Starter
Lively Member
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
-
Sep 14th, 2004, 03:13 PM
#2
Frenzied Member
I think if you leave out this line it will work..
f.getContentPane().add(this);
-
Sep 14th, 2004, 05:38 PM
#3
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.
-
Sep 14th, 2004, 09:17 PM
#4
Fanatic Member
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();
}
}
-
Sep 15th, 2004, 06:00 PM
#5
Dazed Member
All of the add() methods in java.awt.Container take Component refs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|