首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

这样调用如何不行啊

2011-12-29 
这样调用怎么不行啊?下面有个地方调用怎么不行啊70行的p.paintLine(ul)importjava.awt.*importjavax.swi

这样调用怎么不行啊?
下面有个地方调用怎么不行啊70行的         p.paintLine(ul);
import   java.awt.*;
import   javax.swing.*;
import   java.awt.event.*;
import   java.util.*;
import   java.io.*;
public   class   ScribbleDemo   extends   JFrame   implements   ActionListener{

    JMenuBar   menubar=new   JMenuBar();
    JMenu   []   menus=   new   JMenu[]
        {
                new   JMenu( "文件 "),
                new   JMenu( "编辑 "),
new   JMenu( "查找 "),
                new   JMenu( "帮助 ")
        };
    JMenuItem   menuitems   [][]   =new   JMenuItem[][]
        {
                {
                        new   JMenuItem( "打开 "),
                        new   JMenuItem( "保存 "),
                        new   JMenuItem( "退出 ")
                },
                {
                new   JMenuItem( "全选 "),
                        new   JMenuItem( "剪切 "),
                        new   JMenuItem( "粘贴 "),
                        new   JMenuItem( "复制 ")
                },
                {
                new   JMenuItem( "查找 "),
                new   JMenuItem( "替换 ")
                },
                {
                        new   JMenuItem( "About ")
                }
      };
      private   FileDialog   fd;
      private   LinkedList[]   m=new   LinkedList[20];
      public   ScribblePanel   p   =new   ScribblePanel();
      public   ScribbleDemo()   {
        //   Create   a   PaintPanel   and   add   it   to   the   content   pane
        getContentPane().add(p,   BorderLayout.CENTER);
        for(int   i=0;i <menus.length;i++)
      {
                        menubar.add(menus[i]);
                        for(int   j=0;j <menuitems[i].length;j++)
                        {


                                menus[i].add(menuitems[i][j]);
                                menuitems[i][j].addActionListener(this);
                        }
      }
                this.setJMenuBar(menubar);
    }
      public   void   actionPerformed(ActionEvent   e)
      {
      String   choose   =e.getActionCommand();
      //if(choose.equals( "保存 "))
        //this.openFile();
     
      }
      public   void   openFile()
      {
              fd=new   FileDialog(this, "打开 ",FileDialog.LOAD);
          fd.setVisible(true);
          String   path=fd.getDirectory()+ "// "+fd.getFile();
          try
          {
          FileInputStream   fin   =   new   FileInputStream(path);
                ObjectInputStream   in   =   new   ObjectInputStream(fin);
                LinkedList[]   u1   =   (LinkedList[])in.readObject();   //读取对象
                p.paintLine(ul);//********这个地方怎么不行啊??
                }
                catch   (FileNotFoundException   fe){}
                catch   (IOException   ioe){}
                catch   (ClassNotFoundException   ioe)   {}

               
      }

    /**   Main   method   */
    public   static   void   main(String[]   args)   {
        ScribbleDemo   frame   =   new   ScribbleDemo();
        frame.setTitle( "ScribbleDemo ");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300,   300);
        frame.setVisible(true);
    }
}

//   ScribblePanel   for   scribbling   using   the   mouse
  class   ScribblePanel   extends   JPanel
        implements   MouseListener,   MouseMotionListener   {
    final   int   CIRCLESIZE   =   20;   //   Circle   diameter   used   for   erasing
    private   Point   lineStart   =   new   Point(0,   0);   //   Line   start   point
   
    //private   LinkedList   l=new   LinkedList();
    private   LinkedList[]   m=new   LinkedList[20];//最多20条线
    private   int   i=0;
    protected   void   paintComponent(Graphics   g)


      {
      super.paintComponent(g);
        paintLine(m);
      }
     
    public   void   paintLine(LinkedList[]   m)  
    {  
        Graphics   g=this.getGraphics();
    Point   start=new   Point(0,   0);
        Point   end=new   Point(0,   0);
        for(int   k=0;k <i;k++)
        {      
        if(m[k].size()> 0)
        {
        start.move(((Point)m[k].get(0)).x,((Point)m[k].get(0)).y);
        for(int   n=1;n <m[k].size();n++)
        {
        end.move(((Point)m[k].get(n)).x,((Point)m[k].get(n)).y);
        g.drawLine(start.x,start.y,end.x,end.y);
        start.move(((Point)m[k].get(n)).x,((Point)m[k].get(n)).y);
        }
        }
        }
    }
    public   ScribblePanel()   {
        //   Register   listener   for   the   mouse   event
        addMouseListener(this);
        addMouseMotionListener(this);
    }

    public   void   mouseClicked(MouseEvent   e)   {
    }

    public   void   mouseEntered(MouseEvent   e)   {
    }

    public   void   mouseExited(MouseEvent   e)   {
    }

    public   void   mouseReleased(MouseEvent   e)   {
    }

    public   void   mousePressed(MouseEvent   e)   {
        lineStart.move(e.getX(),   e.getY());
        LinkedList   l=new   LinkedList();
        m[i]=l;
        Point   s=new   Point(e.getX(),e.getY());
        l.add(s);
        i++;

    }

    public   void   mouseDragged(MouseEvent   e)   {
        //   Create   a   Graphics   object   for   drawing
        Graphics   g   =   getGraphics();
        Point   s=new   Point(e.getX(),e.getY());
        if   (e.isMetaDown())   {   //   Detect   right   button   pressed
            //   Erase   the   drawing   using   an   oval
            g.setColor(getBackground());
            g.fillOval(e.getX()   -   (CIRCLESIZE   /   2),
                  e.getY()   -   (CIRCLESIZE   /   2),   CIRCLESIZE,   CIRCLESIZE);
        }
        else   {
            g.setColor(Color.black);
            g.drawLine(lineStart.x,   lineStart.y,


                e.getX(),   e.getY());
        }
       
        lineStart.move(e.getX(),   e.getY());
        m[i-1].add(s);
        g.dispose();
    }

    public   void   mouseMoved(MouseEvent   e)   {
    }
}


[解决办法]
是u1,不是ul。。。
[解决办法]
LinkedList[] u1 = (LinkedList[])in.readObject(); //读取对象
p.paintLine(ul);//********这个地方怎么不行啊??
------------------------
一个ul 一个u1 LZ啊!

热点排行