Results 1 to 7 of 7
  1. #1
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    78
    Rep Power
    0

    Default Error with my simple GUI code

    Hi,

    I was just going trough a simple Java GUI tutorial when I ran into trouble. I get an error message cannot find symbol and it makes reference to line 56, which is this line below.
    Java Code:
    f.addWindowListener(new ListenCloseWdw());
    I have pasted the complete code below for help please.

    Java Code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class BasicGui {
    	private JFrame f = new JFrame("Basic GUI");
    	private JPanel pnlNorth = new JPanel(); //North area
    	private JPanel pnlSouth = new JPanel(); //South area
    	private JPanel pnlEast  = new JPanel(); //East area
    	private JPanel pnlWest = new JPanel(); //West area
    	private JPanel pnlCenter = new JPanel(); //Center area
    	
    	//A few buttons to put in the panels
    	private JButton btnNorth = new JButton("North");
    	private JButton btnSouth = new JButton("South");
    	private JButton btnEast = new JButton("East");
    	private JButton btnWest = new JButton("West");
    	private JButton btnCenter = new JButton("Center");
    	
    	//here we put some menus
    	private JMenuBar mb = new JMenuBar(); //Menubar
    	private JMenu mnuFile = new JMenu("File"); // File entry on menu bar
    	private JMenuItem mnuItemQuit = new JMenuItem("Quit"); //quite sub item
    	private JMenu mnuHelp = new JMenu("Help"); //help menu entry
    	private JMenuItem mnuItemAbout = new JMenuItem("About"); //about entry
    	
    	/*here we have a construtor for the GUI*/
    	  public BasicGui() {
    	  	// Set menu bar
    	  	f.setJMenuBar(mb);
    	  	
    	  	//Build Menus
    	  	mnuFile.add(mnuItemQuit); // Create quit line
    	  	mnuHelp.add(mnuItemAbout); //Create About line
    	  	mb.add(mnuFile); // Add menu items to form
    	  	mb.add(mnuHelp);
    	  	
    	  	// Add Buttons
    	  	pnlNorth.add(btnNorth);
    	  	pnlSouth.add(btnSouth);
    	  	pnlEast.add(btnEast);
    	  	pnlWest.add(btnWest);
    	  	pnlCenter.add(btnCenter);
    	  	
    	  	// Setup Main Frame
    	  	f.getContentPane().setLayout(new BorderLayout());
    	  	f.getContentPane().add(pnlNorth, BorderLayout.NORTH);
    	  	f.getContentPane().add(pnlSouth, BorderLayout.SOUTH);
    	  	f.getContentPane().add(pnlEast,  BorderLayout.EAST);
    	  	f.getContentPane().add(pnlWest,  BorderLayout.WEST);
    	  	f.getContentPane().add(pnlCenter, BorderLayout.CENTER);
    	  	
    	  	//Allows the swing App to be closed
    	  	f.addWindowListener(new ListenCloseWdw());
    	  	
    	  	//Add Menu listener
    	  	mnuItemQuit.addActionListener(new ListenMenuQuit());
    	  }
    	  
    	  //Add menu listenet
    	  public class ListenMenuQuit implements ActionListener{
    	  	  public void actionPerformed(ActionEvent e){
    	  	  	System.exit(0);
    	  }
    	}
    	  
    	  public class ListenCloseWindowAdapter{
    	  	 public void windowClosing(WindowEvent e) {
    	  	 	System.exit(0);
    	  	 }
    	  }
    
      public void launchFrame(){
      	//Display Frame
      	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      	f.pack(); //Adjust panel to component for display
      	f.setVisible(true);
      }
      
      public static void main(String [] args) {
      	BasicGui gui = new BasicGui();
      	gui.launchFrame();
      }
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default

    Please post the full text of the error message when you get errors.
    Which symbol can't it find?

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,533
    Blog Entries
    7
    Rep Power
    20

    Default

    There simply is no ListenCloseWdw class in scope; that's why your compiler is whining.

    kind regards,

    Jos

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    78
    Rep Power
    0

    Default

    Hi Again,
    The full error message that I am getting is shown below.
    Java Code:
    cannot find symbol class ListenCloseWdw
    There simply is no ListenCloseWdw class in scope; that's why your compiler is whining.
    Java Code:
    Where is the code for the ListenCloseWdw class?
    The code that I posted earlier is the full code that I read in the tutorial. I thought as much that something was missing or not right with that tutorial. I have not been able to fix it now. Can someone help me sove the problem, please?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default

    What you posted is NOT the full text of the error message. You've only given part of it.
    Here is an example of the full text:
    TabbedPaneDemo.java:162: cannot find symbol
    symbol : class NoClassDef
    location: class TabbedPaneDemo
    new NoClassDef();
    ^
    I think the class you need(ListenCloseWindowAdapter) is defined in your source but spelled differently:
    Replace ListenCloseWdw() with ListenCloseWindowAdapter()
    to use the class that is in your source.

    Also you need to add: extends WindowAdapter after 'public class ListenCloseWindowAdapter()'
    Last edited by Norm; 06-28-2010 at 08:22 PM.

  7. #7
    Menre is offline Member
    Join Date
    Feb 2008
    Posts
    78
    Rep Power
    0

    Thumbs up

    Thank you very much everyone. I did as you said and it is now working perfectly. The corrected code is place below.
    Java Code:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class BasicGui {
    	private JFrame f = new JFrame("Basic GUI");
    	private JPanel pnlNorth = new JPanel(); //North area
    	private JPanel pnlSouth = new JPanel(); //South area
    	private JPanel pnlEast  = new JPanel(); //East area
    	private JPanel pnlWest = new JPanel(); //West area
    	private JPanel pnlCenter = new JPanel(); //Center area
    	
    	//A few buttons to put in the panels
    	private JButton btnNorth = new JButton("North");
    	private JButton btnSouth = new JButton("South");
    	private JButton btnEast = new JButton("East");
    	private JButton btnWest = new JButton("West");
    	private JButton btnCenter = new JButton("Center");
    	
    	//here we put some menus
    	private JMenuBar mb = new JMenuBar(); //Menubar
    	private JMenu mnuFile = new JMenu("File"); // File entry on menu bar
    	private JMenuItem mnuItemQuit = new JMenuItem("Quit"); //quite sub item
    	private JMenu mnuHelp = new JMenu("Help"); //help menu entry
    	private JMenuItem mnuItemAbout = new JMenuItem("About"); //about entry
    	
    	/*here we have a construtor for the GUI*/
    	  public BasicGui() {
    	  	// Set menu bar
    	  	f.setJMenuBar(mb);
    	  	
    	  	//Build Menus
    	  	mnuFile.add(mnuItemQuit); // Create quit line
    	  	mnuHelp.add(mnuItemAbout); //Create About line
    	  	mb.add(mnuFile); // Add menu items to form
    	  	mb.add(mnuHelp);
    	  	
    	  	// Add Buttons
    	  	pnlNorth.add(btnNorth);
    	  	pnlSouth.add(btnSouth);
    	  	pnlEast.add(btnEast);
    	  	pnlWest.add(btnWest);
    	  	pnlCenter.add(btnCenter);
    	  	
    	  	// Setup Main Frame
    	  	f.getContentPane().setLayout(new BorderLayout());
    	  	f.getContentPane().add(pnlNorth, BorderLayout.NORTH);
    	  	f.getContentPane().add(pnlSouth, BorderLayout.SOUTH);
    	  	f.getContentPane().add(pnlEast,  BorderLayout.EAST);
    	  	f.getContentPane().add(pnlWest,  BorderLayout.WEST);
    	  	f.getContentPane().add(pnlCenter, BorderLayout.CENTER);
    	  	
    	  	//Allows the swing App to be closed
    	  	f.addWindowListener(new ListenCloseWindowAdapter());
    	  	
    	  	//Add Menu listener
    	  	mnuItemQuit.addActionListener(new ListenMenuQuit());
    	  }
    	  
    	  //Add menu listenet
    	  public class ListenMenuQuit implements ActionListener{
    	  	  public void actionPerformed(ActionEvent e){
    	  	  	System.exit(0);
    	  }
    	}
    	  
    	  public class ListenCloseWindowAdapter extends WindowAdapter{
    	  	 public void windowClosing(WindowEvent e) {
    	  	 	System.exit(0);
    	  	 }
    	  }
    
      public void launchFrame(){
      	//Display Frame
      	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      	f.pack(); //Adjust panel to component for display
      	f.setVisible(true);
      }
      
      public static void main(String [] args) {
      	BasicGui gui = new BasicGui();
      	gui.launchFrame();
      }
    }
    Once again, thanks.

Similar Threads

  1. please help in java code (simple)
    By rahul_swe23 in forum New To Java
    Replies: 4
    Last Post: 01-26-2009, 03:32 PM
  2. Simple code. Could you help pls..?
    By Iliyas in forum New To Java
    Replies: 8
    Last Post: 12-26-2008, 03:17 AM
  3. Simple code help
    By rednose in forum New To Java
    Replies: 11
    Last Post: 11-30-2008, 06:02 AM
  4. Please help me this is simple bit of code
    By BlitzAcez in forum New To Java
    Replies: 4
    Last Post: 11-27-2008, 05:52 AM
  5. simple code
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:49 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
  •