Question: package application; import java.net.URL; import javafx.application.Application; import javafx.fxml . FXMLLoader; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.HBox; public class Main extends Application { @Override public void

package application;
import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
public class Main extends Application {
@Override
public void start(Stage stage){
try {
URL url = getClass().getResource("state_names.fxml");
HBox root = FXMLLoader.load(url);
Scene scene = new Scene(root,350,200);
stage.setScene(scene);
stage.setTitle("State Names");
stage.show();
} catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args){
launch(args);
}
}
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionModel;
import javafx.scene.control.SingleSelectionModel;
public class StateNamesController {
private StateNamesModel model;
@FXML private ComboBox stateCodes;
@FXML private Label stateName;
private SingleSelectionModel selectionModel;
public void initialize()
{
model = new StateNamesModel();
// populate combobox with data from the Model
stateCodes.getItems().addAll( model.getStateCodeList());
// get a reference to the SingleSelectionModel
selectionModel = stateCodes.getSelectionModel();
// initialize View with initial data from Model
selectionModel.select( model.getSelectedIndex());
stateName.setText( model.getSelectedStateName());
}
@FXML private void itemSelected(ActionEvent e)
{
int index = selectionModel.getSelectedIndex();
model.updateSelection(index);
stateName.setText(model.getSelectedStateName());
}
}
package application;
public class StateNamesModel {
private String[] stateCodeList={"CA","IL","WI","OH","FL"};
private String[] stateNames ={"California", "Illinois","Wisconsin", "Ohio", "Florida"};
private int selectedIndex;
public StateNamesModel()
{
selectedIndex =0;
}
public String [] getStateCodeList()
{
String [] temp = new String[stateCodeList.length];
for(int i=0; i< stateCodeList.length; i++)
{
temp[i]= stateCodeList[i];
}
return temp;
}
public int getSelectedIndex()
{
return selectedIndex;
}
public void updateSelection(int index)
{
selectedIndex = index;
}
public String getSelectedStateName()
{
return stateNames[selectedIndex];
}
}
With so many technical issues, I want to ensure that everyone has a working system. I think we have the problem resolved, so I need everyone to create a project, load the files I have provided and run it. Then provide a screenshot that shows that it is working.
StateNames App.zipDownload StateNames App.zipOpen this document with ReadSpeaker docReader
Please complete this as soon as possible, so I can verify that the solution worked, but complete no later than class on Thursday.

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 Programming Questions!