package One;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
class HopCanvas extends Canvas implements MouseListener, MouseMotionListener {
HopfieldApp parent;
public HopCanvas(HopfieldApp a) {
parent = a;
setSize(680, 200);
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public void paintRectangles() {
Graphics g = getGraphics();
Pattern current_pattern = parent.current_pattern;
int xsize, ysize;
int loc, xpos, ypos, i;
xsize = parent.xsize;
ysize = parent.ysize;
setBackground(Color.white);
for (loc = 0; loc < parent.current_pattern.length; loc++) {
ypos = (int) (loc / (xsize / current_pattern.blocksize))
* current_pattern.blocksize;
xpos = (loc % (xsize / current_pattern.blocksize))
* current_pattern.blocksize;
if (current_pattern.pattern[loc] > 0)
g.setColor(Color.red);
else
g.setColor(Color.blue);
g.fillRect(xpos + 1, ypos + 1, current_pattern.blocksize - 2,
current_pattern.blocksize - 2);
}
}
public void paintGraph() {
Graphics g = getGraphics();
int i;
Pattern current_pattern = parent.current_pattern;
int xsize, ysize;
double overlap1[];
double overlap2[];
int overlap;
xsize = parent.xsize;
ysize = parent.ysize;
overlap1 = parent.overlap1;
overlap2 = parent.overlap2;
overlap = parent.overlap;
setBackground(Color.white);
g.setColor(Color.black);
g.drawRect(0, 0, xsize - 1, ysize - 1); // frames
g.drawLine(xsize + 20, 10, xsize + 20, ysize - 20); // axis
g.drawLine(xsize + 20, 10, xsize + 15, 20);
g.drawLine(xsize + 20, 10, xsize + 25, 20);
g.drawLine(xsize + 18, ysize - 100, xsize + 380, ysize - 100);
g.drawLine(xsize + 380, ysize - 100, xsize + 370, ysize - 105);
g.drawLine(xsize + 380, ysize - 100, xsize + 370, ysize - 95);
g.drawString("迭代", xsize + 340, ysize - 108);
g.drawString("重叠", xsize + 28, 20);
g.drawString("0", xsize + 9, ysize - 96);
g.drawString("最先模式", xsize + 322, 20);
g.drawString("最后模式", xsize + 322, 40);
g.drawString("1", xsize + 9, ysize - 166);
g.drawString("1", xsize + 9, ysize - 26);
g.drawLine(xsize + 18, ysize - 30, xsize + 22, ysize - 30);
g.drawLine(xsize + 18, ysize - 170, xsize + 22, ysize - 170);
for (i = 1; i < 10; i++)
g.drawLine(xsize + 20 + (i * 34), ysize - 98,
xsize + 20 + (i * 34), ysize - 102);
g.setColor(Color.red);
g.drawLine(xsize + 300, 16, xsize + 320, 16);
if (overlap == 1)
g.drawRect(xsize + 21, ysize - 100
- (int) (overlap1[0] * 70), 1, 1);
else
for (i = 0; i < overlap - 1; i++)
g.drawLine(xsize + 21 + i * 34, ysize - 100
- (int) (overlap1[i] * 70), xsize + 21 + (i + 1) * 34,
ysize - 100 - (int) (overlap1[i + 1] * 70));
g.setColor(Color.blue);
g.drawLine(xsize + 300, 36, xsize + 320, 36);
if (overlap == 1)
g.drawRect(xsize + 21, ysize - 100
- (int) (overlap2[0] * 70), 1, 1);
else
for (i = 0; i < overlap - 1; i++)
g.drawLine(xsize + 21 + i * 34, ysize - 100
- (int) (overlap2[i] * 70), xsize + 21 + (i + 1) * 34,
ysize - 100 - (int) (overlap2[i + 1] * 70));
}
public void paint(Graphics g) {
paintRectangles();
paintGraph();
}
public void mouseClicked(MouseEvent e) {
int xsize = parent.xsize;
int ysize = parent.ysize;
int x = e.getX();
int y = e.getY();
Pattern current_pattern = parent.current_pattern;
int click_loc = (int) ((x / current_pattern.blocksize) + ((int) (y / current_pattern.blocksize) * (int) (xsize / current_pattern.blocksize)));
if ((x < xsize) && (y < ysize)) {
current_pattern.toggle(click_loc);
Graphics hop_graphics = getGraphics();
if (current_pattern.pattern[click_loc] > 0) {
parent.erase = false;
hop_graphics.setColor(Color.red);
} else {
parent.erase = true;
hop_graphics.setColor(Color.blue);
}
hop_graphics.fillRect(x - (x % current_pattern.blocksize) + 1, y
- (y % current_pattern.blocksize) + 1,
current_pattern.blocksize - 2,
current_pattern.blocksize - 2);
parent.changed = true;
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
int xsize = parent.xsize;
int ysize = parent.ysize;
int x = e.getX();
int y = e.getY();
Pattern current_pattern = parent.current_pattern;
boolean erase = parent.erase;
int click_loc = (int) ((x / current_pattern.blocksize) + ((int) (y / current_pattern.blocksize) * (int) (xsize / current_pattern.blocksize)));
if ((x < xsize) && (y < ysize)) {
Graphics hop_graphics = getGraphics();
if (erase) {
if (current_pattern.pattern[click_loc] > 0)
current_pattern.toggle(click_loc);
hop_graphics.setColor(Color.blue);
} else {
if (current_pattern.pattern[click_loc] < 0)
current_pattern.toggle(click_loc);
hop_graphics.setColor(Color.red);
}
hop_graphics.fillRect(x - (x % current_pattern.blocksize) + 1, y
- (y % current_pattern.blocksize) + 1,
current_pattern.blocksize - 2,
current_pattern.blocksize - 2);
parent.changed = true;
}
}
public void mouseMoved(MouseEvent e) {
}
}
Hopfield Binary Model Java实现【源代码】
5星 · 超过95%的资源 需积分: 10 76 浏览量
2008-11-27
00:15:20
上传
评论
收藏 20KB RAR 举报
黑夜愁客
- 粉丝: 81
- 资源: 48
最新资源
- Pandas 透视表和交叉表
- 基于C51单片机+DS1302+lcd1602仿真设计多功能时钟(C软件源程序+proteus仿真)文件.zip
- 747333869988656【泰拉地图】1.0_Android手机版.apk
- 基于小程序的交友系统项目(免费提供全套java开源项目源码+论文+ppt+软件+使用说明)
- Fortran语言要点和难点具体案例代码实例和代码解析
- Screenshot_20240505_104248.jpg
- 基于C51单片机电子抽奖系统设计proteus仿真+软件源程序.zip
- 旅行商问题(Travelling Salesman Problem, TSP)是一个经典的组合优化问题,在运筹学和理论计算机科学
- 基于小程序+Socket+Node的IM系统项目(免费提供全套java开源项目源码+论文+ppt+软件+使用说明)
- Spring Boot是一个基于Spring框架的开源项目,旨在简化Spring应用的初始搭建以及开发过程 以下是对Spring
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈