Как получить доступ к массиву - Java
Формулировка задачи:
Друзья, нужна помощь.
Мне нужно получить доступ или как-то скопировать информацию из массива DataArray, доступ нужен здесь: onCalculateData. Спасибо за помощь)
Листинг программы
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.scene.control.Button;
- import javafx.scene.control.TextField;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import sample.objects.Parser;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class Controller {
- private int ClusterNumber;
- private int ParameterNumber;
- @FXML
- private TextField clusterNTF;
- @FXML
- private TextField parameterNTF;
- @FXML
- private Button idGetData;
- public void onEnteredData(ActionEvent event) {
- if (!clusterNTF.getText().isEmpty()){
- ClusterNumber = Integer.parseInt(clusterNTF.getText());
- }
- if (!parameterNTF.getText().isEmpty()){
- ParameterNumber = Integer.parseInt(parameterNTF.getText());
- }
- }
- public void onNewForm(ActionEvent actionEvent) throws IOException {
- System.out.println(ClusterNumber + ParameterNumber);
- Workbook wb_out = new HSSFWorkbook();
- Sheet sheet = wb_out.createSheet("Данные");
- Row row1 = sheet.createRow(1);
- Cell cell_industry = row1.createCell(0);
- cell_industry.setCellValue("Промышленность");
- Row row0 = sheet.createRow(0);
- Cell cell_parameter = row0.createCell(0);
- cell_parameter.setCellValue("Параметр");
- for(int cell_i = 1; cell_i < ParameterNumber + 1; cell_i++ ) {
- Cell head = row0.createCell(cell_i);
- head.setCellValue(cell_i + "-параметр");
- }
- for(int row_i = 2; row_i < ClusterNumber + 2; row_i++){
- Row row = sheet.createRow(row_i);
- Cell cell_out = row.createCell(0);
- cell_out.setCellValue(row_i - 1 + " кластер");
- }
- FileOutputStream fos = new FileOutputStream("Формула.xls");
- wb_out.write(fos);
- fos.close();
- wb_out.close();
- }
- public void onGetData(ActionEvent actionEvent) throws IOException {
- System.out.println("Привет");
- FileInputStream fileIn = new FileInputStream("Формула.xls");
- Workbook wb = new HSSFWorkbook(fileIn);
- double[][] DataArray = new double[ParameterNumber][ClusterNumber];
- Sheet sheet = wb.getSheetAt(0);
- for (int column_i = 1; column_i < ParameterNumber + 1; column_i++){
- for (int row_i = 2; row_i < ClusterNumber + 2; row_i++) {
- Row row = sheet.getRow(row_i);
- Cell cell_in = row.getCell(column_i);
- DataArray[column_i - 1][row_i - 2] = Double.parseDouble(Parser.getCellText(cell_in));
- }
- }
- fileIn.close();
- }
- public void onClusterNTF(ActionEvent event) {
- }
- public void onParameterNTF(ActionEvent event) {
- }
- public void onCalculateData(ActionEvent event) {
- }
- }
Решение задачи: «Как получить доступ к массиву»
textual
Листинг программы
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.scene.control.Button;
- import javafx.scene.control.TextField;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import sample.objects.Parser;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class Controller {
- private int ClusterNumber;
- private int ParameterNumber;
- @FXML
- private TextField clusterNTF;
- @FXML
- private TextField parameterNTF;
- @FXML
- private Button idGetData;
- private double[][] DataArray;
- public void onEnteredData(ActionEvent event) {
- if (!clusterNTF.getText().isEmpty()){
- ClusterNumber = Integer.parseInt(clusterNTF.getText());
- }
- if (!parameterNTF.getText().isEmpty()){
- ParameterNumber = Integer.parseInt(parameterNTF.getText());
- }
- }
- public void onNewForm(ActionEvent actionEvent) throws IOException {
- System.out.println(ClusterNumber + ParameterNumber);
- Workbook wb_out = new HSSFWorkbook();
- Sheet sheet = wb_out.createSheet("Данные");
- Row row1 = sheet.createRow(1);
- Cell cell_industry = row1.createCell(0);
- cell_industry.setCellValue("Промышленность");
- Row row0 = sheet.createRow(0);
- Cell cell_parameter = row0.createCell(0);
- cell_parameter.setCellValue("Параметр");
- for(int cell_i = 1; cell_i < ParameterNumber + 1; cell_i++ ) {
- Cell head = row0.createCell(cell_i);
- head.setCellValue(cell_i + "-параметр");
- }
- for(int row_i = 2; row_i < ClusterNumber + 2; row_i++){
- Row row = sheet.createRow(row_i);
- Cell cell_out = row.createCell(0);
- cell_out.setCellValue(row_i - 1 + " кластер");
- }
- FileOutputStream fos = new FileOutputStream("Формула.xls");
- wb_out.write(fos);
- fos.close();
- wb_out.close();
- }
- public void onGetData(ActionEvent actionEvent) throws IOException {
- System.out.println("Привет");
- FileInputStream fileIn = new FileInputStream("Формула.xls");
- Workbook wb = new HSSFWorkbook(fileIn);
- DataArray = new double[ParameterNumber][ClusterNumber];
- Sheet sheet = wb.getSheetAt(0);
- for (int column_i = 1; column_i < ParameterNumber + 1; column_i++){
- for (int row_i = 2; row_i < ClusterNumber + 2; row_i++) {
- Row row = sheet.getRow(row_i);
- Cell cell_in = row.getCell(column_i);
- DataArray[column_i - 1][row_i - 2] = Double.parseDouble(Parser.getCellText(cell_in));
- }
- }
- fileIn.close();
- }
- public void onClusterNTF(ActionEvent event) {
- }
- public void onParameterNTF(ActionEvent event) {
- }
- public void onCalculateData(ActionEvent event) {
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д