图形绘制系统(一)

这次增加用户登录,用户管理,修改信息,快捷方式,
先说一下实体类的封装,相比于上一次,这次应用MVC架构。
菱形

package 软件工程项目1;

public class LingxingGraph {
   
	private int num;

	public int getNum() {
   
		return num;
	}

	public void setNum(int num) {
   
		this.num = num;
	}
	void LingxingGraph(Lingxing l) {
                            //图形绘制
		int i=0,j=0;
		for ( i = 0; i <= num; i++) {
   
			for (j = 0; j < num - i; j++) {
   
				l.area.append(" ");
			}
			for (int k = 1; k <= 2 * i - 1; k++) {
   
				if (k == 1 || k == 2 * i - 1) {
   
					l.area.append("#");
			} 
				else {
   
					l.area.append(" ");
				}
			}
				l.area.append("\n");
			}

			for ( i = num - 1; i > 0; i--) {
   
				for ( j = 0; j < num - i; j++) {
   
					l.area.append(" ");
			}
			for (int k = 1; k <= 2 * i - 1; k++) {
   
				if (k == 1 || k == 2 * i - 1) {
   
					l.area.append("#");
			} 
				else {
   
					l.area.append(" ");
				}
			}
			l.area.append("\n");
		}
	}
}

金字塔:

package 软件工程项目1;

public class PyramidGraph {
   
	private int level;
	private int size;
	public int getLevel() {
   
		return level;
	}
	public void setLevel(int level) {
   
		this.level = level;
	}
	public int getSize() {
   
		return size;
	}
	public void setSize(int size) {
   
		this.size = size;
	}
	void PyramidGraph(Pyramid p) {
                              //绘制金字塔
		int i=0,j=0,k=0;
		k=level*size;
		for(i=1;i<=k;i++){
   
			for(j=1;j<=i+k;j++){
   
				if((j>=k-i)&&(i+j-k-1)%(2*size)==0){
   
					p.area.append("/");
				}
				else if((j>k-i)&&((k+i-j)%(2*size))==0){
   
					p.area.append("\\");
				}
				else if((j>k-i)&&(j<k+i)&&(i%size==0)){
   
					p.area.append("_");
				}
				else p.area.append(" ");
			}
			p.area.append("\n");
		}
	}
}

长方形:

package 软件工程项目1;

public class RectangleGraph {
   
	private int longg;
	private int thickness;
	private int wide;
	public int getLongg() {
   
		return longg;
	}
	public void setLongg(int longg) {
   
		this.longg = longg;
	}
	public int getThickness() {
   
		return thickness;
	}
	public void setThickness(int thickness) {
   
		this.thickness = thickness;
	}
	public int getWide() {
   
		return wide;
	}
	public void setWide(int wide) {
   
		this.wide = wide;
	}
	void RectangleGraph(Rectangle r) {
                     //绘制长方形
		int i=0,j=0;
			for(i=1;i<=longg;i++)
			{
   
				if(i<=thickness)
				{
   
					for(j=1;j<=wide;j++) 
						r.area.append("#");
				}
				else if(i>longg-thickness){
   
					for(j=1;j<=wide;j++)
						r.area.append("#");
				}
				else{
   
					for(j=1;j<=wide;j++)
					{
   
						if(j<thickness+1)
							r.area.append("#");
						else if(j>wide-thickness)
							r.area.append("#");
						else
							r.area.append(" ");          //空格用A代替
					}
				}
				r.area.append("\n");	
			}
		
	}
    
}

正方形:

package 软件工程项目1;

public class SquareGraph {
   
	private int  height;
	private int thickness;
	public int getHeight() {
   
		return height;
	}
	public void setHeight(int height) {
   
		this.height = height;
	}
	public int getThickness() {
   
		return thickness;
	}
	public void setThickness(int thickness) {
   
		this.thickness = thickness;
	}
	void SquareGraph(Square s) {
                                //绘制正方形
			int i=0,j=0;
			for(i=1;i<=height;i++)
			{
   
				if(i<=thickness)
				{
   
					for(j=1;j<=height;j++) 
						s.area.append("#");
				}
				else if(i>height-thickness){
   
					for(j=1;j<=height;j++)
						s.area.append("#");
				}
				else{
   
					for(j=1;j<=height;j++)
					{
   
						if(j<thickness+1)
							s.area.append("#");
						else if(j>height-thickness)
							s.area.append("#");
						else											
							s.area.append(" ");
					}				
				}
				s.area.append("\n");	
			}
		
		}

}

三角形:

package 软件工程项目1;

public class TriangleGraph {
   
	private int height;
	private int thickness;
	
	public int getHeight() {
   
		return height;
	}
	public void setHeight(int height) {
   
		this.height = height;
	}
	public int getThickness() {
   
		return thickness;
	}
	public void setThickness(int thickness) {
   
		this.thickness = thickness;
	}
	 void TriangleGraph(Triangle t) {
   
		int i=0,j=0;
		for(i=height;i>=1;i--)
		{
   
			if(i<=thickness)
			{
   
				for(j=1;j<=thickness;j++) 
					t.area.append("#");
			}
			else if(i>height-thickness){
   
				for(j=1;j<=i;j++)
					t.area.append("#");
			}
			else{
   
				for(j=1;j<=i;j++)
				{
   
					if(j<thickness+1)
						t.area.append("#");
					else if(j>i-thickness)
						t.area.append("#");
					else
						t.area.append(" ");
				}
			}
			t.area.append("\n");	
		}		
	
	}

 }
	

管理员:

package 软件工程项目1;

public class User {
   
	private String id;
	private String password;
	public String getId() {
   
		return id;
	}
	public void setId(String id) {
   
		this.id = id;
	}
	public String getPassword() {
   
		return password;
	}
	public void setPassword(String password) {
   
		this.password = password;
	}
}

用户:

package 软件工程项目1;

public class User1 {
   
	private String id;
	private String password;
	public String getId() {
   
		return id;
	}
	public void setId(String id) {
   
		this.id = id;
	}
	public String getPassword() {
   
		return password;
	}
	public void setPassword(String password) {
   
		this.password = password;
	}
}

数据库操作:

package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,我们需要定义一些图形绘制的基本操作,如画线、画矩形、画圆等。然后,我们可以使用命令模式将这些操作封装成对象,并将它们放入一个命令队列中。每个对象都有一个execute()方法,用于执行相应的操作。 下面是一个简单的图形绘制系统的实现: 1. 定义一个图形绘制接口: ``` public interface Shape { void draw(); } ``` 2. 实现具体的图形绘制类: ``` public class Line implements Shape { public void draw() { System.out.println("Draw a line."); } } public class Circle implements Shape { public void draw() { System.out.println("Draw a circle."); } } public class Rectangle implements Shape { public void draw() { System.out.println("Draw a rectangle."); } } ``` 3. 实现一个命令接口: ``` public interface Command { void execute(); } ``` 4. 实现具体的命令类: ``` public class DrawCommand implements Command { private Shape shape; public DrawCommand(Shape shape) { this.shape = shape; } public void execute() { shape.draw(); } } ``` 5. 实现一个命令队列: ``` import java.util.ArrayList; import java.util.List; public class CommandQueue { private List<Command> commands = new ArrayList<>(); public void addCommand(Command command) { commands.add(command); } public void executeCommands() { for (Command command : commands) { command.execute(); } } } ``` 6. 测试代码: ``` public class Test { public static void main(String[] args) { Shape line = new Line(); Shape circle = new Circle(); Shape rectangle = new Rectangle(); CommandQueue commandQueue = new CommandQueue(); commandQueue.addCommand(new DrawCommand(line)); commandQueue.addCommand(new DrawCommand(circle)); commandQueue.addCommand(new DrawCommand(rectangle)); commandQueue.executeCommands(); } } ``` 输出结果: ``` Draw a line. Draw a circle. Draw a rectangle. ``` 这个图形绘制系统可以轻松地扩展,添加更多的图形绘制操作,只需要实现相应的图形绘制类和命令类即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值