[問題] 新手的發問 編譯階段出了問題

看板java作者 (行在自我上)時間14年前 (2011/04/26 20:57), 編輯推噓1(107)
留言8則, 4人參與, 最新討論串1/1
TwoButtons.java:49: TwoButtons.ColorListener is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event .ActionListener class ColorListener implements ActionListener 照課本解答KEY出來的程式 編譯卻碰到了這個過不去的問題.... 翻書很久找不到解決方法 只好來這邊求高人指點了 orz 程式碼如下 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TwoButtons { JFrame frame; JLabel label; public static void main (String[] args) { TwoButtons gui = new TwoButtons(); gui.go(); } public void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton labelButton = new JButton("Change Label"); labelButton.addActionListener( new LabelListener() ); JButton colorButton = new JButton("Change Circle"); colorButton.addActionListener( new ColorListener() ); label = new JLabel("I`m a label"); MyDrawPanel drawPanel = new MyDrawPanel(); frame.getContentPane().add(BorderLayout.SOUTH, colorButton); frame.getContentPane().add(BorderLayout.CENTER, drawPanel); frame.getContentPane().add(BorderLayout.EAST, labelButton); frame.getContentPane().add(BorderLayout.WEST, label); frame.setSize(300, 300); frame.setVisible(true); } class LabelListener implements ActionListener { public void actionPerformed(ActionEvent event) { label.setText("Ouch!"); } } class ColorListener implements ActionListener { public void actionPreformed(ActionEvent event) { frame.repaint(); } } } class MyDrawPanel extends JPanel { public void paintComponent (Graphics g) { g.setColor(Color.orange); g.fillRect(20,50,100,100); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.90.63

04/26 20:59, , 1F
不是書印錯就是你打錯,所以請把程式排版好貼上來。
04/26 20:59, 1F
※ 編輯: FUFrench 來自: 118.160.90.63 (04/26 21:16)

04/26 21:29, , 2F
actionPreformed actionPerformed 字打錯
04/26 21:29, 2F

04/26 21:30, , 3F
在ColorListener這個class裡面 錯誤訊息裡有寫了
04/26 21:30, 3F

04/26 21:33, , 4F
好丟人 為這種錯誤搞了半天 我ㄧ直以為 繼承出了問題...
04/26 21:33, 4F

04/26 21:34, , 5F
以後我會多加注意 謝謝各位指正 : )
04/26 21:34, 5F

04/26 21:37, , 6F
你的程式裡面沒有實作 ColorListener 這個類別
04/26 21:37, 6F

04/26 21:39, , 7F
抱歉,看錯
04/26 21:39, 7F

04/26 21:42, , 8F
這個不丟人啦,我在這個 method 上也錯過好幾次 :p
04/26 21:42, 8F
文章代碼(AID): #1Dji5LW1 (java)