コードにコピーとクリアを追加しましたが、正常に動作しますが、ユーザーが指定されたテストの出力領域を検索できるようにするカットと検索コマンドにまだ問題があります
public class rr extends JFrame implements ActionListener {
private JTextArea outputArea;
public rr()
{
associatedTextSet = new HashSet<String>();
initialiseWindow();
}
private void initialiseWindow()
{
setTitle("rr");
setLocation(50, 50);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
contentPane = getContentPane();
contentPane.setBackground(Color.magenta);
contentPane.setLayout( new BoxLayout(contentPane, BoxLayout.Y_AXIS) );
WindowAdapter windowListener = new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
ActionEvent action = new ActionEvent(this, 0, "Exit");
actionPerformed(action);
} };
addWindowListener(windowListener);
setupMenusAndActions();
setUpOutputArea();
setVisible(true);
}
private void setUpOutputArea()
{
outputArea = new JTextArea();
outputArea.setFont(new Font("Courier", Font.PLAIN, 12));
outputArea.setEditable(false);
outputArea.setBackground(Color.white);
outputArea.setLineWrap(true);
outputArea.setWrapStyleWord(true);
outputArea.setMargin(new Insets( 5, 10, 5, 10));
JScrollPane areaScrollPane = new JScrollPane(outputArea);
areaScrollPane.setPreferredSize( new Dimension(WIDTH, HEIGHT) );
Border b = BorderFactory.createLoweredBevelBorder();
areaScrollPane.setViewportBorder(BorderFactory.createTitledBorder(b, "Output View"));
contentPane.add(areaScrollPane);
pack();
TextAreaOutputStream textOutput = new TextAreaOutputStream(outputArea);
PrintStream capturedOutput = new PrintStream(textOutput);
System.setOut(new PrintStream(capturedOutput)); // divert StandardOutput to capturedOutput
}
private void setupMenusAndActions()
{
JMenuBar menuBar = new JMenuBar();
// Edit menu
editMenu = setupMenu(menuBar, "Edit", 'E');
setupMenuItem(editMenu, "Copy", "Copy selected text from Output area to clipboard", 'C', true, KeyStroke.getKeyStroke("ctrl C"));
setupMenuItem(editMenu, "Cut", "Cut selected text from Output area to clipboard", 'T', true );
setupMenuItem(editMenu, "Find", " Find selected text from Output area to clipboard", 'F', true );
setupMenuItem(editMenu, "Clear", "Clear Output area", 'L', true, KeyStroke.getKeyStroke("ctrl F3"));
setJMenuBar(menuBar);
}
public void actionPerformed(ActionEvent e)
{
String action = e.getActionCommand();
//
// Edit menu
//
else if( action.equals("Copy") )
{
outputArea.copy();
}
else if(action.equals("Cut"))
{
outputArea.cut();
}
else if( action.equals("Clear") )
{
outputArea.selectAll();
outputArea.setText("");
}
else if(action.equals("Find"))
{
}
}