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

📄 myeditorkit.java

📁 这是一个汉诺塔程序
💻 JAVA
字号:
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.PlainView;
import javax.swing.text.Segment;
import javax.swing.text.Utilities;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;

/**
 * 
 */

/**
 * @author LightingMan
 *
 */
class   MyEditorKit   extends   DefaultEditorKit{   
        public   MyEditorKit(){   
                super();   
        }   
  
        public   ViewFactory   getViewFactory(){   
                return   new   MyViewFactory();   
      }   
}   
  
class   MyViewFactory   implements   ViewFactory   
{   
        public   MyViewFactory(){   
        }   
  
        public   View   create(Element   element){   
                return   new   MyEditorView(element);   
        }   
}   
  
class   MyEditorView   extends   PlainView{   
        public   MyEditorView(Element   element){   
                super(element);   
        }  
         protected   int   drawUnselectedText(Graphics   g,   int   x,   int   y,   int   p0,   int   p1)   
                throws   BadLocationException{   
                Document   doc=getDocument();   
                Segment   segment=new   Segment(),   token=new   Segment();   
                
                int   index=0,   count=p1-p0;   
  
                doc.getText(p0,   count,   segment);   
                
                for(int   i=0;   i<count;   i++){   
                        if(Character.isLetter(segment.array[segment.offset+i])){   
                                index=i;   
                                while(++i<count&&Character.isLetter(segment.array[segment.offset+i]));
                                
                                doc.getText(p0+index,   (i--)-index,   token);   //change
                                										//change
                                
                                if(KeyWord.isKeyWord(token)){   
                                        g.setFont(KEYWORDFONT);   
                                        g.setColor(KEYWORDCOLOR);   
                                }
                                else
                                if (Attrib.isKeyWord(token)){
                                	g.setFont(ATTRIBWORDFONT);
                                	g.setColor(ATTRIBWORDCOLOR);
                                }
                                else
                                {   
                                        g.setFont(TEXTFONT);   
                                        g.setColor(TEXTCOLOR);   
                                }   
                               	x=Utilities.drawTabbedText(token, x, y,   g, this, p0+index)+1;
                              
                                continue;   
                        }
                        else
                        {   
                                index=i;   
                                while(++i<count&&!Character.isLetter(segment.array[segment.offset+i]));   
                                doc.getText(p0+index,   (i--)-index,   token);   
                                g.setFont(TEXTFONT);   
                                g.setColor(TEXTCOLOR);   
                                x=Utilities.drawTabbedText(token,   x,   y,   g,   this,   p0+index)+1;   
                                continue;   
                        }   
                }   
                return   0;   
          }   
  
        public   static   Font   TEXTFONT=new   Font("Courier   New",   Font.PLAIN,   20);   
        public   static   Color   TEXTCOLOR=Color.black;   
        public   static   Font   KEYWORDFONT=new   Font("Courier   New",   Font.PLAIN,   20);   
        public   static   Color   KEYWORDCOLOR=Color.blue;   
        public   static   Font   ATTRIBWORDFONT=new   Font("Courier   New",   Font.PLAIN,   20);   
        public   static   Color   ATTRIBWORDCOLOR=Color.red; 
}   

⌨️ 快捷键说明

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