Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone pleasedebug and fix my java code in my inItSelectPanel ( ) method so that it selects the data within my record within my
Can someone pleasedebug and fix my java code in my inItSelectPanelmethod so that it selects the data within my record within my data to display.Using this psuedocode Extract the ship name from selected item of the options from the pull down list REPEAT for each ship in the ship list where full data is stored. IF ship name is the same as the selected ship name fill all textfields with the information the ship exit REPEAT END IF 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 when using the setText method when getting integer values from the ship. The problems are the lines yearText.setTextshipgetYearBuilt lenText.setTextshipgetLength draftText.setTextshipgetDraft and beamText.setTextshipgetBeam which give me "int cannot be converted to String" can you please debug this as well?
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 windwid ;
private int windhei ;
JComboBox selectShipBox;
ArrayList flotilla new ArrayList;
private JTextField nameText, nationText,yearText, lenText, draftText, beamText;
private JButton clearButton, quitButton, addShipButton;
String fileName TiaRosasFleet.csv;
File inFile new FilefileName;
private void initSelectPanel
int fontSize ;
Font bigFont new FontArial fontSize ;
JLabel lab new JLabelSelect a Ship";
lab.setFontbigFont;
selectShipBox new JComboBox;
selectShipBox.addItemListenernew ItemListener
public void itemStateChangedItemEvent ie
String selectedShip String iegetItem;
call helper method
forShip ship: flotilla
ifshipgetNameequalsselectedShip
nameText.setTextshipgetName;
nationText.setTextshipgetNation;
yearText.setTextshipgetYearBuilt;
lenText.setTextshipgetLength;
draftText.setTextshipgetDraft;
beamText.setTextshipgetBeam;
break;
System.out.printlnSelected ship: selectedShip;
;
String shipNames Green Acres Afloat","Sputnik",
"Her Majesty's Glory",
"Sulaco","Nostromos","Flying Dutchmen","Enterprize","Black Pearl",
PT"Titanic","IronSides","Nautilus","El Vaquero","Machu Picchu",
"Folgers Best";
selectShipBox.setModelnew javax.swing.DefaultComboBoxModelshipNames;
selectShipBox new JComboBoxshipNames;
ImageIcon icon new ImageIconYachtbig.png;
int scalex ;
int scaley ;
JLabel iconLab new JLabel
public void PaintComponentGraphics g
Image img icon.getImage;
gdrawImageimg scalex,scaley, this;
;
iconLab.setPreferredSizenew Dimensionscalex scaley;
iconLab.setIconicon;
JPanel northPan new JPanel;
northPan.addiconLab;
northPan.addlab;
this.addnorthPanBorderLayout.NORTH;
northPan.addselectShipBox;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started