自己写的计算器,输出栏无法显示,求大神
package stu.view;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.TextField;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.JTextComponent;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class edu extends JFrame {
private JFrame frame;
private final TextField textResult = new TextField();
private JPanel contentPane;
private JTextField textField;
protected Component operateSub;
protected Component operateAdd;
protected Component operateRes;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
edu frame = new edu();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public edu() {
initialize();
}
private void initialize() {
// TODO 自动生成的方法存根
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(10, 10, 401, 28);
contentPane.add(textField);
textField.setColumns(10);
JButton button_1 = new JButton("1");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(1);
}
});
button_1.setBounds(10, 60, 93, 23);
contentPane.add(button_1);
JButton button_2 = new JButton("2");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(2);
}
});
button_2.setBounds(150, 60, 93, 23);
contentPane.add(button_2);
JButton button_3 = new JButton("3");
button_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(3);
}
});
button_3.setBounds(282, 60, 93, 23);
contentPane.add(button_3);
JButton button_4 = new JButton("4");
button_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(4);
}
});
button_4.setBounds(10, 120, 93, 23);
contentPane.add(button_4);
JButton button_5 = new JButton("5");
button_5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(5);
}
});
button_5.setBounds(150, 120, 93, 23);
contentPane.add(button_5);
JButton button_6 = new JButton("6");
button_6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(6);
}
});
button_6.setBounds(282, 120, 93, 23);
contentPane.add(button_6);
JButton button_7 = new JButton("7");
button_7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(7);
}
});
button_7.setBounds(10, 172, 93, 23);
contentPane.add(button_7);
JButton button_8 = new JButton("8");
button_8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(8);
}
});
button_8.setBounds(150, 172, 93, 23);
contentPane.add(button_8);
JButton button_9 = new JButton("9");
button_9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
inputProc(9);
}
});
button_9.setBounds(282, 172, 93, 23);
contentPane.add(button_9);
JButton button_10 = new JButton("+");
button_10.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
contentPane.add(operateAdd);
}
});
button_10.setBounds(10, 229, 93, 23);
contentPane.add(button_10);
JButton button_12 = new JButton("=");
button_12.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
contentPane.add(operateRes);
}
});
button_12.setBounds(282, 229, 93, 23);
contentPane.add(button_12);
JButton button_11 = new JButton("-");
button_11.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
contentPane.add(operateSub);
}
});
button_11.setBounds(150, 229, 93, 23);
contentPane.add(button_11);
}
protected void inputProc(int i) {
// TODO 自动生成的方法存根
String newNum = String.valueOf(i);
JTextComponent textResult = null;
String strOut = textResult.getText();
strOut += newNum;
textResult.setText(strOut);
}
}