where do i place my clearFields() method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Badboy112
    New Member
    • Oct 2008
    • 8

    #1

    where do i place my clearFields() method

    Hi guys where do i place my clearFields method so that when i click to book the 1st room it will not add that text to the second room and so forth

    here is my code


    Code:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.text.*;
    import javax.swing.text.*;
    import javax.swing.*;
    
    public class LenzHotel extends JFrame implements ActionListener
    {
    	DataInputStream output;
    	DataInputStream input;
    	//contruct components
    	JTextArea roomDisplay1 = new JTextArea();
    	JTextArea roomDisplay2 = new JTextArea();
    	JTextArea roomDisplay3 = new JTextArea();
    	JTextArea roomDisplay4 = new JTextArea();
    	JTextArea roomDisplay5 = new JTextArea();
    	JTextArea roomDisplay6 = new JTextArea();
    	JTextArea roomDisplay7 = new JTextArea();
    	JTextArea roomDisplay8 = new JTextArea();
    	JTextArea roomDisplay9 = new JTextArea();
    	JTextArea roomDisplay10 = new JTextArea();
    	JTextArea roomDisplay11 = new JTextArea();
    	JTextArea roomDisplay12 = new JTextArea();
    	JTextArea roomDisplay13 = new JTextArea();
    	JTextArea roomDisplay14 = new JTextArea();
    	JTextArea roomDisplay15 = new JTextArea();
    	JTextArea roomDisplay16 = new JTextArea();
    	JTextArea roomDisplay17 = new JTextArea();
    	JTextArea roomDisplay18 = new JTextArea();
    	JTextArea roomDisplay19 = new JTextArea();
    	JTextArea roomDisplay20 = new JTextArea();
    	JComboBox choice = new JComboBox();
    	JLabel name = new JLabel("Name");
    	JTextField nameField = new JTextField(5);
    	JLabel phone = new JLabel("Phone Number");
    	JTextField phoneField = new JTextField(5);
    	JLabel vehicle = new JLabel("Vehicle Registration Number");
    	JTextField vehicleField = new JTextField(5);
    	JLabel address = new JLabel("Customers address");
    	JTextField addressField = new JTextField(5);
    	JLabel checkin = new JLabel("Check in time and date");
    	JTextField checkinField = new JTextField(5);
    	JLabel business = new JLabel("Business or Overnight");
    	JTextField businessField = new JTextField(5);
    	JLabel tariff = new JLabel("Tariff");
    	JTextField tariffField = new JTextField(5);
    	JLabel deposit = new JLabel("Deposit");
    	JTextField depositField = new JTextField(5);
    	JLabel checkout = new JLabel("Check out Time and Date");
    	JTextField checkoutField = new JTextField(5);
    	JLabel choiceLabel = new JLabel("Clear which Field");
    	JComboBox smoking = new JComboBox();
    	JLabel bookLabel = new JLabel("Book which room");
    	JComboBox book = new JComboBox();
    
    
    
    
    	public LenzHotel()
    	{
    		super("Lenasia Hotel");
    	}
    
    	public Container createContentPane()
    	{
    		JPanel bottomPanel = new JPanel();
    		bottomPanel.add(bookLabel);
    		bottomPanel.add(book);
    			book.addItem("1");
    			book.addActionListener(this);
    			book.setActionCommand("one");
    			book.addItem("2");
    			book.setActionCommand("two");
    			book.addItem("3");
    			book.setActionCommand("three");
    			book.addActionListener(this);
    			book.addItem("4");
    			book.setActionCommand("four");
    			book.addActionListener(this);
    			book.addItem("5");
    			book.setActionCommand("five");
    			book.addActionListener(this);
    			book.addItem("6");
    			book.setActionCommand("six");
    			book.addActionListener(this);
    			book.addItem("7");
    			book.setActionCommand("seven");
    			book.addActionListener(this);
    			book.addItem("8");
    			book.setActionCommand("eight");
    			book.addActionListener(this);
    			book.addItem("9");
    			book.setActionCommand("nine");
    			book.addActionListener(this);
    			book.addItem("10");
    			book.setActionCommand("ten");
    			book.addActionListener(this);
    			book.addItem("11");
    			book.setActionCommand("eleven");
    			book.addActionListener(this);
    			book.addItem("12");
    			book.setActionCommand("twelve");
    			book.addActionListener(this);
    			book.addItem("13");
    			book.setActionCommand("thirteen");
    			book.addActionListener(this);
    			book.addItem("14");
    			book.setActionCommand("fourteen");
    			book.addActionListener(this);
    			book.addItem("15");
    			book.setActionCommand("fifteen");
    			book.addActionListener(this);
    			book.addItem("16");
    			book.setActionCommand("sixteen");
    			book.addActionListener(this);
    			book.addItem("17");
    			book.setActionCommand("seventeen");
    			book.addActionListener(this);
    			book.addItem("18");
    			book.setActionCommand("eighteen");
    			book.addActionListener(this);
    			book.addItem("19");
    			book.setActionCommand("nineteen");
    			book.addActionListener(this);
    			book.addItem("20");
    			book.setActionCommand("twenty");
    			book.addActionListener(this);
    
    
    
    
    
    		bottomPanel.add(choiceLabel);
    		bottomPanel.add(choice);
    			choice.addItem("1");
    			choice.setActionCommand("1");
    			choice.addActionListener(this);
    			choice.addItem("2");
    			choice.setActionCommand("2");
    			choice.addActionListener(this);
    			choice.addItem("3");
    			choice.setActionCommand("3");
    			choice.addActionListener(this);
    			choice.addItem("4");
    			choice.setActionCommand("4");
    			choice.addActionListener(this);
    			choice.addItem("5");
    			choice.setActionCommand("5");
    			choice.addActionListener(this);
    			choice.addItem("6");
    			choice.setActionCommand("6");
    			choice.addActionListener(this);
    			choice.addItem("7");
    			choice.setActionCommand("7");
    			choice.addActionListener(this);
    			choice.addItem("8");
    			choice.setActionCommand("8");
    			choice.addActionListener(this);
    			choice.addItem("9");
    			choice.setActionCommand("9");
    			choice.addActionListener(this);
    			choice.addItem("10");
    			choice.setActionCommand("10");
    			choice.addActionListener(this);
    			choice.addItem("11");
    			choice.setActionCommand("11");
    			choice.addActionListener(this);
    			choice.addItem("12");
    			choice.setActionCommand("12");
    			choice.addActionListener(this);
    			choice.addItem("13");
    			choice.setActionCommand("13");
    			choice.addActionListener(this);
    			choice.addItem("14");
    			choice.setActionCommand("14");
    			choice.addActionListener(this);
    			choice.addItem("15");
    			choice.setActionCommand("15");
    			choice.addActionListener(this);
    			choice.addItem("16");
    			choice.setActionCommand("16");
    			choice.addActionListener(this);
    			choice.addItem("17");
    			choice.setActionCommand("17");
    			choice.addActionListener(this);
    			choice.addItem("18");
    			choice.setActionCommand("18");
    			choice.addActionListener(this);
    			choice.addItem("19");
    			choice.setActionCommand("19");
    			choice.addActionListener(this);
    			choice.addItem("20");
    			choice.setActionCommand("20");
    			choice.addActionListener(this);
    
    
    
    
    		JPanel northPanel = new JPanel();
    		northPanel.setLayout(new GridLayout(5,4,10,10));
    		northPanel.add(roomDisplay1);
    			roomDisplay1.setColumns(5);
    			roomDisplay1.setRows(5);
    		JScrollPane scrollPane1 = new JScrollPane(roomDisplay1);
    			scrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane1.setPreferredSize(new Dimension(30,30));
    		northPanel.add(scrollPane1);
    		roomDisplay1.setLineWrap(true);
    		roomDisplay1.setBackground(Color.green);
    		roomDisplay1.setText("Room 1");
    		roomDisplay1.setEditable(false);
    		northPanel.add(roomDisplay2);
    		roomDisplay2.setColumns(5);
    		roomDisplay2.setRows(5);
    		roomDisplay2.setLineWrap(true);
    		JScrollPane scrollPane2 = new JScrollPane(roomDisplay2);
    			scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane2.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane2);
    		roomDisplay2.setText("Room 2");
    		roomDisplay2.setEditable(false);
    		roomDisplay2.setBackground(Color.green);
    		northPanel.add(roomDisplay3);
    		roomDisplay3.setColumns(5);
    		roomDisplay3.setRows(5);
    		roomDisplay3.setLineWrap(true);
    		JScrollPane scrollPane3 = new JScrollPane(roomDisplay3);
    			scrollPane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane3.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane3);
    		roomDisplay3.setText("Room 3");
    		roomDisplay3.setEditable(false);
    		roomDisplay3.setBackground(Color.green);
    		northPanel.add(roomDisplay4);
    		roomDisplay4.setColumns(5);
    		roomDisplay4.setRows(5);
    		roomDisplay4.setLineWrap(true);
    		JScrollPane scrollPane4 = new JScrollPane(roomDisplay4);
    			scrollPane4.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane4.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane4);
    		roomDisplay4.setText("Room 4");
    		roomDisplay4.setEditable(false);
    		roomDisplay4.setBackground(Color.green);
    		northPanel.add(roomDisplay5);
    		roomDisplay5.setColumns(5);
    		roomDisplay5.setRows(5);
    		roomDisplay5.setLineWrap(true);
    		JScrollPane scrollPane5 = new JScrollPane(roomDisplay5);
    			scrollPane5.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane5.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane5);
    		roomDisplay5.setText("Room 5");
    		roomDisplay5.setBackground(Color.green);
    		roomDisplay5.setEditable(false);
    		northPanel.add(roomDisplay6);
    		roomDisplay6.setColumns(5);
    		roomDisplay6.setRows(5);
    		roomDisplay6.setLineWrap(true);
    		JScrollPane scrollPane6 = new JScrollPane(roomDisplay6);
    			scrollPane6.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane6.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane6);
    		roomDisplay6.setText("Room 6");
    		roomDisplay6.setEditable(false);
    		roomDisplay6.setBackground(Color.green);
    		northPanel.add(roomDisplay7);
    		roomDisplay7.setColumns(5);
    		roomDisplay7.setRows(5);
    		roomDisplay7.setLineWrap(true);
    		JScrollPane scrollPane7 = new JScrollPane(roomDisplay7);
    			scrollPane7.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane7.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane7);
    		roomDisplay7.setText("Room 7");
    		roomDisplay7.setEditable(false);
    		roomDisplay7.setBackground(Color.green);
    		northPanel.add(roomDisplay8);
    		roomDisplay8.setText("Room 8");
    		roomDisplay8.setColumns(5);
    		roomDisplay8.setRows(5);
    		roomDisplay8.setLineWrap(true);
    		JScrollPane scrollPane8 = new JScrollPane(roomDisplay8);
    			scrollPane8.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane8.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane8);
    		roomDisplay8.setEditable(false);
    		roomDisplay8.setBackground(Color.green);;
    		northPanel.add(roomDisplay9);
    		roomDisplay9.setColumns(5);
    		roomDisplay9.setRows(5);
    		roomDisplay9.setLineWrap(true);
    		JScrollPane scrollPane9 = new JScrollPane(roomDisplay9);
    			scrollPane9.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane9.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane9);
    		roomDisplay9.setText("Room 9");
    		roomDisplay9.setEditable(false);
    		roomDisplay9.setBackground(Color.green);
    		northPanel.add(roomDisplay10);
    		roomDisplay10.setColumns(5);
    		roomDisplay10.setRows(5);
    		roomDisplay10.setLineWrap(true);
    		JScrollPane scrollPane10 = new JScrollPane(roomDisplay10);
    			scrollPane10.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane10.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane10);
    		roomDisplay10.setText("Room 10");
    		roomDisplay10.setEditable(false);
    		roomDisplay10.setBackground(Color.green);
    		northPanel.add(roomDisplay11);
    		roomDisplay11.setColumns(5);
    		roomDisplay11.setRows(5);
    		roomDisplay11.setLineWrap(true);
    		JScrollPane scrollPane11 = new JScrollPane(roomDisplay11);
    			scrollPane11.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane11.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane11);
    		roomDisplay11.setText("Room 11");
    		roomDisplay11.setEditable(false);
    		roomDisplay11.setBackground(Color.green);
    		northPanel.add(roomDisplay12);
    		roomDisplay12.setColumns(5);
    		roomDisplay12.setRows(5);
    		roomDisplay12.setLineWrap(true);
    		JScrollPane scrollPane12 = new JScrollPane(roomDisplay12);
    			scrollPane12.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane12.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane12);
    		roomDisplay12.setText("Room 12");
    		roomDisplay12.setEditable(false);
    		roomDisplay12.setBackground(Color.green);
    		northPanel.add(roomDisplay13);
    		roomDisplay13.setColumns(5);
    		roomDisplay13.setRows(5);
    		roomDisplay13.setLineWrap(true);
    		JScrollPane scrollPane13 = new JScrollPane(roomDisplay13);
    			scrollPane13.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane13.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane13);
    		roomDisplay13.setText("Room 13");
    		roomDisplay13.setEditable(false);
    		roomDisplay13.setBackground(Color.green);;
    		northPanel.add(roomDisplay14);
    		roomDisplay14.setColumns(5);
    		roomDisplay14.setRows(5);
    		roomDisplay14.setLineWrap(true);
    		JScrollPane scrollPane14 = new JScrollPane(roomDisplay14);
    			scrollPane14.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane14.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane14);
    		roomDisplay14.setText("Room 14");
    		roomDisplay14.setEditable(false);
    		roomDisplay14.setBackground(Color.green);
    		northPanel.add(roomDisplay15);
    		roomDisplay15.setColumns(5);
    		roomDisplay15.setRows(5);
    		roomDisplay15.setLineWrap(true);
    		JScrollPane scrollPane15 = new JScrollPane(roomDisplay15);
    			scrollPane15.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane15.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane15);
    		roomDisplay15.setText("Room 15");
    		roomDisplay15.setEditable(false);
    		roomDisplay15.setBackground(Color.green);
    		northPanel.add(roomDisplay16);
    		roomDisplay16.setColumns(5);
    		roomDisplay16.setRows(5);
    		roomDisplay16.setLineWrap(true);
    		JScrollPane scrollPane16 = new JScrollPane(roomDisplay16);
    			scrollPane16.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane16.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane16);
    		roomDisplay16.setText("Room 16");
    		roomDisplay16.setEditable(false);
    		roomDisplay16.setBackground(Color.green);;
    		northPanel.add(roomDisplay17);
    		roomDisplay17.setColumns(5);
    		roomDisplay17.setRows(5);
    		roomDisplay17.setLineWrap(true);
    		JScrollPane scrollPane17 = new JScrollPane(roomDisplay17);
    			scrollPane17.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane17.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane17);
    		roomDisplay17.setText("Room 17");
    		roomDisplay17.setEditable(false);
    		roomDisplay17.setBackground(Color.green);
    		northPanel.add(roomDisplay18);
    		roomDisplay18.setColumns(5);
    		roomDisplay18.setRows(5);
    		roomDisplay18.setLineWrap(true);
    		JScrollPane scrollPane18 = new JScrollPane(roomDisplay18);
    			scrollPane18.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane18.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane18);
    		roomDisplay18.setText("Room 18");
    		roomDisplay18.setEditable(false);
    		roomDisplay18.setBackground(Color.green);
    		northPanel.add(roomDisplay19);
    		JScrollPane scrollPane19 = new JScrollPane(roomDisplay19);
    			scrollPane19.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    			scrollPane19.setPreferredSize(new Dimension(30,30));
    		   northPanel.add(scrollPane19);
    		roomDisplay19.setColumns(5);
    		roomDisplay19.setRows(5);
    		roomDisplay19.setLineWrap(true);
    		roomDisplay19.setText("Room 19");
    		roomDisplay19.setEditable(false);
    		roomDisplay19.setBackground(Color.green);
    		northPanel.add(roomDisplay20);
    		roomDisplay20.setColumns(5);
    		roomDisplay20.setRows(5);
    		roomDisplay20.setLineWrap(true);
    		roomDisplay20.setText("Room 20");
    		roomDisplay20.setEditable(false);
    		roomDisplay20.setBackground(Color.green);
    
    
    				JPanel centerPanel = new JPanel();
    				centerPanel.setLayout(new GridLayout(9,9,10,10));
    				centerPanel.add(name);
    				centerPanel.add(nameField);
    				centerPanel.add(phone);
    				centerPanel.add(phoneField);
    				centerPanel.add(vehicle);
    				centerPanel.add(vehicleField);
    				centerPanel.add(address);
    				centerPanel.add(addressField);
    				centerPanel.add(checkin);
    				centerPanel.add(checkinField);
    				centerPanel.add(business);
    				centerPanel.add(businessField);
    				centerPanel.add(tariff);
    				centerPanel.add(tariffField);
    				centerPanel.add(deposit);
    				centerPanel.add(depositField);
    				centerPanel.add(checkout);
    				centerPanel.add(checkoutField);
    
    
    
    		Container c = getContentPane();
    			c.setLayout(new BorderLayout(10,10));
    			c.add(northPanel,BorderLayout.NORTH);
    			c.add(centerPanel,BorderLayout.CENTER);
    			c.add(bottomPanel,BorderLayout.SOUTH);
    		return c;
    
    	}//end of container pane
    
    
    	public void actionPerformed(ActionEvent e)
    	{
    		String arg = e.getActionCommand();
    		if (arg == "one");
    		{
    			roomDisplay1.setBackground(Color.red);
    			roomDisplay1.setText("Room 1 "+"\nName: "+
    			nameField.getText()+"\nPhone number: "+
    			phoneField.getText()+"\nVehicle Registration number: "+
    			vehicleField.getText()+"\nAddress Field: "+
    			addressField.getText()+"\nCheck in: "+
    			checkinField.getText()+"\nType of stay: "+
    			businessField.getText()+"\nTarrif: "+
    			tariffField.getText()+"\nDeposit: "+
    			depositField.getText()+"\nCheckout: "+
    			checkoutField.getText());
    		}
    
    		clearFields();
    
    		if(arg == "two");
    				roomDisplay2.setBackground(Color.red);
    				roomDisplay2.setText("Room 1 "+"\nName: "+
    				nameField.getText()+"\nPhone number: "+
    				phoneField.getText()+"\nVehicle Registration number: "+
    				vehicleField.getText()+"\nAddress Field: "+
    				addressField.getText()+"\nCheck in: "+
    				checkinField.getText()+"\nType of stay: "+
    				businessField.getText()+"\nTarrif: "+
    				tariffField.getText()+"\nDeposit: "+
    				depositField.getText()+"\nCheckout: "+
    				checkoutField.getText());
    
    	}
    
    
    
    	public static void main(String[] args)
    	{
    		JFrame.setDefaultLookAndFeelDecorated(true);
    		LenzHotel f = new LenzHotel();
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.setContentPane(f.createContentPane());
    		f.setSize(1680,1050);
    		f.setVisible(true);
    	}//end of main method
    
    	public void clearFields()
    	{
    		nameField.setText("");
    		phoneField.setText("");
    		vehicleField.setText("");
    		addressField.setText("");
    		checkinField.setText("");
    		businessField.setText("");
    		tariffField.setText("");
    		depositField.setText("");
    		checkoutField.setText("");
    	}
    }//end of main costructor method
    thanks guys
    Last edited by JosAH; Oct 19 '08, 01:51 PM. Reason: added [code] ... [/code] tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Please add proper code tags; when you compose your message read the legend
    on the right: it tells you how to do it.

    Another remark: I bet noone is going to plough through all that code and figure
    out what it is supposed to do (and doesn't do now). Post a short example that
    exhibits the unwanted behaviour and post that; this humongous piece of code
    is just too much.

    kind regards,

    Jos

    Comment

    Working...