⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 circlenode.java~1~

📁 源程序(包括最初的版本
💻 JAVA~1~
字号:
package treeandbtreedemo;

/**
 * <p>Title:节点的图像,用了一个JLable的表示 </p>
 * <p>Description:节点的图行显示 ,用了一个JLable的表示</p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 3.0(2005.7.8)
 */
import java.awt.*;
import java.awt.Dimension;
import javax.swing.*;
import java.awt.event.*;


public class CircleNode extends JLabel{
  String name;//节点名字
  //int color;//颜色
  int radius;//半径
  boolean fill;//填充

  public CircleNode() { }
  public CircleNode(String name,int r,boolean fill){
    this.name=name; radius=r; this.fill=fill;
    paintComponent(this.getGraphics());
    this.setPreferredSize(new Dimension( radius+1,radius+ 1));
    this.setBackground(Color.white);//背景色
    this.setOpaque(true);//可见
  }

  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    g.setColor(Color.BLACK);
    g.drawString(name,this.getWidth()/2,this.getHeight()/2);//文字

    g.setColor(Color.RED);
    g.drawOval(0,0,radius,radius);//外框

    if(fill==false){//如果不需要填充颜色
      g.setColor(Color.WHITE);
      g.drawOval(1, 1, radius - 1, radius - 1);//填白色
    }
    else{//需要填充颜色
      g.setColor(Color.yellow);
      g.drawOval(1, 1, radius - 1, radius - 1);//填蓝色
    }
  }




}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -