Question: Can someone please fix my java code in my inItSelectPanel ( ) method so that it selects the data within my record within my data

Can someone please fix my java code in my inItSelectPanel()method so that it 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. This is in a submethod within a class. I already have an an ArrayList of Ship objects and JTextFields to display ship information. My code was also giving me errors wwhen using the setText method when getting integer values from the ship.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.*;
import java.io.*;
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(ship.getYearBuilt());
lenText.setText(ship.getLength());
draftText.setText(ship.getDraft());
beamText.setText(ship.getBeam());
break;
}
}
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);
this.add(northPan,BorderLayout.NORTH);
northPan.add(selectShipBox);
}

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!