Answered step by step
Verified Expert Solution
Link Copied!

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 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 when using the setText method when getting integer values from the ship. The problems are the lines yearText.setText(ship.getYearBuilt()), lenText.setText(ship.getLength()), draftText.setText(ship.getDraft()), and beamText.setText(ship.getBeam()) 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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

What approach is used by the auditor to test for kiting?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago