我只是不知道怎么把中间的editor部分变成一个可以Panel,其他的再自己研究,请高人赐教

解决方案 »

  1.   

    只要把中间写字板的部分改成可以画画的panel
      

  2.   

    ajian111(longhorn) 能不能把源吗的具体地址贴出来啊,找了半天都没找到
      

  3.   

    没有啊,为什么不能有MenuBar呢,可以保存和读取文件啊,至于编辑的部分倒可以去掉
      

  4.   

    以下是我上java实验课时候做的画板程序的代码,功能包括打开,保存,退出,清除
    希望能对你有所帮助
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.awt.*;
    import java.util.*;
    public class MainFrame extends JFrame implements MouseMotionListener,MouseListener
                                                     //ActionListener
    {  JPanel desktop;
      
      JMenuBar MBar;
      Vector dot=new Vector();  
      boolean beginDraw = false;
      Vector v = new Vector();

      public MainFrame(){    super("Draw");
        buildContent();
        buildMenu();
        addMouseMotionListener(this);
        addMouseListener(this);
        
        this.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           quit(); 
            }
        });//end of addWindowListener
      }//end of main  protected void buildContent() {
        desktop = new JPanel();
        getContentPane().add(desktop,BorderLayout.CENTER);
        desktop.setBackground(Color.white);
      }//end of buildContent()  protected void buildMenu(){
       JPopupMenu.setDefaultLightWeightPopupEnabled(false);    MBar = new JMenuBar(); 
        MBar.setOpaque(true);
        JMenu mfile = buildFileMenu();    MBar.add(mfile);
        
        setJMenuBar(MBar);    
      }//end of bulidMenu()  public void quit(){
        System.exit(0); 
      }//end of quit()  public JMenu buildFileMenu() {
      
        JMenu file = new JMenu("File");    JMenuItem open = new JMenuItem("Open");
        JMenuItem save= new JMenuItem("Save");   
        JMenuItem clear = new JMenuItem("Clear");
        JMenuItem exit = new JMenuItem("Exit");
        file.add(open);
        file.add(save);
          file.add(clear);      
        file.addSeparator();
        file.add(exit);
        open.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
            {  
           try{
         FileInputStream fis=new FileInputStream("Save.ser");
    ObjectInputStream ois=new ObjectInputStream(fis);
    v=(Vector) ois.readObject();
    ois.close();
    repaint();
        }catch(Exception t){}
        
            }});
        save.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
            {
           try{
         FileOutputStream fos=new FileOutputStream("Save.ser");
    ObjectOutputStream oos=new ObjectOutputStream(fos);
    oos.writeObject(v);
    oos.close();
            }catch(Exception t){}
            }});
        exit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
            {
        
         System.exit(0);
        
            }}); 
        clear.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
            {      
                v.clear();
                repaint();
            }});
        return file;
      }//end of buildFileMenu()
    public void mouseMoved(MouseEvent e){}public void mouseDragged(MouseEvent e)
    {
       Point p = null;
       if(beginDraw)
       {
          p = new Point(e.getX(), e.getY());
          dot.add(p); 
         Graphics g = getGraphics();
        
          draw_buf(g);
         
       }
    }
    public void mouseClicked(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}
    public void mousePressed(MouseEvent e)
    {
        dot.clear();
        beginDraw = true;
    }
    public void mouseReleased(MouseEvent e)
    {
       beginDraw = false;
       v.add(dot.clone());
       
    }
    public  void paint(Graphics g)
     {  
       super.paint(g);
      
       g.setColor(Color.blue);
        for(int i = 0; i < v.size(); i++)
        {
            Vector temporary = (Vector)v.get(i);
                 for(int loop=0;loop<temporary.size()-1;loop++)
             {
                      Point p = (Point)temporary.get(loop);
                      Point p1 = (Point)temporary.get(loop + 1);
                      g.drawLine(p.x,p.y,p1.x,p1.y);
             }
         }
          }
     public void draw_buf(Graphics g)
      {
       g.setColor(Color.blue);
      for(int loop=0;loop<dot.size()-1;loop++)
        {
          Point p = (Point)dot.get(loop);
          Point p1 = (Point)dot.get(loop + 1);
          g.drawLine(p.x,p.y,p1.x,p1.y);
        }
      }  public static void main(String[] args)
      {
       MainFrame win1=new MainFrame();
       win1.setSize(600,600);
       win1.show();
      
      }
    }//end of class MainFrame