编写程序的创新方式:触摸屏编程 (编写程序创建类Temperature)

编写程序的创新方式

编写程序创建类Temperature

使用触摸屏编程是一种创新且用户友好地创建交互式应用程序的方式。它允许用户使用触摸屏交互界面,而无需键盘或鼠标。

在本文中,我们将探索使用触摸屏编程创建类Temperature的步骤。该类将表示温度值并提供转换温度的功能。

步骤 1:创建触摸屏项目

  1. 打开您选择的触摸屏编程环境。
  2. 创建一个新项目。
  3. 将项目命名为“Temperature”。

步骤2:创建类Temperature

  1. 右键单击项目资源管理器中的“代码”文件夹。
  2. 选择“添加” > “类”。
  3. 将类命名为“Temperature”。

步骤 3:定义类成员

  1. 在类Temperature中,声明以下成员变量:
  2. private double celsius;private double fahrenheit;

步骤 4:定义类方法

  1. 在类Temperature中,声明以下方法:
  2. public Temperature(double celsius) {this.celsius = celsius;}public Temperature(double fahrenheit) {this.fahrenheit = fahrenheit;}public double getCelsius() {return celsius;}public double getFahrenheit() {return fahrenheit;}public void setCelsius(double celsius){this.celsius = celsius;updateFahrenheit();}public void setFahrenheit(double fahrenheit) {this.fahrenheit = fahrenheit;updateCelsius();}private void updateCelsius() {celsius = (fahrenheit - 32)  5 / 9;}private void updateFahrenheit() {fahrenheit = (celsius  9 / 5) + 32;}

步骤 5:测试类Temperature

  1. 在“代码”文件顶部添加以下代码行:
  2. public class Main {public static void main(String[] args) {Temperature temp1 = new Temperature(20);System.out.println("温度: " + temp1.getCelsius() + " 摄氏度");System.out.println("温度: " + temp1.getFahrenheit() + " 华氏度");temp1.setFahrenheit(68);System.out.println("温度: " + temp1.getCelsius() + " 摄氏度");System.out.println("温度: " + temp1.getFahrenheit() + " 华氏度");}}

结论

按照这些步骤,您已经成功创建了一个类Temperature,该类可以表示温度值并转换温度单位。这说明了使用触摸屏编程的创新和用户友好性,因为它允许您快速轻松地创建交互式应用程序。

触摸屏编程为各种行业和应用程序提供了无穷的可能性。无论是创建医疗保健应用程序、教育工具还是工业控制系统,触摸屏编程都是一个强大的工具,可以简化交互,并为用户提供直观且方便的体验。


触摸屏的程序是要根据你的PLC程序开编写的 单独的触摸屏没有很强的控制能力 一般是你的PLC程序有了以后然后在编写触摸屏的程序 触摸屏就是提供一个人机交互的界面。

本文原创来源:电气TV网,欢迎收藏本网址,收藏不迷路哦!

相关阅读

添加新评论