Dedugging problems

Discussion in 'Java' started by Ken, Apr 24, 2008.

  1. Ken

    Ken New Member

    Joined:
    Apr 9, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    I have a problem with some coding and i an having trouble understanding where i am going wrong

    Here the coding

    Code:
    	import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Hire extends JDialog implements ActionListener
    {
    	private JButton ok;
    	private JButton cancel;
    	private JTextField bid;
    	private JTextField name;
    	private JTextField time;
    	private BoatHireCompany theBoat;
    	
    	public Hire(String sTitle, JFrame owner) {
    		super (owner, sTitle, true);
    		setLayout(new FlowLayout());
    		setSize(350,200);
    		add (new JLabel("Enter Boat ID:"));
    		bid = new JTextField(20);
    		add (bid);
    		add (new JLabel("Enter Customer Name:"));
    		name = new JTextField(20);
    		add (name);
    		add (new JLabel("Enter Current Time:"));
    		time = new JTextField(20);
    		add (time);
    		ok = new JButton("Hire Boat!");
    		ok.addActionListener(this);
    		add(ok);
    		cancel = new JButton("Cancel");
    		cancel.addActionListener(this);	
    		add(cancel);
    	}
    	public BoatHireCompany getBoat()
    	{
    		return theBoat;
    	}
    	public void actionPerformed(ActionEvent e) {
    		if (e.getSource() == ok) {
    		    theBoat =  new BoatHireCompany(bid.getText(), name.getText(), time.getText());
    		}
    		else if (e.getSource() == cancel) {
    		    // data entry cancelled
    		    theBoat = null;
    		} 
    		dispose();
    	}
    }
    
    line 40
    Error cannot find symbol
    constuctor BoatHireCompany (java.lang.String,java.lang.String,java.lang.String)
    Class BoatHireCompany

    The thing is i have the BoatHirecompany class

    Code:
    import java.util.*;
    import javax.swing.*;
     
    public class BoatHireCompany {
    	
    	private ArrayList <Boat> theBoats;
    	private int numBoats;
    	private int maxBoats;
    	private String companyName;
    	
    	// create a boat hire company
    	public BoatHireCompany (String name, int num) {
    		companyName = name;
    		numBoats = 0;
    		maxBoats = num;
    		theBoats = new ArrayList <Boat> (maxBoats);
    	}
    	
    	public boolean addBoat( Boat newBoat )
        {   // add another Boat to the BoatHireCompany
            if ( numBoats == maxBoats ) {
    			return false;
            }
            else {   // add Boat to the BoatHireCompany
                theBoats.add(newBoat);
                numBoats++;
                return true;
            }
        }
    	
    	public void displayAll() {
    		for (int i = 0; i < numBoats; i++) {
                System.out.println(theBoats.get(i).toString());
            }
    	}
    	
    	public void displayPedalBoats() {
    	}
    	
    	public void displayRowingBoats() {
    	}
    	
    	public void displayHiredBoats() {
    	}
    	
    	public void findPedalBoats() {
    	}
    	
    	public void findRowingBoats() {
    	}
    	
    	public void findBoat() {
    	}
    	
    }
    
    my Main where the data is the big headache

    Code:
    public class Main
    {
       public static void main( String[] args)
        {
    // create company
    	BoatHireCompany octagon = new BoatHireCompany("octagon", 10);
    	
     
    	public Main() 
    	{
    		
    		// add default boats to octagon company
    		octagon.addBoat(new RowingBoat("Titanic", 11));
    		octagon.addBoat(new PedalBoat("Red", 12));
    		octagon.addBoat(new PedalBoat("Green", 13));
    		octagon.addBoat(new RowingBoat("London", 14));
    		octagon.addBoat(new PedalBoat("White", 15));
    		octagon.addBoat(new PedalBoat("White", 16));
    
    
    
    
    // Add code to handle the menu events
    	public void actionPerformed(ActionEvent e) 
    	{
    	 if (e.getSource() == mfOne) 
    	 { // hire a boat
         Hire hire = new Hire("Hire a boat", this);
         hire.setVisible(true);
         Boat boat = hire.getBoat(); 
    	        if( p != null) 
    	        {
    		    	textarea.setText( p.toString() );
    	 	      	octagon.addBoat(new PedalBoat(p));
    	        }
    	        else 
    	       {
    		    	textarea.setText( "Boat not added" );
    			   }
    		}
    		
    		else if (e.getSource() == mtOne) 
    		{ // add new boat
    			GUINew newb = new GUINew("Add a new boat", this);
    			newb.setVisible(true);
    			if(newb.getType().equals "Rowing Boat") 
    			{
    				octagon.addBoat(new RowingBoat(newb.getName(), newb.getBid()), newb.getBid(), textarea, title);
    			}
    			else {
    				octagon.addBoat(new PedalBoat(newb.getName(), newb.getBid()), newb.getBid(), textarea, title);
    			}
    		}
    
      }
    }
    }
    }
    
    
    P:\BPRC\src\Main.java:9: illegal start of expression
    public Main()
    ^
    P:\BPRC\src\Main.java:9: ';' expected
    public Main()
    ^
    P:\BPRC\src\Main.java:24: illegal start of expression
    public void actionPerformed(ActionEvent e)
    ^
    P:\BPRC\src\Main.java:24: illegal start of expression
    public void actionPerformed(ActionEvent e)
    ^
    P:\BPRC\src\Main.java:24: ';' expected
    public void actionPerformed(ActionEvent e)
    ^
    P:\BPRC\src\Main.java:24: ';' expected
    public void actionPerformed(ActionEvent e)
    ^
    P:\BPRC\src\Main.java:46: ')' expected
    if(newb.getType().equals "Rowing Boat")
    ^
    P:\BPRC\src\Main.java:46: not a statement
    if(newb.getType().equals "Rowing Boat")
    ^
    P:\BPRC\src\Main.java:46: ';' expected
    if(newb.getType().equals "Rowing Boat")
    ^
    P:\BPRC\src\Main.java:50: 'else' without 'if'
    else {

    Any Help would be welcome thank you for you time
     
  2. Ken

    Ken New Member

    Joined:
    Apr 9, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    sorted out the above problem but there one error with an havin trouble getting rid of

    Code:
    import javax.swing.JFrame;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.ButtonGroup;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
    import javax.swing.UIManager;
     
    public class GUINew extends JDialog implements ActionListener
    {
        public static void main (String [] args)       
      {
    	protected JButton ok;
    	protected JButton cancel;
    	protected ButtonGroup type;
    	protected JTextField bid;
    	protected JTextField name;
    	
    	int theBid;
    	String theName;
    	String theType;
    	
    	public GUINew(String sTitle, JFrame owner) {
    		super (owner, sTitle, true);
    		setLooknFeel();
    		bid = new JTextField(4);
    		name = new JTextField(14);
    		ok = new JButton("Hire Boat!");
    		ok.addActionListener(this);
    		cancel = new JButton("Cancel");
    		cancel.addActionListener(this);
    		
    		type = new ButtonGroup();
    		// create each radio button, specifying its label
    		JRadioButton pedal = new JRadioButton("Pedal boat");
    		JRadioButton rowing = new JRadioButton("Rowing boat");
    		// set a String to associate with each button
    		// will use this when the radio button is selected
    		pedal.setActionCommand("Pedal boat");
    		rowing.setActionCommand("Rowing boat");
    		type.add(pedal);
    		type.add(rowing);
    		
    		JPanel top = new JPanel();
    		top.add(pedal);
    		top.add(rowing);
    	        getContentPane().add("North", top);
    	
    		JPanel center = new JPanel();
    		center.add(new JLabel("Enter Boat ID:"));
    		center.add(bid);
    		center.add(new JLabel("Enter Name/Colour:"));
    		center.add(name);
    		getContentPane().add("Center", center);
    		
    		JPanel bottom = new JPanel();
    		bottom.add(ok);
    		bottom.add(cancel);
    		getContentPane().add("South", bottom);
    		
    		pack();
    	}
    	
    	public int getBid() { return theBid; }
    	public String getName() { return theName; }
    	public String getType() { return theType; }
    	
    	public void actionPerformed(ActionEvent e) {
    		if (e.getSource() == ok)
    		{
    			theType = type.getSelection().getActionCommand();
    		    // use the entered data
    		    theBid = Integer.parseInt(bid.getText());
                theName = name.getText();
    		}
    		else if (e.getSource() == cancel) {
    		    this.dispose(); //will release memory
    			this.setVisible(false); //will hide the window
    		} 
    		dispose();
    	}
    	
    	// windows look and feel settings
    	protected void setLooknFeel() 
            {
            String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            try 
            {
                UIManager.setLookAndFeel(lookAndFeel);
            }
            catch (Exception e) 
            {
                e.printStackTrace();
            }
          }
        }
    }
    
    Error message java:17: illegal start of expression
    protected JButton ok;
    ^

    How do i get rid of this error message i have tried to get rid of the protected but more errors occure
    and also how do i get the above prgram to work of this program

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Hire extends JDialog implements ActionListener
    {
       public stimatic void main (String [] args)       
      {
    	protected JButton ok;
    	protected JButton cancel;
    	protected JTextField bid;
    	protected JTextField name;
    	protected JTextField time;
    	protected BoatHireCompany theBoat;
    	
    	public Hire(String sTitle, JFrame owner) {
    		super (owner, sTitle, true);
    		setLayout(new FlowLayout());
    		setSize(350,200);
    		add (new JLabel("Enter Boat ID:"));
    		bid = new JTextField(20);
    		add (bid);
    		add (new JLabel("Enter Customer Name:"));
    		name = new JTextField(20);
    		add (name);
    		add (new JLabel("Enter Current Time:"));
    		time = new JTextField(20);
    		add (time);
    		ok = new JButton("Hire Boat!");
    		ok.addActionListener(this);
    		add(ok);
    		cancel = new JButton("Cancel");
    		cancel.addActionListener(this);	
    		add(cancel);
    	}
    	public BoatHireCompany getBoat()
    	{
    		return theBoat;
    	}
    	public void actionPerformed(ActionEvent e) {
    		if (e.getSource() == ok) {
    		    theBoat =  new BoatHireCompany(bid.getText(), name.getText(), time.getText());
    		}
    		else if (e.getSource() == cancel) {
    		    // data entry cancelled
    		    theBoat = null;
    		} 
    		dispose();
    	}
    }
    
    
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice