import java.awt.*; import java.awt.event.*; class StickyPad implements ActionListener, WindowListener { private Frame frm; private TextArea noteTA, responseTA; private Button leaveBtn, returnBtn, submitBtn; private String savedMessages; public StickyPad() { savedMessages = ""; frm = new Frame("Sticky Pad"); Panel centerPnl = new Panel(); centerPnl.setLayout(new FlowLayout()); noteTA = new TextArea(6,40); //set the color of the text area to yellow: noteTA.setBackground(Color.yellow); //set the font of the text area to a large 20 point font noteTA.setFont(new Font("Dialog", Font.PLAIN, 20)); centerPnl.add(noteTA); responseTA = new TextArea(6,40); //set the color of the text area to green: responseTA.setBackground(Color.green); //set the font of the text area to a large 20 point font responseTA.setFont(new Font("Dialog", Font.PLAIN, 20)); centerPnl.add(responseTA); Panel southernPnl = new Panel(); southernPnl.setLayout(new FlowLayout()); submitBtn = new Button("Submit"); southernPnl.add(submitBtn); submitBtn.addActionListener(this); submitBtn.setEnabled(false); leaveBtn = new Button("Leave"); southernPnl.add(leaveBtn); leaveBtn.addActionListener(this); returnBtn = new Button("Return"); southernPnl.add(returnBtn); returnBtn.addActionListener(this); returnBtn.setEnabled(false); frm.add(centerPnl, BorderLayout.CENTER); frm.add(southernPnl, BorderLayout.SOUTH); frm.setSize(500, 420); frm.show(); frm.addWindowListener(this); } public void windowClosing(WindowEvent e) { System.exit(0); } public void windowOpened(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("Leave")) { //Disable the outgoing text area so it can //not be changed and enable the response text //area and buttons noteTA.setEnabled(false); leaveBtn.setEnabled(false); returnBtn.setEnabled(true); submitBtn.setEnabled(true); } else if (e.getActionCommand().equals("Submit")) { //Save the message and clear the response text //area for the next visitor savedMessages += responseTA.getText() + "\n"; responseTA.setText(""); } else if (e.getActionCommand().equals("Return")) { //Disable the response text area and buttons and //display the save messages responseTA.setText(savedMessages); submitBtn.setEnabled(false); returnBtn.setEnabled(false); } } public static void main(String args[]) { StickyPad sp = new StickyPad(); } }