Java 객체로드를위한이 간단한 테스트를 만들었습니다. 하지만 유감스럽게도 SQL 쿼리를 사용하여 대규모 테스트를 수행 할 수는 없습니다.로드 중 메시지 테스트
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MainApp extends Application
{
GetDailySalesService service = new GetDailySalesService();
TestData obj;
@Override
public void start(Stage stage) throws Exception
{
obj = new TestData();
HBox hb = new HBox(100);
Tab tabA = new Tab("test");
Button button = new Button("Test");
///////////
Region veil = new Region();
veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
veil.setPrefSize(240, 160);
ProgressIndicator p = new ProgressIndicator();
p.setMaxSize(140, 140);
p.progressProperty().bind(service.progressProperty());
veil.visibleProperty().bind(service.runningProperty());
p.visibleProperty().bind(service.runningProperty());
//tableView.itemsProperty().bind(service.valueProperty());
//tableView.setMinSize(240, 140);
StackPane stack = new StackPane();
stack.getChildren().addAll(obj.someData(), veil, p);
service.start();
//////////////////
button.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
tabA.setContent(stack);
}
});
TabPane tb = new TabPane();
tb.setPrefSize(300, 300);
tb.getTabs().add(tabA);
hb.getChildren().addAll(button, tb);
hb.setPadding(new Insets(20, 20, 20, 20));
hb.setAlignment(Pos.CENTER);
Scene scene = new Scene(hb, 500, 300);
stage.setTitle("JavaFX and Maven");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
class TestData
{
public Label someData() throws InterruptedException
{
Label lb = new Label("It's working!!!!");
Thread.sleep(6000);
return lb;
}
}
class GetDailySalesService extends Service<ObservableList<Object>>
{
@Override
protected Task createTask()
{
return new GetDailySalesTask();
}
}
class GetDailySalesTask extends Task<ObservableList<Object>>
{
@Override
protected ObservableList<Object> call() throws Exception
{
return (ObservableList<Object>) obj.someData();
}
}
}
이 테스트를 구현하고 코드를 개선하는 적절한 방법이라고 말해 줄 수 있습니까?
왜 SQL 쿼리에서 사용할 수 없습니까? – ItachiUchiha
개체를로드하기 위해 UI 구성 요소를 클릭하면 응용 프로그램이 1-2 초 동안 정지합니다. –
someData() 내부에서 Label을 반환하기 전에 Javafx UI 스레드를 6 초 동안 잠자기 상태로 만듭니다. 검토하십시오. 데이터가 데이터베이스에서로드되는 동안 UI에 영향을 미치지 않도록 Task 클래스에 모든 데이터로드 이벤트를 넣으십시오. – ItachiUchiha