📄 drawpanel.java~45~
字号:
package App;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 2.0(2005.7.5)加入图形界面
* @version 2.1(2005.7.5)加入动画,节点的遍历
*/
import javax.swing.*;
import java.awt.* ;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.border.*;
public class DrawPanel extends JPanel {
Table t ;//表格数据
String function;//进行某种操作的标志
public DrawPanel() {
t=new Table();
function=new String();
}
public DrawPanel(Table t){
this.t=t;
}
public DrawPanel(Table t,String function){
this.t=t; this.function=function;
}
/**画布边框(35,15,600,420)即wide=565 high=415
*画节点的区域为(35,15,600,400)
*节点半径r=20
*/
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(t.tables[0]==null)
paintInit(g);
else{
if(function!=null&&function.equals("text")==true)
//super.paintComponent(g);
paintTree(g);
}
//画边框
//g.setColor(Color.blue);
//t.setTable();
//Dimension d=new Dimension();
//d=this.getSize();
//g.drawString(d.getWidth()+" "+d.getHeight(),100,100);
//this.setSize(new Dimension(630,500));
//g.drawRect(0+35,0+15,600,420);
/**if(t.isEmpty()==true){
//画白框
g.setColor(Color.white);
g.fillRect(0 + 35, 0 + 15, 600, 420);
}
else{
//画白框
g.setColor(Color.white);
g.fillRect(0 + 35, 0 + 15, 600, 420);
//画线
for (int i = 1; t.tables[i] != null; i++) {
if (i > 0) {
paintLine(g, t.tables[t.tables[i].parents], t.tables[i]);
}
}
//画点
for (int i = 0; t.tables[i] != null; i++) {
paintNode(g, t.tables[i]);
}
}*/
}
public void paintInit(Graphics g){
//super.paintComponent(g);
//画白框
g.setColor(Color.white);
g.fillRect(0 + 35, 0 + 15, 600, 420);
}
public void paintTree(Graphics g){
//画白框
g.setColor(Color.white);
g.fillRect(0 + 35, 0 + 15, 600, 420);
//画线
for (int i = 1; t.tables[i] != null; i++) {
if (i > 0) {
paintLine(g, t.tables[t.tables[i].parents], t.tables[i]);
}
}
//画点
for (int i = 0; t.tables[i] != null; i++) {
paintNode(g, t.tables[i]);
}
repaint();
}
/**画点*/
public void paintNode(Graphics g, TableNode nodes) {
//locateName(name)
int r=10;//圆圈半径为10
g.setColor(Color.RED);
g.drawOval(nodes.getX()-r, nodes.getY()-r, r*2,r*2); //圆圈直径为20
g.setColor(Color.white);
g.fillOval(nodes.getX()-r + 1, nodes.getY()-r + 1, r*2-1, r*2-1);
g.setColor(Color.BLACK);
g.drawString(nodes.name.toString(), nodes.getX()-r + 7,
nodes.getY()-r + 14);
}
/**画线*/
public void paintLine(Graphics g, TableNode nodes1, TableNode nodes2) {
g.setColor(Color.BLACK);
g.drawLine(nodes1.getX(), nodes1.getY() , nodes2.getX(),
nodes2.getY() );
}
/**设置表格*/
public void setTable(Table table){
t=table;
}
/**设置所要进行的操作*/
public void setFunction(String f){
function=f;
}
public int index(int i){
if(t.pathnumber!=null){
i++;
}
return t.pathnumber[i];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -