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

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 請問有關於setText的問題
heyipomoea8866





發文: 11
積分: 0
於 2013-01-04 18:33 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


如上圖我想寫一個可以統計月薪跟年資來計算你所可領的年終(bouns)的小程式
可是我輸入年終跟年資卻沒辦法顯示最後的總金額
IDE標明的錯誤點我在下列Code有指出
請問是哪裡錯誤了呢?
我把Bouns改成字串或數字都無法顯示...
可以麻煩大大開示嗎

感謝不盡!

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
package Book;
import java.awt.event.*;
import javax.swing.*;
 
class CCsalary extends JFrame implements ActionListener {
    private JTextField txtDollar = new JTextField("0");
    private JTextField txtYears = new JTextField("0");
    private JTextField txtBouns = new JTextField();
    private JButton btnOK = new JButton("確定");
    private JButton btnClear = new JButton("清除");   
      
   
    CCsalary() {
        JLabel lblDollar = new JLabel("輸入底薪(元)");
        lblDollar.setBounds(20, 10, 100, 20);    add(lblDollar);
        JLabel lblYears = new JLabel("輸入年資(元)");
        lblYears.setBounds(20, 30, 100, 20);     add(lblYears);
        txtDollar.setBounds(100, 10, 80, 20);   add(txtDollar);
        txtYears.setBounds(100, 30, 80, 20);    add(txtYears);
        txtBouns.setBounds(20, 100, 200, 20);    add(txtBouns);
        btnOK.setBounds(20, 70, 70, 20);         add(btnOK);
        btnClear.setBounds(100, 70, 70, 20);     add(btnClear);
        txtBouns.setEnabled(false);
        btnOK.addActionListener(this);
        
        
        setTitle("計算員工薪資");       setLayout(null);
        setBounds(100, 100, 200, 200);  setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }                                   
 
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == btnOK) {           
            int dollar , years, bouns;
            
            String stringValue = null;
            years = Integer.parseInt(txtYears.getText());
            dollar = Integer.parseInt(txtDollar.getText());
            if(years>=5){
                bouns = dollar + years + 2000;               
            }else if(years<1){
                bouns = dollar + years;
            }else if(years<2){
                bouns = dollar + years + 500;
            }else if(years<5){
                bouns = dollar + years + 1000;
            }
        }       
        txtBouns.setText("目前每個月薪水為:"+bouns);        //<==問題點
        btnOK.removeActionListener(this);
       // btnClear.addActionListener(this);
    }
}
 
public class NewClass {
    public static void main(String[] args) {
        CCsalary CCsalary = new CCsalary();
    }
}


heyipomoea8866 edited on 2013-01-04 18:38
reply to postreply to post
作者 Re:請問有關於setText的問題 [Re:heyipomoea8866]
chuanchu





發文: 120
積分: 0
於 2013-01-04 18:47 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
注意變數生命期
把code35拉出if區塊


reply to postreply to post
» JWorld@TW »  Java SE 討論區

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8