import java.io.IOException;
import com.hy.java.gui.javafx.iotdb.AppConstant;
import com.hy.java.gui.javafx.iotdb.properties.IotDBProperties;
import com.hy.java.gui.javafx.iotdb.utils.MsgUtils;
import com.hy.java.gui.javafx.iotdb.utils.NumberUtils;
import com.hy.java.gui.javafx.iotdb.utils.StringUtils;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.control.Alert.AlertType;
/**
-
@author hy
-
@createTime 2021-07-25 17:09:00
-
@description 主要的登录界面
*/
public class LoginController {
@FXML
TextField iotdbIp;
@FXML
TextField iotdbPort;
@FXML
TextField iotdbUsername;
@FXML
TextField iotdbPassword;
@FXML
Label loginMsg;
@FXML
public void login(Event event) {
// 检查登录参数是否填写完毕
boolean check = loginCheck();
if (check) {
IotDBProperties iotDBProperties = createIotDBProperties();
boolean checkCanConnectionTODB = checkCanConnectionTODB(iotDBProperties);
if (!checkCanConnectionTODB) {
MsgUtils.alert(AlertType.ERROR, “错误”, “打开连接失败!”);
loginMsg.setText(“打开连接失败!”);
loginMsg.setTextFill(Color.RED);
} else {
// 直接打开另外一个界面
try {
if (AppConstant.mainStage == null) {
openMainStage(new Stage());
}else {
openMainStage(AppConstant.mainStage);
}
} catch (IOException e) {
e.printStackTrace();
MsgUtils.alert(AlertType.ERROR, “错误”, e.getMessage());
}
}
}
}
private void openMainStage(Stage mainStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource(“…/resources/main.fxml”));
Scene scene = new Scene(root, 500, 450);
mainStage.setTitle(“open other window”);
mainStage.setScene(scene);
mainStage.setOnCloseRequest((event) -> {
AppConstant.loginStage.show();
mainStage.close();
});
// 保存上一次的状态
AppConstant.mainStage = mainStage;
AppConstant.loginStage.hide();
mainStage.show();
}
private boolean loginCheck() {
String ipString = iotdbIp.getText();
String portString = iotdbPort.getText();
String usernameString = iotdbUsername.getText();
String passwordString = iotdbPassword.getText();
if (StringUtils.isEmpty(ipString)) {
iotdbIp.setText(AppConstant.DEFAULT_IP);
}
if (StringUtils.isEmpty(portString)) {
iotdbPort.setText(String.valueOf(AppConstant.DEFAULT_PORT));
} else {
boolean intNum = NumberUtils.isIntNum(portString);
if (!intNum) {
MsgUtils.alert(AlertType.ERROR, “错误”, “当前输入的端口=” + portString + “不是整数”);
return false;
}
}
if (StringUtils.isEmpty(usernameString)) {
iotdbUsername.setText(AppConstant.DEFAULT_USERNAME);
}
if (StringUtils.isEmpty(passwordString)) {
iotdbPassword.setText(AppConstant.DEFAULT_PASSWORD);
}
return true;
}
private IotDBProperties createIotDBProperties() {
String ipString = iotdbIp.getText();
String portString = iotdbPort.getText();
String usernameString = iotdbUsername.getText();
String passwordString = iotdbPassword.getText();
IotDBProperties iotDBProperties = new IotDBProperties();
iotDBProperties.setIp(ipString);
iotDBProperties.setPort(portString);
iotDBProperties.setUsername(usernameString);
iotDBProperties.setPassword(passwordString);
return iotDBProperties;
}
private boolean checkCanConnectionTODB(IotDBProperties iotDBProperties) {
return true;
}
}
MainController
package com.hy.java.gui.javafx.iotdb.controller;
import java.net.URL;
import java.util.ResourceBundle;
import com.hy.java.gui.javafx.iotdb.pojo.MeasurementPointData;
import com.sun.javafx.scene.control.skin.LabeledText;
import javafx.collections.ObservableList;
import javafx.event.EventTarget;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
/**
-
@author hy
-
@createTime 2021-07-25 17:08:29
-
@description 主要查看iotdb数据的地方
*/
public class MainController implements Initializable {
@FXML
ListView storageGroupList; // 左边显示存储组
@FXML
TableView mpInfo; // 右边存放mpInfo的信息
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
// SimpleListProperty storageGroupDatas=new
// SimpleListProperty();
ObservableList items = storageGroupList.getItems();
items.add(“root.test.machine”);
items.add(“root.test.machine1”);
// 开始获取当前的table中的数据,必须通过点击事件获取,例如点击左边的测点
storageGroupList.setOnMouseClicked((event) -> {
// System.out.println(“listView==>event=” + event);
EventTarget target = event.getTarget();
System.out.println(target);
// 这里不能执行强制类型转换操作,由于字节码文件不支持(54,而当前为52)
if (target == null) {
return;
}
if (target instanceof LabeledText) {
LabeledText clickLabeledText = (LabeledText) target;
String text = clickLabeledText.getText();
System.out.println(“获取当前点击的目标存储组为:” + text);
// 下面这里可能从iotdb中获取实际的数据,并加载数据到TableView
setMpDataFromDB(text);
}
});
ObservableList<TableColumn<MeasurementPointData, ?>> columns = mpInfo.getColumns();
columns.clear();
// 开始将列的值与当前的javabean的属性进行绑定
TableColumn<MeasurementPointData, Object> columne1 = new TableColumn<MeasurementPointData, Object>(“测点名称”);
TableColumn<MeasurementPointData, Object> columne2 = new TableColumn<MeasurementPointData, Object>(“时间”);
TableColumn<MeasurementPointData, Object> columne3 = new TableColumn<MeasurementPointData, Object>(“值”);
columne1.setCellValueFactory(new PropertyValueFactory<MeasurementPointData, Object>(“mpName”));
columne2.setCellValueFactory(new PropertyValueFactory<MeasurementPointData, Object>(“timestamp”));
columne3.setCellValueFactory(new PropertyValueFactory<MeasurementPointData, Object>(“value”));
columns.add(columne1);
columns.add(columne2);
columns.add(columne3);
}
private void setMpDataFromDB(String storageGroupName) {
// 这里应该从iotdb数据库中加载数据
ObservableList items = mpInfo.getItems();
items.clear();
MeasurementPointData mpData = new MeasurementPointData();
mpData.setMpName(“root.test.machine.value”);
mpData.setTimestamp(“1”);
mpData.setValue(“999”);
items.add(mpData);
System.out.println(items);
}
}
2.程序常量类和pojo类和properties类
package com.hy.java.gui.javafx.iotdb;
import javafx.stage.Stage;
/**
-
@author hy
-
@createTime 2021-07-25 13:49:05
-
@description 定义系统运行中的常量部分
*/
public abstract class AppConstant {
public static final String DEFAULT_IP = “localhost”;
public static final int DEFAULT_PORT = 6667;
public static final String DEFAULT_USERNAME = “root”;
public static final String DEFAULT_PASSWORD = “root”;
//public static final String LOGIN_RESOURCE_LOCATION=“”;
//public static final String MAIN_RESOURCE_LOCATION=“…/main”;
public static Stage loginStage;
public static Stage mainStage;
}
package com.hy.java.gui.javafx.iotdb.pojo;
import javafx.beans.property.SimpleStringProperty;
public class MeasurementPointData {
private String mpName;
private String timestamp;
private String value;
// 省略getset之类的方法
}
package com.hy.java.gui.javafx.iotdb.properties;
public class IotDBProperties {
private String ip;
private String port;
private String username;
private String password;
// 省略getset之类的方法
}
3.各种工具类
package com.hy.java.gui.javafx.iotdb.utils;
import java.util.Optional;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Alert.AlertType;
public abstract class MsgUtils {
public static void alert(AlertType alertType, String title, String msg) {
Alert alert = new Alert(alertType, msg, ButtonType.YES, ButtonType.NO);
alert.setTitle(title);
alert.setHeaderText(“”);
Optional showAndWait = alert.showAndWait();
if (showAndWait.get() == ButtonType.YES) {
alert.close();
}
}
}
package com.hy.java.gui.javafx.iotdb.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class NumberUtils {
private static final String INT_STRING_REGEX = “^\d+$”;
private static final Pattern INT_STRING_PATTERN = Pattern.compile(INT_STRING_REGEX);
public static boolean isIntNum(String text) {
Matcher matcher = INT_STRING_PATTERN.matcher(text);
return matcher.matches();
}
}
package com.hy.java.gui.javafx.iotdb.utils;
public abstract class StringUtils {
public static boolean isEmpty(String text) {
if (text == null || “”.equals(text.trim())) {
return true;
}
return false;
}
}
实际入口类
package com.hy.java.gui.javafx.iotdb;
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class IotdbJavaFxApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource(“resources/login.fxml”));
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
![img](https://img-blog.csdnimg.cn/img_convert/5b05d48fd8f014a9b36b279b45e72b53.jpeg)
最后
俗话说,好学者临池学书,不过网络时代,对于大多数的我们来说,我倒是觉得学习意识的觉醒很重要,这是开始学习的转折点,比如看到对自己方向发展有用的信息,先收藏一波是一波,比如如果你觉得我这篇文章ok,先点赞收藏一波。这样,等真的沉下心来学习,不至于被找资料分散了心神。慢慢来,先从点赞收藏做起,加油吧!
另外,给大家安排了一波学习面试资料:
以上就是本文的全部内容,希望对大家的面试有所帮助,祝大家早日升职加薪迎娶白富美走上人生巅峰!
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
Java开发知识点,真正体系化!**
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
![img](https://img-blog.csdnimg.cn/img_convert/5b05d48fd8f014a9b36b279b45e72b53.jpeg)
最后
俗话说,好学者临池学书,不过网络时代,对于大多数的我们来说,我倒是觉得学习意识的觉醒很重要,这是开始学习的转折点,比如看到对自己方向发展有用的信息,先收藏一波是一波,比如如果你觉得我这篇文章ok,先点赞收藏一波。这样,等真的沉下心来学习,不至于被找资料分散了心神。慢慢来,先从点赞收藏做起,加油吧!
另外,给大家安排了一波学习面试资料:
[外链图片转存中…(img-pLvJN1rN-1713118486112)]
[外链图片转存中…(img-y2XxlQth-1713118486112)]
以上就是本文的全部内容,希望对大家的面试有所帮助,祝大家早日升职加薪迎娶白富美走上人生巅峰!
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!