从JPanel添加/删除行 [英] Adding/Removing Lines from a JPanel

查看:118
本文介绍了从JPanel添加/删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个图形实现,其中图形显示在JPanel上.

I am trying to create a graph implementation where the graph is displayed on a JPanel.

我可以毫无问题地添加和删除顶点(为此我使用了更多面板).我遇到的问题是添加线条来表示边缘.我知道我可以使用

I am adding and removing vertices without a problem (I am using more panels for these). The problem I am having is adding lines to represent the edges. I know I can use

contentPane.getGraphics().drawLine(x1, y1, x2, y2)

添加一行,但是以后我无法删除该行.有什么想法吗?

to add a line, but it leaves no way for me to delete that line later on. Any ideas?

推荐答案

GraphPanel 使用List<Edge>建模连接图节点的边.

GraphPanel uses a List<Edge> to model edges connecting the nodes of a graph.

这篇关于从JPanel添加/删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆