JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 inner class 的地方被指出錯誤@@a?
X_Killer





發文: 111
積分: 0
於 2010-05-20 15:49 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
搞半天也不知道問題出在那裡,快昏哩= =
我要弄二個按鈕,
一個是button,建立在南邊,按下去會改變中間drawPanel的圖
一個是buttonRight,建立在右邊,按下去會改變左邊的labshow的Text
都建立在同一個frame
以下是程式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class start{
  public static void main(String[] args){
    buttonf bon=new buttonf();
    bon.go();  
  }
  
 
}
 
class buttonf{
  
  draw3 drawPanel;
  JFrame frame;    
  JLabel labshow;  
  
  public void go(){
  
 
  frame=new JFrame();
  
  drawPanel=new draw3();  
  JButton button=new JButton("click me");
  JButton buttonRight=new JButton("change txt");
  labshow=new JLabel("i not change");  
  
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  
  frame.getContentPane().add(BorderLayout.SOUTH,button);
  frame.getContentPane().add(BorderLayout.CENTER,drawPanel);  
  frame.getContentPane().add(BorderLayout.EAST,buttonRight);
  frame.getContentPane().add(BorderLayout.WEST,labshow);  
 
  button.addActionListener(new changedraw());
  buttonRight.addActionListener(new changetxt());
  
  frame.setSize(300,300);
  frame.setVisible(true);
  
  }
  
 
          /*下面這二個innerclass被程式說有錯…錯誤訊息如下
C:\javatest\start.java:48: buttonf.changedraw is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    class changedraw implements ActionListener{
    ^
*/
 
   
 
  class changedraw implements ActionListener{
    public void actionPerform(ActionEvent event){
      
      drawPanel.repaint();
      //frame.repaint();  
    }
  }
  
/*這個inner 的錯誤如下
C:\javatest\start.java:56: buttonf.changetxt is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    class changetxt implements ActionListener{
    ^
       */
  class changetxt implements ActionListener{
    public void actionPerform(ActionEvent event){
 
      labshow.setText("i changed!!");
    
    }      
  }
 
}//end of class
 
class draw3 extends JPanel{
 
  public void paintComponent(Graphics g){
 
    g.fillRect(0,0,this.getWidth(),this.getHeight());
 
    int red=(int)(Math.random()*255);
    int blue=(int)(Math.random()*255);
    int green=(int)(Math.random()*255);
    Color randomColor=new Color(red,green,blue);
    g.setColor(randomColor);
    g.fillOval(70,70,100,100);
  }
}
 
  
 


真的不知道是啥錯,請賜教


X_Killer edited on 2010-05-20 15:52
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
887 inner class 的地方被指出錯誤@@a? X_Killer 2470 2010-05-20 15:49
799 Re:inner class 的地方被指出錯誤@@a? mylee 112 2010-05-20 16:07
858 Re:inner class 的地方被指出錯誤@@a? X_Killer 5 2010-05-20 16:14
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8