dimanche 1 mars 2015

Want my JButton to return a previous area of text



I am trying to create a GUI that gives you hints when the program is opened. I am not sure how I am going to be able to add my text and then create buttons that allow me to go to the next text or return to the previous. I am not sure what type of actionListener I should use for that.



import java.awt.*;
import javax.swing.*;


public class HelpfulHints extends JFrame{

private JTextArea area; //This is my textarea to display hints
private JPanel panel;
private JButton close, previous, next; //Three buttons to operate program

public HelpfulHints(){

super("Tip of the Day");
setLayout(new BorderLayout());

panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.CENTER));

//Create first button
close= new JButton("Close");
add(close);

//Create second button
previous = new JButton("Previous");
add(previous);

//Create third button
next = new JButton("Next");
add(next);

//Add buttons to panel
panel.add(close);
panel.add(previous);
panel.add(next);

//Keep buttons to south of panel
add(panel, BorderLayout.SOUTH);

//Create ButtonHandler for button event handling
ButtonHandler handler = new ButtonHandler();
close.addActionListener(handler);
previous.addActionListener(handler);
next.addActionListener(handler);

//Create the helpful hint area on the screen
area = new JTextArea();
area.setEditable(true);
area.setLayout(new FlowLayout(FlowLayout.CENTER));

add(area, BorderLayout.CENTER);

setVisible(true);

}

//Inner class for button event handling
private class ButtonHandler implements ActionListener{

//handle Button event
@Override
public void actionPerformed(ActionEvent e){


}
}
}



Aucun commentaire:

Enregistrer un commentaire