Question: Can someone please add the code to my inItSelectPanel ( ) method that selects the data within my record within my data to display.Using this

Can someone please add the code to my inItSelectPanel() method that selects the data within my record within my data to display.Using this psuedocode 1. Extract the ship name from selected item of the options from the pull down list 2. REPEAT for each ship in the ship list where full data is stored. 43.4.5.6. IF ship name is the same as the selected ship name fill all textfields with the information the ship exit REPEAT END IF 7. END REPEAT. It should display the information of the ship based off of what ship name the user has selected. All ships have the same attributes. This is in a submethod within a class. I already have an an ArrayList of Ship objects and JTextFields to display ship information.
Code so far:
public class ShipWindow extends JFrame
{
//dimensions of the window
private int wind_wid =650;
private int wind_hei =240;
JComboBox selectShipBox;
ArrayList flotilla = new ArrayList();
private JTextField nameText, nationText,yearText, lenText, draftText, beamText;
private JButton clearButton, quitButton, addShipButton;
String fileName =("Tia_RosasFleet.csv");
File inFile = new File(fileName);
private void initSelectPanel()
{
int font_Size =26;
Font bigFont = new Font("Arial",1, font_Size );
JLabel lab = new JLabel("Select a Ship");
lab.setFont(bigFont);
selectShipBox = new JComboBox();
selectShipBox.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent ie)
{
String selectedShip =(String) ie.getItem();
//call helper method
for(Ship ship: flotilla)
{
if(ship.getName().equals(selectedShip))
{
nameText.setText(ship.getName());
nationText.setText(ship.getNation());
yearText.setText(Integer.toString(ship.getYearBuilt()));
lenText.setText(Double.toString(ship.getLength()));
draftText.setText(Double.toString(ship.getDraft()));
beamText.setText(Double.toString(ship.getBeam()));
}
}
System.out.println("Selected ship: "+ selectedShip);
}
});
String[] shipNames ={"Green Acres Afloat","Sputnik",
"Her Majesty's Glory",
"Sulaco","Nostromos","Flying Dutchmen","Enterprize","Black Pearl",
"PT109","Titanic","IronSides","Nautilus","El Vaquero","Machu Picchu",
"Folgers Best"};
selectShipBox.setModel(new javax.swing.DefaultComboBoxModel>(shipNames));
selectShipBox = new JComboBox(shipNames);
ImageIcon icon = new ImageIcon("Yacht_big.png");
int scalex =164;
int scaley =82;
JLabel iconLab = new JLabel()
{
public void PaintComponent(Graphics g)
{
Image img = icon.getImage();
g.drawImage(img ,0,0, scalex,scaley, this);
}
};
iconLab.setPreferredSize(new Dimension(scalex, scaley));
iconLab.setIcon(icon);
JPanel northPan = new JPanel();
northPan.add(iconLab);
northPan.add(lab);
northPan.add(selectShipBox);
this.add(northPan,BorderLayout.NORTH);
}Green Acres Afloat, USA, 1910,180,45,95
Sputnik, Russia, 1911,64,16,38
Her Majesty's Glory, UK,1945,117,29,68
Sulaco, USA, 1975,45,11,31
Nost romos, USA, 1914,194,49,101
Flying Dutchmen, Tortuga, 1912,69,17,36
Enterprize, USSF, 1997,125,31,65
Black Pearl, Barbados, 1925,196,49,106
PT109, USN, 1933,151,38,77
Titanic, UK,1995,188,47,97
IronSides, USA, 1907,126,32,69
Nautilus, no flag, 1886,127,32,68
E1 Vaquero, Argentina, 1986,91,23,51
Machu Picchu Skiff, Peru, 2004,135,34,76
Folgers Best, Columbia, 1959,197,49,108
 Can someone please add the code to my inItSelectPanel() method that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!