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.
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);
}
}