3 Replies - 219 Views - Last Post: 18 May 2014 - 07:41 PM Rate Topic: -----

#1 shoup0198  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 07-February 14

New to Java... GUI problems...

Posted 18 May 2014 - 07:20 PM

I found a tutorial on how to build a GUI. I typed (not copy and paste) this code line by line to understand and get a meaning to each command. I ran into some errors while compiling and decided I would try to fix it. I ran into a problem there..... How do I fix this lol

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

/** 
This class demonstrates the basics of setting up a Java Swing GUI uisng the BorderLayout. You should be able to use this program to drop in other components when building a GUI 
**/

public class javawindo{
    //Initialize swing objects
    private JFrame f = new Jframe("Basick GUI");
    private JPanel pnlNorth = new JPanel();
    private JPanel pnlSouth = new JPanel();
    private JPanel pnlEast = new JPanel();
    private JPanel pnlWest = new JPanel();
    private JPanel pnlCenter = new JPanel();

    //Buttons.
    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");

    //Menu.
    private JMenuBar mb = new JMenuBar(); // Menubar
    private JMenu mnuFile = new JMenu("File"); 
    private JMenuItem mnuItemQuit = new JMenuItem("Quit"); 
    private JMenu mnuHelp = new JMenu("Help"); // Help Menu entry
    private JMenuItem mnuItemAbout = new JMenuItem("About"); // Ab

    /*Constructer for GUI*/
    public javawindo(){
	f.setJMenuBar(mb);

	//build menus
	mnuFile.add(mnuItemQuit);
	mnuHelp.add(mnuItemAbout);
	mb.add(mnuFile);
	mb.add(mnuHelp);

	//add buttons
	pnlNorth.add(btnNorth);
        pnlSouth.add(btnSouth);
        pnlEast.add(btnEast);
        pnlWest.add(btnWest);
        pnlCenter.add(btnCenter);

	//set up 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 closing
	f.addWindoListener(new ListenCloseWdw());

	//menu listener
	mnuItemQuit.addActionListener(new ListenMenuQuit());
    }

    public class ListenMenuQuit implements ActionListener{
        public void actionPerformed(ActionEvent e){
            System.exit(0);         
        }
    }

    public class ListenCloseWdw extends WindowAdapter{
        public void windowClosing(WindowEvent e){
            System.exit(0);         
        }
    }

    public void launchFrame(){
        // Display Frame
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.pack(); //Adjusts panel to components for display
        f.setVisible(true);
    }    

    public static void main(String args[]){
        javawindo gui = new javawindo();
        gui.launchFrame();
    }
}



These are the errors I get:
javawindo.java:12: error: cannot find symbol
    private JFrame f = new Jframe("Basick GUI");
                           ^
  symbol:   class Jframe
  location: class javawindo
javawindo.java:59: error: cannot find symbol
	f.addWindoListener(new ListenCloseWdw());
	 ^
  symbol:   method addWindoListener(javawindo.ListenCloseWdw)
  location: variable f of type JFrame
2 errors



Thanks ahead of time to anyone who wants to chat about this and help me figure it out.

Is This A Good Question/Topic? 0
  • +

Replies To: New to Java... GUI problems...

#2 farrell2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,576
  • Joined: 29-July 11

Re: New to Java... GUI problems...

Posted 18 May 2014 - 07:26 PM

JFrame f = new Jframe

Typo. Needs to be JFrame
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: New to Java... GUI problems...

Posted 18 May 2014 - 07:28 PM

  • Java is case-sensitive. Jframe is not the same as JFrame.

  • Read this method call again, very carefully: addWindoListener. What's missing there? (Hint: it's also missing in the name of your class.)

Was This Post Helpful? 0
  • +
  • -

#4 shoup0198  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 07-February 14

Re: New to Java... GUI problems...

Posted 18 May 2014 - 07:41 PM

Wow jeez thanks guys. I actually omitted the 'w' in the name of the class for a reason but apparently forgot that wasnt the name of the class I was calling. Thanks guys I'm gonna fix these and see what I get....

Everything ran fine after fixing those errors and compiling. Thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1