LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-18-2006, 09:41 PM   #1
radicaledward
LQ Newbie
 
Registered: Oct 2004
Posts: 3

Rep: Reputation: 0
Java "Cannot Find Symbol"


Okay, I just can figure this out. I'm fairly new to Java but not programming on the whole. Am I missing something obvious here?

Code:
package dmpanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class MainPanel extends JPanel implements ActionListener {
    
    public static void main(String args[]){

    } 
    
    MainPanel() {
        createAndShowGUI casg = new createAndShowGUI();
        JTextField d20 = new JTextField();
    }

    void createAndShowGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);

        JFrame frame = new JFrame("DMPanel");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        addPanelsToPane(frame.getContentPane());

        frame.pack();
        frame.setVisible(true);
    }
    
    public void actionPerformed(ActionEvent evt) {
        
    }
       
}
I know the code is kind of a mess but i'm just playing around trying to make a dnd DM's panel. (I also didn't include a fair number of methods that don't matter).
The compiler complains it cannot find createAndShowGUI when I try to initialize it in the contstructor (or if I try and do it in the main method it complains too). Help please!
 
Old 05-18-2006, 11:02 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Your class name must be the same as the constructor name

Hi -

Your class name must == your constructor name, which == your source file name. for example:
Code:
class CreateAndShowGUI extends JPanel implements ActionListener {
    
    public static void main(String args[]){
        CreateAndShowGUI casg = new createAndShowGUI();

    } 
    
    CreateAndShowGUI () {
        JFrame.setDefaultLookAndFeelDecorated(true);

        JFrame frame = new JFrame("DMPanel");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        addPanelsToPane(frame.getContentPane());
        JTextField d20 = new JTextField(); // Not sure where this belongs ... but not in main()!
        frame.pack();
        frame.setVisible(true);
    }
    
    public void actionPerformed(ActionEvent evt) {
        
    }
       
}

Last edited by paulsm4; 05-18-2006 at 11:07 PM.
 
Old 05-19-2006, 01:00 AM   #3
ppanyam
Member
 
Registered: Oct 2004
Location: India
Distribution: Redhat
Posts: 88

Rep: Reputation: 15
In your program, replacing

<code> createAndShowGUI casg = new createAndShowGUI(); </code>

with the code

<code> createAndShowGUI(); </code>

should work. In your program, "createAndShowGUI" is a method, and you are trying to create an object from it. You can create an object from a class with new(...).

Prabhakar Panyam
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
avgscan "relocation error" "undefined symbol: __dynamic_cast_2" Monster_user Linux - Software 0 02-22-2006 11:57 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
1. shell script "find and replace" on text 2. java GUI application randomx Programming 4 03-05-2004 01:01 PM
using java to find the location of the "\" char in a string caged Programming 8 02-03-2004 10:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration