Java Gui 設計模式中的事件監聽

來源:互聯網
上載者:User

標籤:selected   ext   另一個   orm   一個   儲存格   set   cte   mouse   

  • 按鈕點擊監聽

  通過點擊按鈕觸發監聽事件

 1         button_20 = new JButton("20");                        //建立按鈕的對象button_20 2         button_20.addActionListener(new ActionListener() {    //添加按鈕監聽事件 3             public void actionPerformed(ActionEvent e) {     4                 if(textField_6.getText().equals("")){       5                     textField_6.setText("20");         //為目標文字框新增內容 6                 }else{ 7                     int sum = Integer.parseInt(textField_6.getText())+20; 8                     textField_6.setText(String.valueOf(sum)); 9                 }10             }11         });

  

  • 滑鼠點擊監聽

  通過點擊滑鼠左鍵觸發監聽事件

  

       comboBox.addMouseListener(new MouseAdapter(){//為我們的元素添加滑鼠監聽事件            public void mouseClicked(MouseEvent e) {//滑鼠左鍵點擊後(目標表格)                           int r= table_2.getSelectedRow();             //獲得儲存格所在的行                 int c= table_2.getSelectedColumn();                    //獲得儲存格所在的列                 Object value= table_2.getValueAt(r, c);              //得到點擊儲存格的值                      int a = Integer.parseInt(String.valueOf(table_2.getValueAt(r, 3)));           int b = Integer.parseInt(String.valueOf(table_2.getValueAt(r, 2)));           int res = a * b;//         int a = (int)table_2.getValueAt(r, 3)*(int)table_2.getValueAt(r, 2);           table_2.setValueAt(res, r, 4);        //將我們所需要的功能實現(給同行不同列的另一個儲存格修改參數)                                 System.out.println(info);            }        });                                 

 

Java Gui 設計模式中的事件監聽

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.