CPlusPlusBeginner
CPlusPlusBeginner

Reputation: 11

Java ClipBoard Problem

I am writing a GUI for animation in Java. I am completely stumped on one element. I have a 2 JTextAreas that are called InputText, and OutputText where the input is copied to the output area with the use of a copy Jbutton. I then have a Next and Previous Button that should switch through frames on the OutputText area. I used a JLabel as a counter in between these two buttons.

What I am trying to do is use the clipboard to hold each "frame" if you will, on the Output JTextArea as I flip through the counter. As well as return the text once I flip backwards through the counter. Is this even possible? I have looked through multiple links online that describe Clipboard usage, but none of the examples that I have come across give a solid understanding how to do this.

Please see code below:

*Note I have left out unimportant elements that I already know work! Thanks!

This is called at the top of my Java file:

 private Clipboard clipbd = getToolkit().getSystemClipboard();
public static final int MAX_COUNT = 10;
//sets maximum for count
public static final int MIN_COUNT = 1;
//sets minimum for count
private int count = 1;
//sets up integer for counter

This is called in the ActionListener:

public void actionPerformed ( ActionEvent event ) {
boolean status = false;

String OutputText1;

if(event.getSource()== CopyButton){
//get text from InputText
OutputText1 = InputText.getText();
//put text into OutputText field
OutputText.setText(OutputText1);
}//end if for CopyButton

if(event.getSource() == NextButton){
    //LabelOutPut.setText("Next");
    if (count < MAX_COUNT) {
        count++;    
    }//end if
    LabelCounter.setText("" + count);
    OutputText.setText("");

}//end if for NextButton

if(event.getSource() == PreviousButton){
    //LabelOutPut.setText("Previous");
    if(count > MIN_COUNT){
        count--;
    }//end if
    LabelCounter.setText("" + count);


}//end if for PreviousButton

Upvotes: 1

Views: 489

Answers (2)

Java Drinker
Java Drinker

Reputation: 3167

You only need the SystemClipboard if you want to get copied/pasted data from places outside your program. If you just have to copy between 2 places in your own program, and you need history etc... just use a variable in your code (string, or list of strings, or whatever) and just update this when they click the button. Camickr mentions the same as well...

Upvotes: 1

camickr
camickr

Reputation: 324118

Why would you use a Clipboard to hold text. Just use a String and the data is in the control of your program. I don't see any reason to complicate your processing.

Also, follow standard Java naming conventions. Varible names should NOT start with an upper cased character.

LabelCounter ==> labelCounter

Upvotes: 5

Related Questions