日期:2014-05-20  浏览次数:20835 次

为什么我的复制剪切功能不能实现,请大家棒我修改下
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.*;
import java.io.*;
import javax.swing.JMenu;
import javax.swing.*;
import java.awt.*;

public class TestMenu
{
  public static void main(String args[])
  {
  MyMenuFrame mf = new MyMenuFrame();
  }
}

class MyMenuFrame extends Frame
{
MenuBar m_MenuBar;
Menu menuFile, menuEdit,menuFont;
MenuItem mi_File_Open,mi_File_Close,mi_File_Exit;
MenuItem mi_Edit_Cut, mi_Edit_Copy, mi_Edit_Paste,mi_Edit_Find,mi_Edit_All;
CheckboxMenuItem mi_Font_Style, mi_Font_Size;
TextArea ta;
FileDialog fd;
String str="";
String ta_Font_Name;
Clipboard clipboard = null;
BufferedReader br;
FileReader fr;
BufferedWriter bw;
FileWriter fw;
int ta_Font_Style,new_Style, ta_Font_Size,new_Size;
FileDialog fdialog= new FileDialog(this,"文件对话框",FileDialog.LOAD);
MyMenuFrame()
{
super("拥有菜单的窗口");
ta = new TextArea(5,30);

add(ta,BorderLayout.CENTER);
m_MenuBar = new MenuBar();
menuFile = new Menu("文件");
mi_File_Open = new MenuItem("打开");
mi_File_Open.setShortcut(new MenuShortcut(KeyEvent. VK_O));
mi_File_Close = new MenuItem("关闭");
mi_File_Exit = new MenuItem("退出");
mi_File_Open.addActionListener(new HandleActFile1(this));
mi_File_Close.addActionListener(new HandleAct());
mi_File_Exit.addActionListener(new HandleAct());
menuFile.add(mi_File_Open);
menuFile.add(mi_File_Close);
menuFile.addSeparator();
menuFile.add(mi_File_Exit);
m_MenuBar.add(menuFile);
menuEdit = new Menu("编辑");
mi_Edit_Cut = new MenuItem("剪切");
mi_Edit_Cut.setShortcut(new MenuShortcut(KeyEvent. VK_X));
mi_Edit_Copy = new MenuItem("复制");
mi_Edit_Copy.setShortcut(new MenuShortcut(KeyEvent. VK_C));
mi_Edit_Paste = new MenuItem("粘贴");
mi_Edit_Paste.setShortcut(new MenuShortcut(KeyEvent. VK_V));
mi_Edit_Find= new MenuItem("查找");
mi_Edit_Find.setShortcut(new MenuShortcut(KeyEvent. VK_F));
mi_Edit_All=new MenuItem("全选");
mi_Edit_All.setShortcut(new MenuShortcut(KeyEvent. VK_A));
mi_Edit_Cut.addActionListener(new HandleActFile1(this));
mi_Edit_Copy.addActionListener(new HandleActFile1(this));
mi_Edit_Paste.addActionListener(new HandleActFile1(this));
mi_Edit_Find.addActionListener(new HandleActFile1(this));
mi_Edit_All.addActionListener(new HandleAct6());
menuEdit.add(mi_Edit_Cut);
menuEdit.add(mi_Edit_Copy);
menuEdit.add(mi_Edit_Paste);
menuEdit.add(mi_Edit_Find);
menuEdit.add(mi_Edit_All);
m_MenuBar.add(menuEdit);
menuFont=new Menu("文字");
mi_Font_Style = new CheckboxMenuItem("粗体");
mi_Font_Size = new CheckboxMenuItem("大字体");
mi_Font_Style.addItemListener(new HandleItem1());
mi_Font_Size.addItemListener(new HandleItem2());
menuFont.add(mi_Font_Size);
menuFont.add(mi_Font_Style);
m_MenuBar.add(menuFont);
this.setMenuBar(m_MenuBar);
setSize(400,200);
setVisible(true);
ta_Font_Name = (ta.getFont()).getName();
ta_Font_Style = (ta.getFont()).getStyle();
new_Style = ta_Font_Style;
ta_Font_Size = (ta.getFont()).getSize();
new_Size = ta_Font_Size;
this.addWindowListener(new HandleWin());
}

class HandleAct implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Frame ff=new Frame();
ConfirmDlg confirm=new ConfirmDlg(ff);
if(e.getActionCommand()=="退出")
{
if(confirm.ans)
{

  ff.dispose();