FilmCast
import java.util.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class FilmCastII extends JFrame{
//ds
Person person;
Cast filmCast = new Cast();
String output = "";
int row,col;
public static void main(String[] args){
FilmCastII theCast = new FilmCastII();
theCast.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Toolkit toolkit = theCast.getToolkit();
Dimension winSize = toolkit.getScreenSize();
//center screen
theCast.setBounds(winSize.width/4,winSize.height/4,winSize.width/2,winSize.height/2);
theCast.setVisible(true);
}
public FilmCastII(){
//window title
super("THE CAST FOR THE FILM");
//populate the crowd
for(;;){
person = readPerson();
if (person == null){
break;
}
filmCast.add(person);
}
int count = filmCast.size();
output += "You've added"+count+(count==1?"person":"people")+"to the film cast.\n";
//show the members of the cast
Iterator thisLot = filmCast.iterator();
output += "\nCasted in the Film are:\n";
//display the people in the cast
while (thisLot.hasNext()){
output+=(thisLot.next())+"\n";
}
//display output
Container pane = getContentPane();
JTextArea textarea = new JTextArea(row,col);
textarea.setText(output);
textarea.setFont(new Font("Tahoma",Font.PLAIN,14));
textarea.setBackground(new Color(250,250,0));
pane.add(textarea);
//add bottom panel
//pane.add(new BottomPanel(), BorderLayout.SOUTH);
}
//readPerson method
//enter person from keyboard
static public Person readPerson(){
//read in the first name
String fullName = JOptionPane.showInputDialog(null,
"\nPlease enter fullname of the actor and actress\n"+
"format: familyname, firstname \nor enter ! to end.|n",
"INPUT FULLNAME OF STAR",JOptionPane.QUESTION_MESSAGE);
fullName = fullName.trim();
if(fullName.charAt(0) == '!'){
return null;
}
//check if format is correct
char separator = ',';
int index = 0, endIndex = 0;
String firstname,surname;
//extract firstname and Lastname of actor/actress
endIndex = fullName.indexOf(separator,index);
surname = fullName.substring(0,endIndex);
firstname = fullName.substring(endIndex + 1, fullName.length());
return new Person(firstname,surname);
}
No comments:
Post a Comment