CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Nov 2010
    Posts
    81

    No matter what I change, program still runs what it said before...

    OK... I need to change the button and my name to CENTER, the input to NORTH, and the green blocks to SOUTH. I did that.... but for some reason it keeps running the way I had it before... also if I change any text, it won't show up as different when I compile and run... for example if I changed the "Name: " label to "Happy: " then compile and run, it still says "Name: "


    By the way, there is an external method, but it doesn't have anything to do with what I'm changing. I colored the areas I need to change... they are oriented the way I need them, but see how the program runs in the attached .jpg


    This is due tonight... please somebody tell me what's wrong so I can fix it!

    Code:
    /*
    	Chapter 5:	Reserve a Party Room
    	Programmer:	Ben Brotsker
    	Date:		04/14/11
    	Filename:	ReservationsRepositioned.java
    	Purpose:	This program creats a windowed application to reserve a part room.
    				It calls an external class named Rooms.  The frames are repositioned.
    */
    
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    
    public class ReservationsRepositioned extends Frame implements ActionListener
    {
    	Color lightRed = new Color(255, 90, 90);
    	Color lightGreen = new Color(140, 215, 40);
    
    	Rooms room = new Rooms(5,3);
    
    	Panel roomPanel = new Panel();
    		TextArea roomDisplay[] = new TextArea[9];
    
    	Panel buttonPanel = new Panel();
    		Button bookButton = new Button("Book Room");
    		Label nameLabel = new Label("Ben B*******   04/16/11");
    
    	Panel inputPanel = new Panel();
    		Label custNameLabel = new Label("Name:");
    		TextField nameField = new TextField(15);
    		Label custPhoneLabel = new Label("Phone number:");
    		TextField phoneField = new TextField(15);
    		Label numLabel = new Label("SOMETHING IS WRONG!!!:");
    		Choice numberOfGuests = new Choice();
    		CheckboxGroup options = new CheckboxGroup();
    			Checkbox nonSmoking = new Checkbox("Nonsmoking",false,options);
    			Checkbox smoking = new Checkbox("Smoking",false,options);
    			Checkbox hidden = new Checkbox("",true,options);
    
    	public ReservationsRepositioned()
    	{
    		//set Layouts for frame and three panels
    		this.setLayout(new BorderLayout());
    			roomPanel.setLayout(new GridLayout(2,4,10,10));
    			buttonPanel.setLayout(new FlowLayout());
    			inputPanel.setLayout(new FlowLayout());
    
    		//add components to room pane
    		for (int i=1; i<9; i++)
    		{
    			roomDisplay[i] = new TextArea(null,3,5,3);
    			if (i<6)
    				roomDisplay[i].setText("Room " + i + " Nonsmoking");
    			else
    				roomDisplay[i].setText("Room " + i + " Smoking");
    			roomDisplay[i].setEditable(false);
    			roomDisplay[i].setBackground(lightGreen);
    			roomPanel.add(roomDisplay[i]);
    		}
    
    		//add components to button panel
    		buttonPanel.add(bookButton);
    		//buttonPanel.add(nameLabel);
    
    		//add compoents to input panel
    		inputPanel.add(custNameLabel);
    		inputPanel.add(nameField);
    		inputPanel.add(custPhoneLabel);
    		inputPanel.add(phoneField);
    		inputPanel.add(numLabel);
    		inputPanel.add(numberOfGuests);
    			for(int i=8; i<=20; i++)
    				numberOfGuests.add(String.valueOf(i));
    		inputPanel.add(nonSmoking);
    		inputPanel.add(smoking);
    
    
    		//add panels to frame
    		add(buttonPanel, BorderLayout.NORTH);
    		add(inputPanel, BorderLayout.NORTH);
    		add(roomPanel, BorderLayout.SOUTH);
    
    		bookButton.addActionListener(this);
    
    		//overriding the windowClosing() method will allow the user to click the close
    		addWindowListener(
    			new WindowAdapter()
    			{
    				public void windowClosing(WindowEvent e)
    				{
    					System.exit(0);
    				}
    			}
    		);
    	} //end of constructor method
    
    	public static void main(String[] args)
    	{
    		Reservations f = new Reservations();
    		f.setBounds(200,200,600,300);
    		f.setTitle("Reserve a Party Room");
    		f.setVisible(true);
    	} //end of main
    
    	public void actionPerformed(ActionEvent e)
    	{
    		if (hidden.getState())
    		{
    			JOptionPane.showMessageDialog(null,"You must select Nonsmoking or Smoking.","Error",JOptionPane.ERROR_MESSAGE);
    		}
    		else
    		{
    			int available = room.bookRoom(smoking.getState());
    
    			if(available > 0) //room is available
    			{
    				roomDisplay[available].setBackground(lightRed); //display room as occupied
    				roomDisplay[available].setText(
    												roomDisplay[available].getText() + "\n" +
    												nameField.getText() + " " +
    												phoneField.getText() + "\nparty of " +
    												numberOfGuests.getSelectedItem()
    												); //display info in room
    				clearFields();
    			}
    			else //room is not available
    			{
    				if (smoking.getState())
    					JOptionPane.showMessageDialog(null, "Smoking is full.","Error", +
    					JOptionPane.INFORMATION_MESSAGE);
    				else
    					JOptionPane.showMessageDialog(null, "Nonsmoking is full.","Error", +
    					JOptionPane.INFORMATION_MESSAGE);
    				hidden.setState(true);
    			} //end of else blaock that checks the available room number
    		} //end of else block that checks the state of the hidden option button
    	} //end of actionPerformed() method
    
    	//reset the text fields and choice component
    	void clearFields()
    	{
    		nameField.setText("");
    		phoneField.setText("");
    		numberOfGuests.select(0);
    		nameField.requestFocus();
    		hidden.setState(true);
    	} //end of clearFields method
    
    } //end of Reservations class
    Attached Images Attached Images  
    Last edited by LogicWavelength; April 17th, 2011 at 03:37 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
  •  





Click Here to Expand Forum to Full Width

Featured