运行报错,不知道错哪里,请前辈指点package application;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class Book {
private SimpleStringProperty barcodeOfBook = null;
private SimpleStringProperty nameOfBook = null;
public Book(String barcode, String nameOfBook) {
this.barcodeOfBook = new SimpleStringProperty(barcode);
this.nameOfBook = new SimpleStringProperty(nameOfBook);
}
public String getBarcodeBook() {
return barcodeOfBook.get();
}
public SimpleStringProperty barcodeOfBookProperty() {
return barcodeOfBook;
}
public String getNameOfBook() {
return nameOfBook.get();
}
public SimpleStringProperty nameOfBookProperty() {
return nameOfBook;
}
}
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
public class MainApp extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("SamplePane.fxml"));
primaryStage.setScene(new Scene(loader.load()));
primaryStage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
package application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
public class MainController {
@FXML
private TableView<Book> table;
@FXML
private TableColumn<Book, String> barcodeOfBookCol;
@FXML
private TableColumn<Book, String> nameOfBookCol;
private ObservableList<Book> cellData = FXCollections.observableArrayList();
public void initialize() {
// 初始化数据
loadData();
// 配置列的CellValueFactory
barcodeOfBookCol.setCellValueFactory(cellData -> cellData.getValue().barcodeOfBookProperty());
nameOfBookCol.setCellValueFactory(cellData -> (cellData.getValue().nameOfBookProperty()));
// 将数据设置到表格中
table.setItems(cellData);
}
private void loadData() {
// 添加示例数据
cellData.add(new Book("Alice", "25"));
cellData.add(new Book("Bob", "30"));
cellData.add(new Book("Charlie", "35"));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<fx:root type="BorderPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="基本数据管理">
<items>
<MenuItem mnemonicParsing="false" text="日常销售" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="重新打印业务数据" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="退 出" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="查询与修改">
<items>
<MenuItem mnemonicParsing="false" text="库存及相关查询" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="基本数据管理">
<items>
<MenuItem mnemonicParsing="false" text="图书资料管理" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<StackPane layoutY="8.0">
<children>
<BorderPane>
<top>
<Pane>
<children>
<Label alignment="CENTER" layoutX="24.0" layoutY="3.0" prefHeight="36.0" prefWidth="144.0" text="单号" textAlignment="CENTER">
<font>
<Font size="20.0" />
</font>
</Label>
<TextArea editable="false" layoutX="230.0" layoutY="4.0" prefHeight="37.0" prefWidth="200.0" />
</children>
</Pane>
</top>
<center>
<TableView fx:id="table" prefHeight="305.0" prefWidth="967.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="barcodeOfBookCol" prefWidth="153.0" resizable="false" text="书号" />
<TableColumn fx:id="nameOfBookCol" prefWidth="117.0" resizable="false" text="书 名" />
<TableColumn minWidth="0.0" prefWidth="94.0" resizable="false" text="单价" />
<TableColumn minWidth="0.0" prefWidth="130.0" resizable="false" text="折扣" />
<TableColumn prefWidth="130.0" resizable="false" text="价格" />
<TableColumn prefWidth="130.0" resizable="false" text="数量" />
<TableColumn prefWidth="150.0" resizable="false" text="码洋" />
<TableColumn prefWidth="150.0" resizable="false" text="金额" />
</columns>
</TableView>
</center>
<bottom>
<Pane BorderPane.alignment="CENTER">
<children>
<TextArea layoutX="52.0" layoutY="10.0" prefHeight="35.0" prefWidth="214.0" />
<TextArea layoutX="428.0" layoutY="11.0" prefHeight="32.0" prefWidth="200.0" />
<TextArea layoutX="663.0" layoutY="14.0" prefHeight="26.0" prefWidth="200.0" />
<TextArea layoutX="918.0" layoutY="15.0" prefHeight="24.0" prefWidth="200.0" />
<StackPane layoutX="-73.0" layoutY="-340.0" />
</children>
</Pane>
</bottom>
</BorderPane>
</children>
</StackPane>
</center>
<bottom>
<Pane prefHeight="65.0" prefWidth="1311.0" BorderPane.alignment="CENTER">
<children>
<TextField layoutX="213.0" layoutY="21.0" />
<TextArea layoutX="556.0" layoutY="22.0" prefHeight="22.0" prefWidth="200.0" />
<Button layoutX="949.0" layoutY="21.0" mnemonicParsing="false" prefHeight="23.0" prefWidth="162.0" text="Button" />
</children>
</Pane>
</bottom>
</fx:root>
本帖最后由 wuliangtdi 于 2023-7-13 13:02 编辑
C#和Java的基础语法差不多。可能需要学一点高级的用法。比如方法拓展、linq等(语法不会的,问问gpt呗。)。而且C#也可以用数据库啊。框架也有啊,像EFCore(这个是微软官方的)、Sqlsugar、Freesql等框架。之前用过JavaFx,但是没有用fxml这玩意。感觉不是很好用。就直接用纯代码撸 时间上来不及的话,可以先看看别人的教程啥的。
比如这位B站的UP主
Aimls
|