Guruh talabasi Ergashev Abduvohid 1-amaliy ish


Download 195.67 Kb.
bet2/2
Sana04.12.2020
Hajmi195.67 Kb.
#158560
1   2
Bog'liq
1-dttl

Dastur kodi

package sample;

import javafx.application.Application;


import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("1-amaliy ish");

primaryStage.setScene(new Scene(root));


primaryStage.show();
}

public static void main(String[] args) {


launch(args);
}
}

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;

import java.net.URL;


import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
import java.util.function.Function;

import static java.util.Arrays.sort;

public class Controller implements Initializable {
public AnchorPane anchor;
@FXML
private LineChart lineGraph;

@FXML
private AreaChart areaGraph;

@FXML
private Button lineGraphButton;

@FXML
private Button areaGraphButton;

@FXML
private Button xyButton;

@FXML
private Button xyButton2;

@FXML
private Button squaredButton;

@FXML
private Button squaredButton2;

@FXML
private Button cubedButton;

@FXML
private Button cubedButton2;

@FXML
private Button clearButton;

private MyGraph mathsGraph;


private MyGraph areaMathsGraph;

@FXML
private void handleLineGraphButtonAction(final ActionEvent event) {


lineGraph.setVisible(true);
areaGraph.setVisible(false);
}

@FXML
private void handleAreaGraphButtonAction(final ActionEvent event) {


areaGraph.setVisible(true);
lineGraph.setVisible(false);
}

@FXML
private void handleXYButtonAction(final ActionEvent event) {


plotLine(x -> x);
}

private void plotLine(Function function) {


if (lineGraph.isVisible()) {
mathsGraph.plotLine(function);
} else {
areaMathsGraph.plotLine(function);
}
}

@FXML
private void handleXYButton2Action(final ActionEvent event) {


plotLine(x -> x - 3);
}

@FXML
private void handleSquaredButtonAction(final ActionEvent event) {


plotLine(x -> Math.pow(x, 2));
}

@FXML
private void handleSquaredButton2Action(final ActionEvent event) {


plotLine(x -> 3*x*(x*x+3.5)+Math.log(x));
}

@FXML
private void handleCubedButtonAction(final ActionEvent event) {


plotLine(x -> -3*Math.pow(x, 2));
}

@FXML
private void handleCubedButton2Action(final ActionEvent event) {


plotLine(x -> Math.pow(x - 3, 3) - 1);
}

@FXML
private void handleClearButtonAction(final ActionEvent event) {


clear();
}

private void clear() {


if (lineGraph.isVisible()) {
mathsGraph.clear();
} else {
areaMathsGraph.clear();
}
}

@Override


public void initialize(URL location, ResourceBundle resources) {
mathsGraph = new MyGraph(lineGraph, 10);
areaMathsGraph = new MyGraph(areaGraph, 10);

}
}


package sample;

import javafx.scene.chart.XYChart;

import java.util.function.Function;

public class MyGraph {


private XYChart graph;
private double range;

public MyGraph(final XYChart graph, final double range) {


this.graph = graph;
this.range = range;
}

public void plotLine(final Function function) {


final XYChart.Series series = new XYChart.Series();
for (double x = -range; x <= range; x = x + 0.01) {
plotPoint(x, function.apply(x), series);
}
graph.getData().add(series);
}

private void plotPoint(final double x, final double y,


final XYChart.Series series) {
series.getData().add(new XYChart.Data(x, y));
}

public void clear() {


graph.getData().clear();
}
}


















Download 195.67 Kb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling