用于TableView行的JavaFx淡入淡出

如何解决用于TableView行的JavaFx淡入淡出

这是我关于stackoverflow的第一个问题,请客气:)

我正在制作一个货币汇率桌面应用程序。每隔10秒,我就会使用API​​刷新表格视图。

我想对每个tableview行进行淡入淡出。当平均值大于前一个值时,该行将变为绿色。如果更少,它将为红色。示例在这里;

https://examples.ext.net/#/SignalR/Basic/StockTicker/

我看到了这一点,但无法解决如何实施我的项目; Fade Transition via custom cell factory in javafx

代码;

Currency.java

package model;

import javafx.beans.property.SimpleStringProperty;

public class Currency {
    private SimpleStringProperty dovizKuru;
    private SimpleStringProperty alis;
    private SimpleStringProperty satis;
    private SimpleStringProperty ortalama;
    private SimpleStringProperty gunlukDegisim;

public Currency(SimpleStringProperty dovizKuru,SimpleStringProperty alis,SimpleStringProperty satis,SimpleStringProperty ortalama,SimpleStringProperty gunlukDegisim) {
    super();
    this.dovizKuru = dovizKuru;
    this.alis = alis;
    this.satis = satis;
    this.ortalama = ortalama;
    this.gunlukDegisim = gunlukDegisim;
}


public String getDovizKuru() {
    return this.dovizKuru.get();
}


public void setDovizKuru(SimpleStringProperty dovizKuru) {
    this.dovizKuru = dovizKuru;
}


public String getAlis() {
    return this.alis.get();
}


public void setAlis(SimpleStringProperty alis) {
    this.alis = alis;
}


public String getSatis() {
    return this.satis.get();
}


public void setSatis(SimpleStringProperty satis) {
    this.satis = satis;
}


public String getOrtalama() {
    return this.ortalama.get();
}


public void setOrtalama(SimpleStringProperty ortalama) {
    this.ortalama = ortalama;
}


public String getGunlukDegisim() {
    return this.gunlukDegisim.get();
}


public void setGunlukDegisim(SimpleStringProperty gunlukDegisim) {
    this.gunlukDegisim = gunlukDegisim;
}

}

Api服务

package services;

import java.net.HttpURLConnection;
import java.net.URL;

import org.json.JSONArray;
import org.json.JSONObject;

import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import model.Currency;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CurrencyRateServices extends Service<ObservableList<Currency>> {
    public ObservableList<Currency> apiResponse() throws IOException{

    
    
    StringBuilder urlBuilder = new StringBuilder("https://api.yapikredi.com.tr/api/investmentrates/v1/currencyRates");
    URL url = new URL(urlBuilder.toString());
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    //Bearer 9e6f33ac-ddfc-4a5d-b55d-155a0f3f0e69
    conn.setRequestProperty("Authorization","TOKEN");
    System.out.println("Response code: " + conn.getResponseCode());
    BufferedReader rd;
    if(conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) {
        rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    } else {
        rd = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
    }
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = rd.readLine()) != null) {
        sb.append(line);
    }
    rd.close();
    conn.disconnect();
    System.out.println(sb);
    
    ObservableList<Currency> currList= FXCollections.observableArrayList();
    JSONObject obj = new JSONObject(sb.toString());
    JSONObject obj2=obj.getJSONObject("response");
    JSONArray jsonArray=obj2.getJSONArray("exchangeRateList");
    for (int i = 0; i < jsonArray.length(); i++) {
        if (jsonArray.getJSONObject(i).getString("minorCurrency").equals("TL")) {
            Currency currency = new Currency(
                    new SimpleStringProperty(jsonArray.getJSONObject(i).getString("majorCurrency") + "/"+ jsonArray.getJSONObject(i).getString("minorCurrency")),new SimpleStringProperty(jsonArray.getJSONObject(i).getString("buyRate")),new SimpleStringProperty(jsonArray.getJSONObject(i).getString("sellRate")),new SimpleStringProperty(jsonArray.getJSONObject(i).getString("averageRate")),new SimpleStringProperty(jsonArray.getJSONObject(i).getString("changeRatioDaily"))

            );
            currList.add(currency);
        }
        
    }
    
    return currList;
}

@Override
protected Task<ObservableList<Currency>> createTask() {
    // TODO Auto-generated method stub
    return new Task<ObservableList<Currency>>() {
        protected ObservableList<Currency> call() throws Exception{
            return apiResponse();
        }
    };
}

}

MyController

package controller;

import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
import java.util.ResourceBundle;
import application.DovizManager;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.util.Duration;
import model.Currency;
import services.CurrencyRateServices;
import view.ViewFactory;

public class DovizMainController extends BaseController implements Initializable{
    @FXML
    private TableView<Currency> dovizTableView;

@FXML
private TableColumn<Currency,String> col_DovizKuru;

@FXML
private TableColumn<Currency,String> col_Alis;

@FXML
private TableColumn<Currency,String> col_Satis;

@FXML
private TableColumn<Currency,String> col_Ortalama;

@FXML
private TableColumn<Currency,String> col_GunlukDegisim;

private ObservableList<Currency> crList;

public DovizMainController(DovizManager dovizManager,ViewFactory viewFactory,String fxmlName) {
    super(dovizManager,viewFactory,fxmlName);
}

@Override
public void initialize(URL arg0,ResourceBundle arg1) {
    setUpFirstTableView();
    setUpTableView();

    // TODO Auto-generated method stub
    
}
public void setUpFirstTableView() {
    //ObservableList<Currency> crList = null;

    CurrencyRateServices crService=new CurrencyRateServices();
    try {
        crList=crService.apiResponse();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    dovizTableView.setItems(crList);
    col_DovizKuru.setCellValueFactory(new PropertyValueFactory<Currency,String>("dovizKuru"));
    col_Alis.setCellValueFactory(new PropertyValueFactory<Currency,String>("alis"));
    col_Satis.setCellValueFactory(new PropertyValueFactory<Currency,String>("satis"));
    col_Ortalama.setCellValueFactory(new PropertyValueFactory<Currency,String>("ortalama"));
    col_GunlukDegisim.setCellValueFactory(new PropertyValueFactory<Currency,String>("gunlukDegisim"));
    
    
}

public void setUpTableView() {
    Timeline timeline = new Timeline(new KeyFrame(Duration.millis(10000),new EventHandler() {
        

        @Override
        public void handle(Event arg0) {
            // TODO Auto-generated method stub


            CurrencyRateServices crService=new CurrencyRateServices();
            crService.start();
            crService.setOnSucceeded(e->{
                ObservableList<Currency> crListNew=crService.getValue();
                for (int i = 0; i < crList.size(); i++) {
                    for (int j = 0; j < crListNew.size(); j++) {
                        if(crList.get(i).getDovizKuru().equals(crListNew.get(j).getDovizKuru())) {
                            System.out.println("başlıklar aynı");
                            
                            if(crList.get(i).getOrtalama()!=crListNew.get(j).getOrtalama()) {
                                System.out.println("ortalamalar aynı");
                                if(Double.parseDouble(crList.get(i).getOrtalama())>Double.parseDouble(crListNew.get(j).getOrtalama())) {
                                    
                                    crList.get(i).setAlis(new SimpleStringProperty(crListNew.get(j).getAlis()));
                                    crList.get(i).setGunlukDegisim(new SimpleStringProperty(crListNew.get(j).getGunlukDegisim()));
                                    crList.get(i).setOrtalama(new SimpleStringProperty(crListNew.get(j).getOrtalama()));
                                    crList.get(i).setSatis(new SimpleStringProperty(crListNew.get(j).getSatis()));
                                    
                                    dovizTableView.getItems().set(i,crList.get(i));
                                } else {
                                    crList.get(i).setAlis(new SimpleStringProperty(crListNew.get(j).getAlis()));
                                    crList.get(i).setGunlukDegisim(new SimpleStringProperty(crListNew.get(j).getGunlukDegisim()));
                                    crList.get(i).setOrtalama(new SimpleStringProperty(crListNew.get(j).getOrtalama()));
                                    crList.get(i).setSatis(new SimpleStringProperty(crListNew.get(j).getSatis()));
                                    
                                    dovizTableView.getItems().set(i,crList.get(i));
                                    
                                }
                                
                            }
                            
                        }else {continue;}
                    }
                    
                    
                }
                
            });



        }
        
    }));
    timeline.setCycleCount(Animation.INDEFINITE);
    timeline.play();

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-