Results 1 to 7 of 7
Thread: Error with my simple GUI code
- 06-28-2010, 04:55 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 78
- Rep Power
- 0
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.I have pasted the complete code below for help please.Java Code:f.addWindowListener(new ListenCloseWdw());
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(); } }
- 06-28-2010, 05:28 PM #2
Please post the full text of the error message when you get errors.
Which symbol can't it find?
- 06-28-2010, 05:35 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
There simply is no ListenCloseWdw class in scope; that's why your compiler is whining.
kind regards,
Jos
-
Where is the code for the ListenCloseWdw class?
- 06-28-2010, 08:07 PM #5
Member
- Join Date
- Feb 2008
- Posts
- 78
- Rep Power
- 0
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.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?Java Code:Where is the code for the ListenCloseWdw class?
- 06-28-2010, 08:18 PM #6
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:
I think the class you need(ListenCloseWindowAdapter) is defined in your source but spelled differently:TabbedPaneDemo.java:162: cannot find symbol
symbol : class NoClassDef
location: class TabbedPaneDemo
new NoClassDef();
^
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.
- 06-28-2010, 10:49 PM #7
Member
- Join Date
- Feb 2008
- Posts
- 78
- Rep Power
- 0
Thank you very much everyone. I did as you said and it is now working perfectly. The corrected code is place below.
Once again, thanks.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(); } }
Similar Threads
-
please help in java code (simple)
By rahul_swe23 in forum New To JavaReplies: 4Last Post: 01-26-2009, 03:32 PM -
Simple code. Could you help pls..?
By Iliyas in forum New To JavaReplies: 8Last Post: 12-26-2008, 03:17 AM -
Simple code help
By rednose in forum New To JavaReplies: 11Last Post: 11-30-2008, 06:02 AM -
Please help me this is simple bit of code
By BlitzAcez in forum New To JavaReplies: 4Last Post: 11-27-2008, 05:52 AM -
simple code
By elizabeth in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks