Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    class Salesman.java:

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import java.util.Vector;
    
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public class Salesman {
    	
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			
    			@Override
    			public void run() {
    				SalesmanFrame salesmanFrame = new SalesmanFrame();
    				salesmanFrame.showUI();
    			}
    		});
    	}
    }
    
    class SalesmanFrame extends JFrame {
    	
    	SalesmanPanel panel;
    	
    	public SalesmanFrame() {		
    		panel = new SalesmanPanel();
    		
    		add(panel);
    	}
    	
    	public void showUI() {
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setSize(600,400);
    		setVisible(true);
    	}
    }
    
    class SalesmanPanel extends JPanel {
    	Performance performance;
    	Theater theater;
    	Theater newTheater;
    	Vector<Theater> theaters;
    	JComboBox performancesCombo;
    	TheaterPanel theaterPanel;
    	int performanceIndex;
    	
    	public SalesmanPanel() {
    		theater = new Theater();
    		setLayout(new BorderLayout());
    		
    		performance = new Performance();
    		theaters = theater.getTheaters(performance.getNamesOfPerformances());
    		
    		theaterPanel = new TheaterPanel() {
    			public void paintComponent(Graphics g) {
    				super.paintComponent(g);
    				if(newTheater != null)
    					newTheater.drawTheater(g);
    			}
    		};
    		
    		performancesCombo = new JComboBox(performance.getNamesOfPerformances());
    		add(performancesCombo, BorderLayout.NORTH);
    		add(theaterPanel, BorderLayout.CENTER);
    		
    		performancesCombo.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent event) {
    				JComboBox performCombo = (JComboBox) event.getSource();
    				
    				performanceIndex =  performCombo.getSelectedIndex();
    				
    				newTheater = new Theater(theaters.get(performanceIndex));
    				repaint();
    			}
    		});
    	}
    }
    
    class TheaterPanel extends JPanel {
    	
    	public TheaterPanel() {
    	}
    	
    }

  2. #22
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    file performances.txt:

    Hamlet HIT
    Macbeth ORDINARY
    Romeo and Juliet HIT
    Cinderella CHILD

  3. #23
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Good job! Seems you've embraced the approach and used it to your advantage.

    couple of minor comments:

    - in Section, getRowNumber() and getSeatsNumber() don't have to be abstract - the section knows the number of rows and columns. If you make them concrete in this class, you'll add two methods and save 4 - net savings of 2 methods :)
    - ArrayLists are generally preferred to Vectors. They do the exact same thing, but quicker.
    - in Theater, getTheaters() method should probably be static, so you dont have to create an instance before creating more instances.


    Otherwise, good job!

  4. #24
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    You've made quite a bit of progress since the last post. I sincerely apologize for my comments earlier, and I hope that you accept this. If you don't mind, I have a few suggestions for you to consider:

    1) Consider giving Section a getSeat method whose signature looks like this:
    Java Code:
    public Seat getSeat(int rowNumber, int seatNumber)
    You might want to have it throw an IndexOutOfBoundsException if rowNumber or seatNumber are < 0 or are greater than maximum. To extract the seat from your vector, you'll use both rowNumber and seatNumber, but don't forget to multiply rowNumber by numberOfSeats. Let me know if your not sure why.

    Your GUI portion of the code will use this method to return the seat selected by the mouse press.

    2) Give Seat a method getBaseSeatPrice() that returns a double for the base price of a seat, and

    3) Give Section an abstract method getSeatPrice. This will use the getBaseSeatPrice from the seat objects contained as well as (in Balcony's situation) apply a discount.

    4) Consider changing the name of Sections numberOfSeats variable to seatsPerRow as it makes more sense to me. Also, your getSeatNumber and getRowNumber methods seem misnamed to me as a better name might be getNumberOfRows() and getSeatsPerRow(). Also, perhaps these methods shouldn't be abstract as I don't see that they'll be different for any subclass of section, but that's not a major issue.

    Good luck and congrats on your progress.

  5. #25
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    Apology accepted.

    @iluxa, @curmudgeon
    Thank you for your good suggestions.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Design Editor
    By Psyclone in forum NetBeans
    Replies: 5
    Last Post: 02-04-2010, 05:28 PM
  2. help: I want to design 2D map?
    By mofaker in forum AWT / Swing
    Replies: 4
    Last Post: 10-29-2009, 01:34 AM
  3. JSP Design.
    By makpandian in forum NetBeans
    Replies: 0
    Last Post: 04-20-2009, 02:21 PM
  4. Doubt in Design doc
    By Arulraj in forum Forum Lobby
    Replies: 0
    Last Post: 06-10-2008, 12:32 PM
  5. Design Calendar UI
    By praveen.kb in forum AWT / Swing
    Replies: 0
    Last Post: 01-21-2008, 12:54 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
  •