直接写方法名称调用方法的,实际上是调用的当前类实例对象自己的方法,也就是省略了 this.的
如 setVisible(true)
就等同于 
this.setVisible(true)

解决方案 »

  1.   

    一般来说一个方法是静态的方法可以不用实例化对象来调用此方法,静态的方法可以调用静态的方法,或者静态的成员,内部类也可以是静态的,也不用实例化对象的。
    打个比方吧,我们常用的system.out.println()方法其实是一个道理。
    他不用实例化任何对象就可以调用,system是类,out是一个静态的成员,也就是一个静态的内部名,println()是内部类的一个方法,所以可以直接调用。
    class System1
    {
    static o out1 = new o();
    static class o
    {
     void print1()
    {
    System.out.println("out");
    }
    }
    }public class a
    {
    public static void main(String args[])
    {
    System1.out1.print1(); 
    }
    }上面是我做的一个仿照system.out.println()做的,可以参考参考~~~~~~~
    如果我上面说的有什么错误,还请大家多多纠正~~~~~~~~
      

  2.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;public class testpanel
        extends JFrame {
      JPanel jp1;
      JPanel jp2;
      Container cp = getContentPane();  JButton b1 = new JButton("1");
      JButton b5 = new JButton("2");  public testpanel() {
        b1.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cp.remove(jp1);
            cp.add(jp2);
            setVisible(true);
            repaint();
          }
        });    b5.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cp.remove(jp2);
            cp.add(jp1);
            setVisible(true);
            repaint();
          }
        });    jp1 = new JPanel();
        jp1.setLayout(new BorderLayout());
        jp1.add(BorderLayout.CENTER, b1);    jp2 = new JPanel();
        jp2.setLayout(new BorderLayout());    // jp2.add(BorderLayout.CENTER, img);    cp.add(jp1);
        setSize(500, 500);
        setVisible(true);
      }  public static void main(String[] args) {
        testpanel app = new testpanel();
        app.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
      }
    }
      

  3.   

    setVisible(true);
            repaint();
    是操作testpanel对象,
    内部类有访问创建它的对象的实现
      

  4.   

    加上 this 通不过是因为不知道是内部类的 this 还是外部类的 this
    可以加上类名来标识,如下面这个程序/*
     * @(#) Test.java
     * Created on 2004-9-21
     * Created by James Fancy
     */
    package jamesfancy;/**
     * @author James Fancy
     */
    public final class Test {
        
        public static interface MyTest {
            public void test();
        }
        
        public void testit() {
            new MyTest() {
                public void test() {
                    System.out.println(this.getClass().getName());
                    System.out.println(Test.this.getClass().getName());
                }
            }.test();
        }
        
        public static void main(String[] args) {
            Test test = new Test();
            test.testit();
        }}
    输出结果是:
    jamesfancy.Test$1
    jamesfancy.Test