java两个类之间的调用 10
classMyMemoextendsFrameimplementsActionListener{privateTextAreaeditor=newTextArea();p...
class MyMemo extends Frame implements ActionListener {
private TextArea editor=new TextArea();
private MyFile mf=new MyFile(this);
private MyClipboard cb=new MyClipboard();
private MyFindDialog findDlg=new MyFindDialog(this,editor);
public void SyntaxHighlighter(){
JFrame frame = new JFrame();
JTextPane editor = new JTextPane();
editor.getDocument().addDocumentListener(new SyntaxHighlighter(editor));
frame.getContentPane().add(editor);
}
class SyntaxHighlighter implements DocumentListener {
private Set<String> keywords;
private Style keywordStyle;
private Style normalStyle;
public SyntaxHighlighter(JTextPane editor) {
// 准备着色使用的样式
keywordStyle = ((StyledDocument) editor.getDocument()).addStyle("Keyword_Style", null);
normalStyle = ((StyledDocument) editor.getDocument()).addStyle("Keyword_Style", null);
StyleConstants.setForeground(keywordStyle, Color.RED);
StyleConstants.setForeground(normalStyle, Color.BLACK);
public static void main(String[]args){
MyMemo memo=new MyMemo("张声龙的编辑器");
memo.setSize(300,300);
memo.setVisible(true);
}
}
求大神指教如何调用SyntaxHighlighter,使字体改变 展开
private TextArea editor=new TextArea();
private MyFile mf=new MyFile(this);
private MyClipboard cb=new MyClipboard();
private MyFindDialog findDlg=new MyFindDialog(this,editor);
public void SyntaxHighlighter(){
JFrame frame = new JFrame();
JTextPane editor = new JTextPane();
editor.getDocument().addDocumentListener(new SyntaxHighlighter(editor));
frame.getContentPane().add(editor);
}
class SyntaxHighlighter implements DocumentListener {
private Set<String> keywords;
private Style keywordStyle;
private Style normalStyle;
public SyntaxHighlighter(JTextPane editor) {
// 准备着色使用的样式
keywordStyle = ((StyledDocument) editor.getDocument()).addStyle("Keyword_Style", null);
normalStyle = ((StyledDocument) editor.getDocument()).addStyle("Keyword_Style", null);
StyleConstants.setForeground(keywordStyle, Color.RED);
StyleConstants.setForeground(normalStyle, Color.BLACK);
public static void main(String[]args){
MyMemo memo=new MyMemo("张声龙的编辑器");
memo.setSize(300,300);
memo.setVisible(true);
}
}
求大神指教如何调用SyntaxHighlighter,使字体改变 展开
展开全部
java类有两种方法一种是类方法就是用static修饰的,一种是实例方法,就是没有static修饰的方法。类方法可以同时类名.方法名的方式调用。而实例方法必须先生存类的实例在通过实例.方法名的方式调用。例如:<pre t="code" l="java">public class MethodCall
{
public static void main(String[] args)
{
Test.sayStatic();
Test test = new Test();
test.sayInstance();
}
}
class Test
{
public static void sayStatic()
{
System.out.println("这是一个静态方法。");
}
public void sayInstance()
{
System.out.println("这是一个实例方法。");
}
}<pre t="code" l="java">
{
public static void main(String[] args)
{
Test.sayStatic();
Test test = new Test();
test.sayInstance();
}
}
class Test
{
public static void sayStatic()
{
System.out.println("这是一个静态方法。");
}
public void sayInstance()
{
System.out.println("这是一个实例方法。");
}
}<pre t="code" l="java">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询