Topic: [求助]这个程序编译出错了 |
Print this page |
1.[求助]这个程序编译出错了 | Copy to clipboard |
Posted by: mitnickcbc Posted on: 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 大虾帮忙! |
2.Re:[求助]这个程序编译出错了 [Re: mitnickcbc] | Copy to clipboard |
Posted by: Biubiu Posted on: 2002-12-13 21:17 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) {} Replace ActionEvent with WindowEvent. Remember to use adater in contrary to listener. |
3.Re:[求助]这个程序编译出错了 [Re: mitnickcbc] | Copy to clipboard |
Posted by: Biubiu Posted on: 2002-12-13 21:21 By the way, this program is not for j2se1.4. If you compile this class, you should add this method to make j2se1.4 happy. public void windowClosing(WindowEvent e) {} |
4.Re:[求助]这个程序编译出错了 [Re: mitnickcbc] | Copy to clipboard |
Posted by: mitnickcbc Posted on: 2002-12-13 21:59 对了,谢谢! |
5.Re:[求助]这个程序编译出错了 [Re: mitnickcbc] | Copy to clipboard |
Posted by: archonLing Posted on: 2002-12-17 14:13 There is another way to do it. You could utilize the abstract class java.awt.event.WindowAdapter to save you some typing . just replace your "WindowListener" with "extends java.awt.event.WindowAdapter" then, you don't have to include all the blank methods for WindowListener interface. Just my 2 cents. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |