Java实现MVC球体

上传者: u011436273 | 上传时间: 2019-12-21 21:22:42 | 文件大小: 15KB | 文件类型: rar
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

文件下载

资源详情

[{"title":"( 23 个子文件 15KB ) Java实现MVC球体","children":[{"title":"MVCSphere","children":[{"title":".project <span style='color:#111;'> 385B </span>","children":null,"spread":false},{"title":"src","children":[{"title":"SphereWindow.java <span style='color:#111;'> 1.20KB </span>","children":null,"spread":false},{"title":"Controller","children":[{"title":"TextController.java <span style='color:#111;'> 1.17KB </span>","children":null,"spread":false},{"title":"GraphicController.java <span style='color:#111;'> 2.60KB </span>","children":null,"spread":false},{"title":"package-info.java <span style='color:#111;'> 74B </span>","children":null,"spread":false}],"spread":true},{"title":"View","children":[{"title":"package-info.java <span style='color:#111;'> 68B </span>","children":null,"spread":false},{"title":"GraphicsView.java <span style='color:#111;'> 1.12KB </span>","children":null,"spread":false},{"title":"TextView.java <span style='color:#111;'> 3.19KB </span>","children":null,"spread":false}],"spread":true},{"title":"Model","children":[{"title":"package-info.java <span style='color:#111;'> 69B </span>","children":null,"spread":false},{"title":"Sphere.java <span style='color:#111;'> 697B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":".settings","children":[{"title":"org.eclipse.jdt.core.prefs <span style='color:#111;'> 598B </span>","children":null,"spread":false}],"spread":true},{"title":".classpath <span style='color:#111;'> 301B </span>","children":null,"spread":false},{"title":"bin","children":[{"title":"SphereWindow.class <span style='color:#111;'> 1.76KB </span>","children":null,"spread":false},{"title":"Controller","children":[{"title":"GraphicController$2.class <span style='color:#111;'> 1.63KB </span>","children":null,"spread":false},{"title":"GraphicController.class <span style='color:#111;'> 1.61KB </span>","children":null,"spread":false},{"title":"package-info.class <span style='color:#111;'> 116B </span>","children":null,"spread":false},{"title":"GraphicController$1.class <span style='color:#111;'> 1.37KB </span>","children":null,"spread":false},{"title":"TextController.class <span style='color:#111;'> 1.69KB </span>","children":null,"spread":false}],"spread":true},{"title":"View","children":[{"title":"TextView.class <span style='color:#111;'> 2.63KB </span>","children":null,"spread":false},{"title":"GraphicsView.class <span style='color:#111;'> 1.70KB </span>","children":null,"spread":false},{"title":"package-info.class <span style='color:#111;'> 110B </span>","children":null,"spread":false}],"spread":true},{"title":"Model","children":[{"title":"Sphere.class <span style='color:#111;'> 912B </span>","children":null,"spread":false},{"title":"package-info.class <span style='color:#111;'> 111B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明