Java实现一个模型、两个视图和两个控制器的功能软件,即采用MVC模式或者说是观察者模式,本程序通过输入球体半径,显示球体形状,面积体积等 Sphere.java package Model; import java.util.Observable; public class Sphere extends Observable { private double radius;//球体半径 private double area;//球体面积 private double volume;//球体体积 public Sphere() { radius=100d; area=4*Math.PI*Math.pow(radius, 2); volume=4*Math.PI*Math.pow(radius, 3)/3; } public double getRadius() { return radius; } public double getArea() { return area; } public double getVolume() { return volume; } public void setRadius(double radius) { this.radius = radius; this.area = 4*Math.PI*Math.pow(radius, 2); this.volume=4*Math.PI*Math.pow(radius, 3)/3; this.setChanged(); this.notifyObservers(); } } textView.java package View; import java.util.Observer; import java.util.Observable; import java.text.NumberFormat; import javax.swing.*; import Controller.TextController; import Model.Sphere; import java.awt.*; import java.awt.event.*; public class TextView extends JPanel implements Observer { private JLabel radiusLab;//提示用户输入球体半径 private JTextField radiusTextField;//接受用户输入球体半径 //private JLabel radiusRang; private JLabel areaLab;//显示球体面积 private JTextField areaTextField;//显示输入球体半径对应的面积 private JLabel volumeLab;//显示球体体积 private JTextField volumeTextField;//显示输入球体半径对应的体积 public TextView() { try { Init(); } catch(Exception e) { e.printStackTrace(); } } private void Init() throws Exception { radiusLab=new JLabel("球体半径"); radiusLab.setForeground(new Color(0,165,168)); //radiusRang=new JLabel("[0-200]"); radiusTextField = new JTextField(12); radiusTextField.setForeground(new Color(223,100,158)); radiusTextField.setBackground(new Color(210,204,230)); areaLab=new JLabel("球体面积"); areaLab.setForeground(new Color(0,165,168)); areaTextField = new JTextField(12); areaTextField.setBackground(new Color(193,219,219)); areaTextField.setEditable(fal
2019-12-21 21:22:42 15KB MVC 球体 Java 观察者模式
1
请根据观察者模式,用Java语言设计并实现气象站程序。其中,部分代码已经写好,包括: • 观察者接口 • 主题接口 • 显示板接口 • 测试程序 请在此框架下,继续完成CurrentConditionsDisplay、ForecastDisplay、StatisticsDisplay等显示板类, 以及气象数据类(WeatherData), 使程序最终运行结果如下图所示(XXXX为本人学号): Currents conditions:80.0F degress and 65.0% humidity (by 1508060330) Avg/Max/Min:temperature = 80.0/80.0/80.0/ (by 1508060330) Forecast (by 1508060330):improving weather on the way Currents conditions:82.0F degress and 70.0% humidity (by 1508060330) Avg/Max/Min:temperature = 81.0/82.0/80.0/ (by 1508060330) Forecast (by 1508060330):watch out for cooler,rainy weather Currents conditions:78.0F degress and 90.0% humidity (by 1508060330) Avg/Max/Min:temperature = 80.0/82.0/78.0/ (by 1508060330) Forecast (by 1508060330):more of the same
2019-12-21 20:00:21 11KB 观察者模式 Java语言 气象站程序
1
观察者模式 c++ 工程角度实现
2019-12-21 19:40:25 9KB observer 观察者 模式
1
使用委托与事件机制实现 Unity消息分发机制,此文件是一个unitypackage类型,可直接运行,unity版本号是5.6.1
2019-12-21 19:32:30 6KB unity 观察者模式 消息分发机制
1