mitnickcbc
发贴: 165
积分: 60
|
于 2002-12-13 19:57
import java.awt.*; import java.awt.event.*;
public class StickyPad implements ActionListener, WindowListener { private Frame frm; private TextArea noteTA, responseTA; private Button submitBtn, leaveBtn, returnBtn; 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 southPnl = new Panel(); southPnl.setLayout(new FlowLayout()); submitBtn = new Button("Submit"); southPnl.add(submitBtn); submitBtn.addActionListener(this); submitBtn.setEnabled(false); leaveBtn = new Button("Leave"); southPnl.add(leaveBtn); leaveBtn.addActionListener(this); returnBtn = new Button("Return"); southPnl.add(returnBtn); returnBtn.addActionListener(this); returnBtn.setEnabled(false); frm.add(centerPnl, BorderLayout.CENTER); frm.add(southPnl, BorderLayout.SOUTH); frm.setSize(500, 420); frm.show(); frm.addWindowListener(this); }//constructor public void windowClosing(ActionEvent e) { System.exit(0); } public void windowOpened(ActionEvent e) {} public void windowClosed(ActionEvent e) {} public void windowIconified(ActionEvent e) {} public void windowDeiconified(ActionEvent e) {} public void windowActivated(ActionEvent e) {} public void windowDeactivated(ActionEvent 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(); }//main }//class StickyPad
出错信息: C:\j2sdk1.4.1_01\myprogram\StickyPad.java:4: StickyPad should be declared abstract; it does not define windowOpened(java.awt.event.WindowEvent) in StickyPad public class StickyPad implements ActionListener, WindowListener ^ 1 error
大虾帮忙!
|