idea自动生成UML图的实现图文教程
idea的强大之处在于此,它包含了很多小插件,我们不需要再次下载相关插件,只需要在idea中小小的设置一下就可以了,真的yyds。
下面是设置方法,我用的是idea2020版本
打开设置File -> Settings->Diagrams,如何如下图:
选择我们UML图需要的部分,我选择的是成员变量、构造器和方法。
下面以一个代码为例,展示一下UML图
import java.util.Scanner; import java.util.Date; public class GeometricObject { public String color; public boolean filled; Date date = new Date(); public GeometricObject(){ //无参构造 String color ="white"; boolean filled = true; } public GeometricObject(String color,boolean filled){ this.color = color; this.filled = filled; } public String getColor(){ return color; } public void setColor(String color){ this.color = color; } public boolean isFilled(){ return filled; } public void setFilled(boolean filled){ this.filled = filled; } public String toString(){ return "创建于"+date.toString()+"\n颜色是"+color+"\n填充方式是"+filled; } } public class Triangle extends GeometricObject{ private double side1 ,side2,side3; public Triangle(){ double side1 = 1.0; double side2 = 1.0; double side3 = 1.0; } public Triangle(double side1,double side2,double side3,String color){ this.side1 = side1; this.side2 = side2; this.side3 = side3; this.color =color; } public Triangle(double side1,double side2,double side3,String color,boolean filled){ this.side1 = side1; this.side2 = side2; this.side3 = side3; setColor(color); setFilled(filled); } public double getArea(){ double s =(side1+side2+side3) /2; return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3)); } public double getPerimeter(){ return side1+side2+side3; } public String toString(){ return "三角形三边是:side1="+side1+"side2="+side2+"side3"+side3; } } import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入三角形的三个边长"); double side1 = scanner.nextDouble(); double side2 = scanner.nextDouble(); double side3 = scanner.nextDouble(); System.out.println("请输入颜色"); String color = scanner.next(); System.out.println("请输入是否填充true/false"); boolean filled = scanner.hasNext(); Triangle t = new Triangle(side1,side2,side3,color,filled); System.out.println("三角形的面积是"+t.getArea()); System.out.println("三角形的周长是"+t.getPerimeter()); System.out.println("三角形的颜色是"+t.getColor()); System.out.println("三角形是否填充"+t.isFilled()); } }
按照以下操作就可以生成UML图,或者快捷键Ctrl+Alt+Shift+U
以下是生成结果:
到此这篇关于idea自动生成UML图的实现图文教程的文章就介绍到这了,更多相关idea自动生成UML图内容请搜索代码部落以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码部落!
本文章来源于网络,作者是:mmmenxj,由代码部落进行采编,如涉及侵权请联系删除!转载请注明出处:https://daimabuluo.cc/qitazonghe/2082.html