JPANEL DISPLAY PROBLEM

The program will display the original matrix and then it won't rep

Page 1 of 1

1 Replies - 1352 Views - Last Post: 11 December 2006 - 10:11 PM Rate Topic: -----

#1 kalludgeStoodunt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-December 06

JPANEL DISPLAY PROBLEM

Posted 11 December 2006 - 10:08 PM

Attached File  Midedit.zip (18.33K)
Number of downloads: 83/* It will bing the proper frame up and display correctly the first time, but it will not overwrite the previous materials on the displayPanel. This is just the constructor part of the code, all the other mehtods work. Here's what happens:
It creates the displayPanel, the display panel adds the Jlabels and then, i click the sort button and it sorts it and it will simply just change one of the displayPanel lines. or if you reinstate the comments and get rid of the duplicate, it will just simply overwrite the last line, and then it will add on the rest.
*/
// If you load the program and look at the code it will 
// the post below is slightly different than the other file 
//you will notice the differences
/*
 * Created on Nov 30, 2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package midterm2;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

/**
 * @author Student
 *
 *
 * 
 */
public class FirmPanel extends JPanel {
	
	//Lists major things that will be used.
	
	JPanel sortPanel;
	JPanel methodPanel;
	JPanel displayPanel;
	JRadioButton nameButton, addressButton, phoneButton, payButton;
	JRadioButton selectSort, insertSort;
	//JRadioButton clear;
	JLabel firm;
	StaffMember[] johnStaff;
	boolean selectionSort; 
	JLabel firm0, firm1, firm2, firm3, firm4, firm5, firm6, firm7;
	
	public FirmPanel() 
		{
//------------------------------------------------------------	
		
		sortPanel = new JPanel();
		
		nameButton = new JRadioButton("Name", true);
		addressButton = new JRadioButton("Address");
		phoneButton = new JRadioButton("Phone");
		payButton = new JRadioButton("Pay");
		
		ButtonGroup sortBy = new ButtonGroup();
		sortBy.add (nameButton);
		sortBy.add (addressButton);
		sortBy.add (phoneButton);
		sortBy.add (payButton);

		sortPanel.add(nameButton);
		sortPanel.add(addressButton);
		sortPanel.add(phoneButton);
		sortPanel.add(payButton);
		
		ButtonListener listener = new ButtonListener();
		nameButton.addActionListener(listener);
		addressButton.addActionListener(listener);
		phoneButton.addActionListener(listener);
		payButton.addActionListener(listener);
		
		

//------------------------------------------------------------------------------
		
		
		methodPanel = new JPanel();
		
		selectSort = new JRadioButton("Select",true);
		insertSort = new JRadioButton("Insert");
		//clear = new JRadioButton("Clear");
		
		ButtonGroup sortMethod = new ButtonGroup();
		sortMethod.add (selectSort);
		sortMethod.add (insertSort);


		methodPanel.add(selectSort);
		methodPanel.add(insertSort);
		//methodPanel.add(clear);
		
		ButtonListener2 listener2 = new ButtonListener2();
		selectSort.addActionListener(listener2);
		insertSort.addActionListener(listener2);
		
		//ButtonListener3 listener3 = new ButtonListener3();
		//clear.addActionListener(listener3);


		
//-------------------------------------------------------------------------------				
		displayPanel = new JPanel();
		
		displayPanel.setPreferredSize (new Dimension(850,820));
		displayPanel.setBackground (Color.white);
		//displayPanel.setLocation(0, 450);
//-------------------------------------------------------------------------------		
		this.setSize(800, 600);
		this.add(sortPanel);
		this.add(methodPanel);
		this.add(displayPanel);	
		
		
		
		//-------------------------------------------------------------------------------------
		
		johnStaff = new StaffMember[8];	//creates new array of Staff members
		
		johnStaff[0] = new StaffMember("Adam","1234 Highland Cove","610-555-7384");
		johnStaff[1] = new Employee("Sarah","9762 E 6123 S","215-555-3827","123-45-6789",50,50.00);
		johnStaff[2] = new Executive("Mark","Hollywood Vine ","733-555-2969","951-84-6237",50,50.00);
		johnStaff[3] = new Volunteer("Laura","520 N Canyon Rd","663-555-3984");
		johnStaff[4] = new Hourly("Lucas" , "1100 Penn. Ave  " , "987-654-3210" , 10 , "732-85-2441", 7.50);
		johnStaff[5] = new Executive("John","842 Spring Lane","894-365-2146","741-85-2369",50,50.00);
		johnStaff[6] = new Hourly("Eliza" , "3200 Rockefeller" , "841-321-1977" , 10 , "963-85-2741", 7.50);
		johnStaff[7] = new Employee("Erica", "2222 May Hall", "546-555-9000", "789-45-6123", 50, 50);
		
		
		/*for (int i=0; i <= johnStaff.length-1; i++)
		{

			String display = johnStaff[i].toString();
			System.out.println(johnStaff[i].toString());
			
			firm = new JLabel (display, SwingConstants.LEFT);
			firm.setFont (new Font ("Helvetica", Font.BOLD, 11));
			
			displayPanel.add(firm);
			

		}
		*/
		
		//for (int i=0; i <= 0; i++)
		{
			String display = johnStaff[0].toString();
			firm0 = new JLabel (display);
			firm0.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm0);
		}
		
		
		//for (int i=1; i <= 1; i++)
		{
			String display = johnStaff[1].toString();
			firm1 = new JLabel (display);
			firm1.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm1);

		}
		
		//for (int i=2; i <= 2; i++)
		{
			String display = johnStaff[2].toString();
			firm2 = new JLabel (display);
			firm2.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm2);

		}
		
		//for (int i=3; i <= 3; i++)
		{
			String display = johnStaff[3].toString();
			firm3 = new JLabel (display);
			firm3.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm3);
	}
		
		//for (int i=4; i <= 4; i++)
		{
			String display = johnStaff[4].toString();
			firm4 = new JLabel (display);
			firm4.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm4);
	}
		
		//for (int i=5; i <= 5; i++)
		{
			String display = johnStaff[5].toString();
			firm5 = new JLabel (display);
			firm5.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm5);
		}
		
		//for (int i=6; i <= 6; i++)
		{
			String display = johnStaff[6].toString();
			firm6 = new JLabel (display);
			firm6.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm6);
		}
		
		//for (int i=7; i <= 7; i++)
		{
			String display = johnStaff[7].toString();
			firm7 = new JLabel (display);
			firm7.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm7);
		}

		
		
		}
		
	public void display()
	{
		//FirmPanel().remove.displayPanel;
		/*for (int i=0; i <= johnStaff.length-1; i++)
		{
			
			String display = johnStaff[i].toString();
			System.out.println(johnStaff[i].toString());
			
			firm = new JLabel (display, SwingConstants.LEFT);
			firm.setFont (new Font ("Helvetica", Font.BOLD, 11));
			
			displayPanel.add(firm);
		}*/
		
		//for (int i=0; i <= 0; i++)
		{
			String display = johnStaff[0].toString();
			firm0.setText(display);
			firm.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm0);
		}
		
		
		//for (int i=1; i <= 1; i++)
		{
			String display = johnStaff[1].toString();
			firm1.setText(display);
			firm1.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm1);

		}
		
		//for (int i=2; i <= 2; i++)
		{
			String display = johnStaff[2].toString();
			firm2.setText(display);
			firm2.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm2);

		}
		
		//for (int i=3; i <= 3; i++)
		{
			String display = johnStaff[3].toString();
			firm3.setText(display);
			firm3.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm3);
	}
		
		//for (int i=4; i <= 4; i++)
		{
			String display = johnStaff[4].toString();
			firm4.setText(display);
			firm4.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm4);
	}
		
		//for (int i=5; i <= 5; i++)
		{
			String display = johnStaff[5].toString();
			firm5.setText(display);
			firm5.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm5);
		}
		
		//for (int i=6; i <= 6; i++)
		{
			String display = johnStaff[6].toString();
			firm6.setText(display);
			firm6.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm6);
		}
		
		//for (int i=7; i <= 7; i++)
		{
			String display = johnStaff[7].toString();
			firm7.setText(display);
			firm7.setFont(new Font ("Helvetica", Font.BOLD, 11));
			displayPanel.add(firm7);
		}

		
		
		
		
	}
	
//---------------------------------------------------------------------------------------------------			
		public class ButtonListener implements ActionListener
		{
			
			public void actionPerformed (ActionEvent event)
			{
				
			
			if (event.getSource() == nameButton)
			{
				if (selectionSort)
					Sorting.selectionSortName(johnStaff);
				else
					Sorting.insertionSortName(johnStaff);
			}

			
				
			if (event.getSource() == addressButton)
			{		if (selectionSort)
					Sorting.selectionSortAddress(johnStaff);
					else
						Sorting.insertionSortAddress(johnStaff);
			}
			if (event.getSource() == phoneButton)
			{		if (selectionSort)
					Sorting.selectionSortPhone(johnStaff);
					else
						Sorting.insertionSortPhone(johnStaff);
			}
			if (event.getSource() == payButton)
			{		if (selectionSort)
					Sorting.selectionSortPay(johnStaff);
					else
						Sorting.insertionSortPay(johnStaff);
			}
			
			//displayPanel = new JPanel();
			display();
			updateUI();
			}
			
		}
		public class ButtonListener2 implements ActionListener
		{
			public void actionPerformed(ActionEvent e)
			{
				if (e.getSource() == selectSort)
				{
					selectionSort = true;
				}
				else
					selectionSort = false;
			}
			
			
		}
		

//--------------------------------------------------------------------------------------------------		
		
			
}


Is This A Good Question/Topic? 0
  • +

Replies To: JPANEL DISPLAY PROBLEM

#2 eXceed69  Icon User is offline

  • "Super Sentai Knight Of DawN"
  • member icon

Reputation: 7
  • View blog
  • Posts: 688
  • Joined: 12-November 06

Re: JPANEL DISPLAY PROBLEM

Posted 11 December 2006 - 10:11 PM

....long enough in caffeine lounge...ADMIN plz move this thread
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1