本人大二学生一枚。求java技术交流群,要平时比较活跃一点的。各位前辈分享一下,谢谢
另外老师让写一个计算器的程序,只要界面不需要实现功能,帮忙看看哪出错了呢,谢~~~~~~~
package jisuanqi;
import java.awt.BorderLayout;
import java.awt.GridLayout;
//import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Calculater extends JFrame {
Calculater(){
JTextField jtf=new JTextField(30);
add(BorderLayout.NORTH,jtf);
JPanel pl=new JPanel();
pl.setLayout(new GridLayout(4,4));
JButton[] j1=new JButton[16];
String[] operatorValue={"+","-","*","/"};
for(int i=0;i<11;i++){
j1[i]=new JButton(""+(char)('0'+i));
pl.add(j1[i]);
}
for(int i=10;i<j1.length;i++){
j1[i]=new JButton(operatorValue[i-10]);
pl.add(j1[i]);
}
add(BorderLayout.CENTER,pl);
setSize(400,400);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new Calculater();
}
}
------解决方案--------------------------------------------------------
for (int i = 16; i < j1.length; i++) {
j1[i] = new JButton(operatorValue[i - 16]);
pl.add(j1[i]);
}