GUI Help

Joined
Oct 29, 2006
Messages
3
Reaction score
0
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);

	}

}
 
Joined
Oct 29, 2006
Messages
2
Reaction score
0
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:
Joined
Oct 29, 2006
Messages
3
Reaction score
0
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:

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top