GUI Help

Discussion in 'Java' started by SunDevil, Oct 30, 2006.

  1. SunDevil

    SunDevil

    Joined:
    Oct 29, 2006
    Messages:
    3
    Location:
    Hot Phoenix Arizona
    Hi All,

    I have a list of videos that are displayed when the app launches, now I have it populated with a few videos already. There is a button when its clicked should open some dialog boxes to collect the information for the next video that should be added to the list (and then displayed with the rest of them.) I got the dialog portion correct, however I am banging my head trying to add it to the existing list. Any help would be most appreciated.
    Code:
    import java.awt.*;
    
    
    
    public class VideoStoreUI extends JFrame
    
    {
    
    protected static final String layout = null;
    
    JButton myButton1 = new JButton("Click to Add");
    
    JLabel myLabel = new JLabel("Add Video to List"); 
    
    public static void main(String[] args) 
    
    {
    
        Video video0 = new Video();
    
        video0.setMovieTitle("Star Wars, ");
    
        video0.setMovieRating("PG-13, ");
    
        video0.setMovieCategory("Science-Fiction, ");
    
        video0.setDirector("George Lucas, ");
    
        video0.setVideoID(101);
    
         video0.setReleaseDate("1977, ");
    
        
    
         Video video1 = new Video();
    
         video1.setMovieTitle("The Pink Panther, ");
    
         video1.setMovieRating ("PG-13, ");
    
         video1.setMovieCategory("Comedy, ");
    
         video1.setDirector("Peter Sellers, ");
    
         video1.setVideoID(131);
    
         video1.setReleaseDate("1963, "); 
    
         
    
         Video video2 = new Video();
    
         video2.setMovieTitle("The Village, ");
    
         video2.setMovieRating("R-17, ");
    
         video2.setMovieCategory ("Thriller, ");
    
         video2.setDirector("M Knight Shamalam, ");
    
         video2.setVideoID(224);
    
         video2.setReleaseDate("2004, ");
    
        
    
         Video [] videos = new Video [3];
    
         videos [0] = video0;
    
         videos [1] = video1;
    
         videos [2] = video2; 
    
         
    
         for (int i = 0; i < videos.length; i++) 
    
         {
    
              VideoManager.getInstance().addVideo(videos[i]);
    
         }
    
         new VideoStoreUI();
    
    }
    
     public VideoStoreUI() 
    
     {
    
        initialize(); 
    
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    
     }
    
    
    
    public void initialize() 
    
    {
    
        setSize(600, 400);
    
        setTitle("Video Store UI");
    
        setResizable(true); 
    
    
    
        Object [] videos = {};
    
        videos = VideoManager.getInstance().getVideos().toArray();
    
        JList myList = new JList(videos);
    
        int size = myList.getModel().getSize();
    
        
    
        Container c = getContentPane(); 
    
        LayoutManager layout1 = new BorderLayout();
    
        c.setLayout(layout1);
    
        c.add(BorderLayout.CENTER, myList);
    
        c.add(BorderLayout.SOUTH, myButton1);
    
        c.add(BorderLayout.NORTH, myLabel);
    
        
    
        myButton1.addActionListener (new ActionListener() 
    
        {
    
            public void actionPerformed(ActionEvent e) 
    
            {
    
    //Stuck here trying to add another video to the existing list.
                JOptionPane.showInputDialog("Enter the Movie Title: ");
    
                JOptionPane.showInputDialog("Enter the Movie Rating: ");
    
                JOptionPane.showInputDialog("Enter the Movie Category: ");
    
                JOptionPane.showInputDialog("Enter the Movie Director: ");
    
                JOptionPane.showInputDialog("Enter the Movie ID Number: ");
    
                JOptionPane.showInputDialog("Enter the Movie Release Date: ");	
    
            }
    
        });
    
        setVisible(true);
    
    	}
    
    }
    
     
    SunDevil, Oct 30, 2006
    #1
    1. Advertising

  2. SunDevil

    jAlexander

    Joined:
    Oct 29, 2006
    Messages:
    2
    Hi, hope this can solve your problem :smile:.

    Please note, this piece of code does not do any validation, so it may cause error, if the user cancelled the input and your method waiting for non-null value, or the if the user input the wrong data-type.

    Code:
    // ... your code ...
    
    // Change the myList's declaration as final, so we can access 
    // from inside myButton1's ActionListener.actionPerfomed.
    final JList myList = new JList(videos);
    
    // ... your code ...
    
    myButton1.addActionListener (new ActionListener() 
    {
        public void actionPerformed(ActionEvent e) 
        {
    	Video newVideo = new Video();
    
    	String s = JOptionPane.showInputDialog("Enter the Movie Title: ");
    	newVideo.setMovieTitle(s);
    
    	s = JOptionPane.showInputDialog("Enter the Movie Rating: ");
    	newVideo.setMovieRating(s);
    
    	s = JOptionPane.showInputDialog("Enter the Movie Category: ");
    	newVideo.setMovieCategory(s);
    
    	s = JOptionPane.showInputDialog("Enter the Movie Director: ");
    	newVideo.setDirector(s);
    
    	s = JOptionPane.showInputDialog("Enter the Movie ID Number: ");
    	int id = Integer.parseInt(s);
    	newVideo.setVideoID(id);
    
    	s = JOptionPane.showInputDialog("Enter the Movie Release Date: ");
    	newVideo.setReleaseDate(s);
    
    	VideoManager.getInstance().addVideo(newVideo);
    	myField.setListData(VideoManager.getInstance().getVideos().toArray());
        }
    });
    
    // ... your code ...
    

    Regards,


    SK - jAlexander
     
    Last edited: Oct 31, 2006
    jAlexander, Oct 31, 2006
    #2
    1. Advertising

  3. SunDevil

    SunDevil

    Joined:
    Oct 29, 2006
    Messages:
    3
    Location:
    Hot Phoenix Arizona
    Thank you I have imported it into my project, and (videos) has a multiple marker, cannot be resolved issue. But I really do appreciate your help, I read it over several times to understand what it is you were getting at. Of course I will read over the logic some more, and thanks again!
    oh I found it! Doh!
     
    Last edited: Nov 5, 2006
    SunDevil, Nov 2, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. paul.foreman

    GUI - GUI value passing

    paul.foreman, Oct 22, 2004, in forum: Java
    Replies:
    5
    Views:
    782
    Michael Rauscher
    Oct 25, 2004
  2. ulysses
    Replies:
    4
    Views:
    802
    Werner Schiendl
    Oct 22, 2003
  3. Andrew Lapidas

    PyGTK GUI update without signals from GUI

    Andrew Lapidas, Apr 13, 2008, in forum: Python
    Replies:
    0
    Views:
    428
    Andrew Lapidas
    Apr 13, 2008
  4. Stefan Ram
    Replies:
    3
    Views:
    509
    Arne Vajhøj
    Nov 20, 2011
  5. Hal Fulton

    GUI and non-GUI data

    Hal Fulton, Aug 5, 2004, in forum: Ruby
    Replies:
    1
    Views:
    158
    Austin Ziegler
    Aug 5, 2004
Loading...

Share This Page