首页 文章 精选 留言 我的

精选列表

搜索[structure],共783篇文章
优秀的个人博客,低调大师

Data Structure_JavaSwing

Java Swing的基础 首先需要注意的就是JFrame这个类,如果在main类整直接new一个出来是没有任何的变化,需要设置一个setvisible为true来显示出来。 public class AlgorFrame extends JFrame { private int canvasWith; private int canvasHeight; public AlgorFrame(String title, int cancasWidth, int canvasHeight) { super(title); this.canvasHeight = canvasHeight; this.canvasWith = cancasWidth; this.setSize(cancasWidth, canvasHeight); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } 这是一个标准的模板,设置窗口大小不可重新改变,关闭窗口时整个程序同时关闭。 JFrame是最上层的一个窗口,如果要绘制的话是不可以在窗口本身绘制的。MenuBar就是最大化最小化关闭等等的操作。Content Pane其实是一个容器,可以装载其他的组件,最常用的就是面板,Jpanel就是一个面板,后面的绘制都会画在Jpanel上。也就是说想要画上东西就需要在Jframe上加入Jpanel。这个时候窗口大小和画布大小就是两个不一样的大小了,如果想要窗口大小自适应画布大小,就可以调用pack这个函数自适应。 绘制 在Jpanel类里面有一个paintComponent方法,这个方法是自带的一个方法,需要绘制的操作都要在这里面画。paintComponent带了一个画笔参数。 private class AlgoCanvas extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawOval(50, 50, 300, 300); } } 画一个简单的圆。 但其实如果是仅仅在2D图像上画其实可以使用Graphic2D来画,把Graphic转换成Graphic2D就好了,而paintComponent是没有2D的这个参数的。这个时候画法就不一样了。 private class AlgoCanvas extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D graphics2D = (Graphics2D)g; Ellipse2D cirle = new Ellipse2D.Float(50, 50, 300, 300); graphics2D.draw(cirle); //g.drawOval(50, 50, 300, 300); } } 如果想要设置颜色,就可以直接调用setColor即可,而这个条件会一直持续要后面结束为止。 抗锯齿 可以看到上面画出的图片有点锯齿边界,不好看。之所以有抗锯齿是因为我们总是把一个像素是非黑即白,抗锯齿就很简单了,利用边缘的透明度灰度就好了,这样在视觉上看就会平滑一些。 双缓存 这种技术表现在动画上。首先看一下单缓存,比如要在画布上画上一个圆,现在要挪动这个圆的位置,那么就必须把这个画布上的圆抹掉,然后再新的位置画上。在我们视觉上就会看到闪烁了一下,有一个经典的解决方法,就是用双缓存,也就是两个画布,用画布的切换来演示动画的运行。要开启其实很简单: public AlgoCanvas(){ super(true); } 简单动画 EventQueue.invokeLater(() -> { AlgorFrame algorFrame = new AlgorFrame("Welcome", 500, 500); new Thread(() -> { while (true) { algorFrame.render(circles); try { Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } for (Circle circle : circles) { circle.move(); } } }).start(); }); } } MVC 用一个弹球动画演示。首先Frame层就是一个view试图层,小球类就是属于model数据层,还差一个控制层把两个逻辑连接起来。 public class AlgoVisualizer { private Circle[] circles; private AlgorFrame algorFrame; public AlgoVisualizer(int sceneWidth, int sceneHeight, int n) { circles = new Circle[n]; for (int i = 0; i < n; i++) { Circle circle = new Circle(30, 30, 5, new Random().nextInt(5), new Random().nextInt(5)); circles[i] = circle; } EventQueue.invokeLater(() -> { algorFrame = new AlgorFrame("Welcome", 500, 500); new Thread(() -> { run(); }).start(); }); } private void run() { while (true) { algorFrame.render(circles); try { Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } for (Circle circle : circles) { circle.move(0, 0, algorFrame.getCanvasWith(), algorFrame.getCanvasHeight()); } } } } 这个就作为控制类。在后面写算法的时候,可视化的操作就可以放在run方法里面写了。 交互 现在添加一个暂停功能。实现键盘监听有两个方法,第一个就是实现接口KeyListener,第二个就是继承KeyAdapter,KeyAdapter其实就是实现了刚刚的那个接口而已,只不过是空方法而已。 private class AlgoKeyListener extends KeyAdapter { @Override public void keyReleased(KeyEvent e) { if (e.getKeyChar() == ' ') { isAnimated = !isAnimated; } } } 鼠标也是一样的,写好监听器,然后注册即可。 private class AlgoMouseListener extends MouseAdapter { @Override public void mousePressed(MouseEvent event) { //System.out.println(event.getPoint()); event.translatePoint(0, -(algorFrame.getBounds().height - algorFrame.getCanvasHeight())); System.out.println(event.getPoint()); } } 简单的界面交互就到这来了。对于上面的实现基本是可以成一个模板的: package ApplicationOfAlgorithm.Probability; import javax.swing.*; import java.awt.*; public class AlgorithmFrame extends JFrame { private int canvasWidth; private int canvasHeight; public AlgorithmFrame(String title, int canvasWidth, int canvasHeight) { super(title); this.canvasWidth = canvasWidth; this.canvasHeight = canvasHeight; } private class AlgorithmCanvas extends JPanel { public AlgorithmCanvas() { super(true); } @Override public void paintComponent(Graphics graphics) { super.paintComponent(graphics); Graphics2D graphics2D = (Graphics2D) graphics; RenderingHints hints = new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); graphics2D.addRenderingHints(hints); } @Override public Dimension getPreferredSize(){ return new Dimension(canvasWidth, canvasHeight); } } } view层的模板。 package ApplicationOfAlgorithm.Probability; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.MouseAdapter; public class AlgorithmVisualizer { private Object data; private AlgorithmFrame frame; public AlgorithmVisualizer(int sceneWidth, int sceneHeight) { EventQueue.invokeLater(() -> { frame = new AlgorithmFrame("title", sceneWidth, sceneHeight); frame.addKeyListener(new AlgoKeyListener()); frame.addMouseListener(new AlgoMouseListener()); new Thread(() -> { run(); }).start(); }); } private void run() { } private class AlgoKeyListener extends KeyAdapter { } private class AlgoMouseListener extends MouseAdapter { } } 控制层模板。 package ApplicationOfAlgorithm.Probability; import javax.swing.*; import java.awt.*; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; public class AlgorithmHelper { private AlgorithmHelper() { } public static final Color Red = new Color(0xF44336); public static final Color Pink = new Color(0xE91E63); public static final Color Purple = new Color(0x9C27B0); public static final Color DeepPurple = new Color(0x673AB7); public static final Color Indigo = new Color(0x3F51B5); public static final Color Blue = new Color(0x2196F3); public static final Color LightBlue = new Color(0x03A9F4); public static final Color Cyan = new Color(0x00BCD4); public static final Color Teal = new Color(0x009688); public static final Color Green = new Color(0x4CAF50); public static final Color LightGreen = new Color(0x8BC34A); public static final Color Lime = new Color(0xCDDC39); public static final Color Yellow = new Color(0xFFEB3B); public static final Color Amber = new Color(0xFFC107); public static final Color Orange = new Color(0xFF9800); public static final Color DeepOrange = new Color(0xFF5722); public static final Color Brown = new Color(0x795548); public static final Color Grey = new Color(0x9E9E9E); public static final Color BlueGrey = new Color(0x607D8B); public static final Color Black = new Color(0x000000); public static final Color White = new Color(0xFFFFFF); public static void strokeCircle(Graphics2D graphics2D, int x, int y, int r) { Ellipse2D circle = new Ellipse2D.Double(x - r, y - r, 2 * r, 2 * r); graphics2D.draw(circle); } public static void fillCircle(Graphics2D graphics2D, int x, int y, int r) { Ellipse2D circle = new Ellipse2D.Double(x - r, y - r, 2 * r, 2 * r); graphics2D.fill(circle); } public static void strokeRectangle(Graphics2D g, int x, int y, int w, int h) { Rectangle2D rectangle = new Rectangle2D.Double(x, y, w, h); g.draw(rectangle); } public static void fillRectangle(Graphics2D g, int x, int y, int w, int h) { Rectangle2D rectangle = new Rectangle2D.Double(x, y, w, h); g.fill(rectangle); } public static void setColor(Graphics2D g, Color color) { g.setColor(color); } public static void setStrokeWidth(Graphics2D g, int w) { int strokeWidth = w; g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); } public static void pause(int t) { try { Thread.sleep(t); } catch (InterruptedException e) { e.printStackTrace(); } } public static void putImage(Graphics2D graphics2D, int x, int y, String imageURL) { ImageIcon imageIcon = new ImageIcon(imageURL); Image image = imageIcon.getImage(); graphics2D.drawImage(image, x, y, null); } public static void drawText(Graphics2D g, String text, int centerx, int centery) { if (text == null) throw new IllegalArgumentException("Text is null in drawText function!"); FontMetrics metrics = g.getFontMetrics(); int w = metrics.stringWidth(text); int h = metrics.getDescent(); g.drawString(text, centerx - w / 2, centery + h); } } model层的模板。

优秀的个人博客,低调大师

架构语言ArchiMate - 语言结构(Language Structure

在ArchiMate - 开篇:企业架构语言ArchiMate介绍中对企业架构语言ArchiMate进行了总体介绍,本篇将介绍一下ArchiMate的语言结构。 元模型级别 知道OO的都知道,任何东西都是对象,在元模型的语言最抽象级别就是对象(Object)和关系(Relation) 对于企业架构来说,重要的概念就是产品(业务流程)和实现(应用) 开发架构时,需要对特定领域进行描述,比如流程图、领域模型图等 核心概念 区分内部和外部概念,有点类似SOA的架构概念 外部是暴露给客户的产品和服务,如Service和Interface 内部是具体行为和相关结构元素 协作与交互(Collaboration and Interaction) 协助包含多个结构元素 交互是一种行为 关系(Relationships) The ArchiMate Framework ArchiMate是一种集成多种架构的一种可视化业务分析模型语言,它从下图业务、应用和技术三个层次(Layer),对象、行为和主体三个方面(Aspect)和产品、组织、流程、信息、数据、应用、技术领域(Domain)来进行描述: 业务层(Business):提供对外部客户的产品和服务 ,这些服务由组织内的业务角色通过业务流程来实现 应用层(Application):支持业务服务的应用 技术层(Technology):通过硬件和软件的交互来运行应用程序 除了以上这些核心方面之外,还有其它一些重要的领域概念,如:目标(Goals)、安全(Security)、治理(Governance)、费用(Costs)、性能(Performance)、时间(Timing)、计划和演进(Planning and evolution)等。 本文转自 jingen_zhou 51CTO博客,原文链接:http://blog.51cto.com/zhoujg/518607,如需转载请自行联系原作者

优秀的个人博客,低调大师

论文札记之 - A Latent Semantic Model with Convolutional-Pooling Structure f...

前言 在统计自然语言处理任务中,最基础也是最关键的一步是将人能够理解的文本编码为机器能够计算的向量,并且在编码过程中,尽量保留原有的语法和语义特征。语法特征包括词法:形容词,动词,名词等;句法:主谓宾,定状补;语义角色:如施事、受事、与事。语义特征则是需要结合上下文推到出的文本真正的含义,对歧义句式进行更严格的分化,可以解释某些同形格式产生歧义的原因。这篇 paper 讨论的是如何利用卷积的方式对语义特征进行编码, The CLSM Architecture 卷积潜在语义模型(CLSM),基于卷积神经网络的潜在语义模型,捕捉重要的上下文特征用于语义建模,传统的 LSM 比较常用的有 LSA ,主要是构造 doc-term 矩阵,然后进行 svd 分解,得到 term vector 和 doc vector,缺点是只能建

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册