所以我創建一個圖形用戶界面,執行添加,子,乘法和除法,但我需要組件,構造函數,過程&顯示應該在子類中我的問題是我無法獲得我的答案按鈕工作。actionperformed在主類
子類:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class basic_arithmetic extends JFrame{
public JPanel panel1, panel2;
public JRadioButton sum, dif, pro, quo;
public JTextField n1, n2;
public JButton answer, clear;
public ButtonGroup button;
public comBHandler cbHandler;
public exBHandler ebHandler;
public static final int WID=400;
public static final int HGT=125;
public basic_arithmetic(){
answer = new JButton("Answer");
cbHandler = new comBHandler();
answer.addActionListener(cbHandler);
clear = new JButton("Clear");
ebHandler = new exBHandler();
clear.addActionListener(ebHandler);
public class comBHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
}
}
public class exBHandler implements ActionListener{
public exBHandler() {
}
public void actionPerformed(ActionEvent event){
n1.setText(null);
n2.setText(null);
}
public void setButtonActionListener(ActionListener al) {
answer.addActionListener(al);
}
}
}
主類:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class basic_arithmetic_caller{
public static void main(String[] args){
basic_arithmetic new = new basic_arithmetic();
//if statement for answer button here
}
}
*「..無法讓我的答案按鈕正常工作」中看到更多關於事件處理/處理程序的信息。*可能它正在進行罷工。 「工作」是什麼意思? –
沒有在ActionListener中爲答覆按鈕實現。 ''comBHandler'具有空的'actionPerformed()'方法。 – Braj
我需要我的答案按鈕才能顯示答案(請參閱主類) – user3857974