Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的产品列表列表视图赢得';不允许与listview进行任何交互_Java_Listview - Fatal编程技术网

Java 我的产品列表列表视图赢得';不允许与listview进行任何交互

Java 我的产品列表列表视图赢得';不允许与listview进行任何交互,java,listview,Java,Listview,因此,这是我的Shoppinglist应用程序来启动窗口,不幸的是,products部分的listview甚至不允许使用鼠标进行任何交互,只允许使用箭头键 import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.stage.Stage; import javaf

因此,这是我的Shoppinglist应用程序来启动窗口,不幸的是,products部分的listview甚至不允许使用鼠标进行任何交互,只允许使用箭头键

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.Pane;

public class ShoppingListApp extends Application {
    private GroceryItem[] GroceryList;
    ShopperListAppView1 view  = new ShopperListAppView1();
    private Shopper shopper = new Shopper();
    private Carryable item ;

    public ShoppingListApp() { GroceryList = Shopper.List1();}

    public void start(Stage primaryStage){
        Pane aPane = new Pane();
        aPane.getChildren().add(view);

        view.getButtonPane().getBuy().setOnAction(new EventHandler<ActionEvent>(){
        public void handle(ActionEvent event) { handleBuyButtonPress();}
        });

        view.getButtonPane().getReturnb().setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) { handleReturnButtonPress();}
        });

        view.getButtonPane().getCheckout().setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) { handleCheckoutButtonPress();}
        });

        primaryStage.setTitle("Grocery Store Application");
        primaryStage.setResizable(false);
        primaryStage.setScene(new Scene(aPane));
        view.update(GroceryList, 0);
        primaryStage.show();
    }

    private void handleBuyButtonPress(){
        for (int i = 0; i < Shopper.List1().length; i++){
            if (view.getpList().getSelectionModel().getSelectedItem() == Shopper.List1()[i].getDescription()){
                item = Shopper.List1()[i];
            }
        }
        shopper.addItem(item);
        view.update(GroceryList, 0);
    }

    private void handleReturnButtonPress(){
        for(int i = 0; i < Shopper.List1().length; i++){
            if (view.getcList().getSelectionModel().getSelectedItem() == Shopper.List1()[i].getDescription()){
                item = Shopper.List1()[i];
            }
        }
        shopper.removeItem(item);
        view.update(GroceryList, 0);
    }

    private void handleCheckoutButtonPress(){
        shopper.computeTotalCost();
        shopper.packBags();
        view.update(GroceryList, 0);
    }

    public static void main(String[] args) { launch(args); }
}
导入javafx.application.application;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.scene.scene;
导入javafx.stage.stage;
导入javafx.scene.layout.Pane;
公共类ShoppingListApp扩展了应用程序{
私人杂货店项目[]杂货店列表;
ShopperListAppView1视图=新的ShopperListAppView1();
私人购物者=新购物者();
私人携带物品;
public ShoppingListApp(){GroceryList=Shopper.List1();}
公共无效开始(阶段primaryStage){
窗格aPane=新窗格();
aPane.getChildren().add(视图);
view.getButtonPane().getBuy().setOnAction(新事件处理程序(){
公共无效句柄(ActionEvent事件){handleBuyButtonPress();}
});
view.getButtonPane().getReturnb().setOnAction(新事件处理程序(){
公共无效句柄(ActionEvent事件){HandlerReturnButtonPress();}
});
view.getButtonPane().getCheckout().setOnAction(新事件处理程序(){
公共无效句柄(ActionEvent事件){handleCheckoutButtonPress();}
});
primaryStage.setTitle(“杂货店应用程序”);
primaryStage.SetResizeable(假);
初始阶段。设置场景(新场景(aPane));
view.update(GroceryList,0);
primaryStage.show();
}
专用无效把手BuyButtonPress(){
对于(int i=0;i
然后是购物列表应用程序视图,用于显示控制器的窗口。这还保存更新方法以刷新屏幕

import javafx.geometry.Pos;
import javafx.scene.control.ListView;
import javafx.scene.control.Label;
import javafx.collections.FXCollections;
import javafx.scene.layout.Pane;
import javafx.scene.control.TextField;

public class ShopperListAppView1 extends Pane implements GroceryView {
    private ListView<String> pList, sList, cList;
    private ShopperButtonPane buttonPane;
    private TextField priceText;

    public ListView<String> getpList() { return pList; }
    public ListView<String> getcList() { return cList; }
    public ListView<String> getsList() { return sList; }

    public ShopperButtonPane getButtonPane() { return buttonPane; }

    public ShopperListAppView1(){
        Label products = new Label("Product");
        products.relocate(10, 10);
        Label shoppingcart = new Label("Shopping Cart");
        shoppingcart.relocate(220,10);
        Label contents = new Label("Contents");
        contents.relocate(430, 10);
        Label price = new Label("Total Price:");
        price.setStyle("-fx-font: 12 arial; -fx-base: WHITE; -fx-text-fill: rgb(0,0,0);");
        price.setAlignment(Pos.TOP_LEFT);
        price.relocate(565, 355);
        price.setPrefSize(65,25);

        priceText = new TextField();
        priceText.relocate(630,355);
        priceText.setPrefSize(100, 25);
        priceText.setEditable(false);

        pList = new ListView<String>();
        pList.relocate(10, 45);
        pList.setPrefSize(200, 300);

        sList = new ListView<String>();
        sList.relocate(220, 45);
        sList.setPrefSize(200, 300);

        cList = new ListView<String>();
        cList.relocate(430, 45);
        cList.setPrefSize(300, 300);

        buttonPane = new ShopperButtonPane();
        buttonPane.relocate(0, 0);
        buttonPane.setPrefSize( 540,25);

        getChildren().addAll(products, shoppingcart, contents, price, pList, cList, sList, buttonPane, priceText);

        setPrefSize(740, 390);
    }

    public void update(GroceryItem[] model, int selectedItem) {
        String[] Product = new String[Shopper.List1().length];
        String[] Cart = new String[Shopper.List1().length];
        String[] Contents = new String[Shopper.List1().length];
        Shopper shopper = new Shopper();

        for (int i = 0; i < Shopper.List1().length; i++) {
            Product[i] = model[i].toString();
            if (shopper.getCart()[i] != null){
                Cart[i] = shopper.getCart()[i].getDescription();
            }
        }

        buttonPane.getBuy().setDisable(pList.getSelectionModel().getSelectedIndex() < 0);     
        buttonPane.getReturnb().setDisable(cList.getSelectionModel().getSelectedIndex() < 0);
        buttonPane.getCheckout().setDisable(cList.hasProperties());

        priceText.setText(shopper.StringTotalCost());
        priceText.setAlignment(Pos.BASELINE_RIGHT);
        pList.setItems(FXCollections.observableArrayList(Product));
        sList.setItems(FXCollections.observableArrayList(Cart));
    }
}
导入javafx.geometry.Pos;
导入javafx.scene.control.ListView;
导入javafx.scene.control.Label;
导入javafx.collections.FXCollections;
导入javafx.scene.layout.Pane;
导入javafx.scene.control.TextField;
公共类ShopperListAppView1扩展窗格实现GroceryView{
私有列表视图pList、sList、cList;
私人商店按钮按钮按钮按钮;
私有文本字段priceText;
public ListView getpList(){return pList;}
public ListView getcList(){return cList;}
public ListView getsList(){return sList;}
public ShopperButtonPane getButtonPane(){return buttonPane;}
public ShopperListAppView1(){
标签产品=新标签(“产品”);
产品。重新定位(10,10);
标签shoppingcart=新标签(“购物车”);
购物车。重新安置(220,10);
标签内容=新标签(“内容”);
搬迁(430,10);
标签价格=新标签(“总价:”);
price.setStyle(“-fx字体:12 arial;-fx基:白色;-fx文本填充:rgb(0,0,0);”);
价格设置对齐(位置左上方);
重新安置(565355);
价格。设定价格(65,25);
priceText=新文本字段();
重新安置(630355);
priceText.setPrefSize(100,25);
priceText.setEditable(false);
pList=newlistview();
重新安置(10,45);
pList.setPrefSize(200300);
sList=newlistview();
重新定位(220,45);
sList.setPrefSize(200300);
cList=newlistview();
客户搬迁(43045);
cList.setPrefSize(300300);
buttonPane=新的ShopperButtonPane();
按钮平面重新定位(0,0);
按钮平面设置尺寸(540,25);
getChildren().addAll(产品、购物车、内容、价格、pList、cList、sList、按钮平面、价格文本);
setPrefSize(740390);
}
公共作废更新(GroceryItem[]模型,int-selectedItem){
String[]Product=新字符串[Shopper.List1().length];
字符串[]购物车=新字符串[Shopper.List1().length];
String[]Contents=新字符串[Shopper.List1().length];
购物者购物者=新购物者();
对于(int i=0;i
请解释一下,当前输出和预期输出是什么。请解释一下,当前输出和预期输出是什么。