程序抛异常,菜鸟无法解决,求教
import java.awt.*;
import java.awt.event.*;
public class Calculator {
public static void main(String[] args){
new Calculator();
}
TextField [] tf = {new TextField(""),new TextField(""),new TextField("")};
int i1;
int i2;
Calculator(){
Frame f = new Frame("calculator");
Panel p1 = new Panel();
Panel p2 = new Panel();
Label [] l = {new Label("number"),new Label("number"),new Label("result")};
Button [] b = {new Button("+"),new Button("-"),new Button("*"),new Button("/")};
p1.setBackground(Color.green);
p2.setBackground(Color.cyan);
for(int i = 0;i<l.length;i++){
p1.add(l[i]);
p1.add(tf[i]);
}
for(int i = 0;i<b.length;i++){
p2.add(b[i]);
}
f.setSize(600,400);
f.setLayout(new GridLayout(2,1));
f.setBackground(Color.yellow);
f.setVisible(true);
f.add(p1);
f.add(p2);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
change(tf[0],tf[1]);
b[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1+i2));
}
});
b[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1-i2));
}
});
b[2].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1*i2));
}
});
b[3].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1/i2));
}
});
}
public void change(TextField t1,TextField t2){
String s1 = t1.getText();
String s2 = t2.getText();
i1 = Integer.parseInt(s1);
i2 = Integer.parseInt(s2);
}
}
import java.awt.event.*;
public class Calculator {
public static void main(String[] args){
new Calculator();
}
TextField [] tf = {new TextField(""),new TextField(""),new TextField("")};
int i1;
int i2;
Calculator(){
Frame f = new Frame("calculator");
Panel p1 = new Panel();
Panel p2 = new Panel();
Label [] l = {new Label("number"),new Label("number"),new Label("result")};
Button [] b = {new Button("+"),new Button("-"),new Button("*"),new Button("/")};
p1.setBackground(Color.green);
p2.setBackground(Color.cyan);
for(int i = 0;i<l.length;i++){
p1.add(l[i]);
p1.add(tf[i]);
}
for(int i = 0;i<b.length;i++){
p2.add(b[i]);
}
f.setSize(600,400);
f.setLayout(new GridLayout(2,1));
f.setBackground(Color.yellow);
f.setVisible(true);
f.add(p1);
f.add(p2);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
change(tf[0],tf[1]);
b[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1+i2));
}
});
b[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1-i2));
}
});
b[2].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1*i2));
}
});
b[3].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tf[2].setText(String.valueOf(i1/i2));
}
});
}
public void change(TextField t1,TextField t2){
String s1 = t1.getText();
String s2 = t2.getText();
i1 = Integer.parseInt(s1);
i2 = Integer.parseInt(s2);
}
}
...全文
相关推荐
java菜鸟教程_JAVA菜鸟教程_
同时,理解异常处理机制也是必不可少的,Java通过try-catch-finally语句块来捕获和处理运行时错误,确保程序的健壮性。
菜鸟关于C++异常的一些思考
- 在函数声明中,应该明确指出可能抛出的异常类型和原因,以便调用者能做好适当的准备。2. 捕获异常: - 捕获异常的时机应当是代码能够有效地解决问题的时候。
菜鸟电子面单接口+js云打印+C#云打印.zip
该项目实现了菜鸟电子面单接口与JS、C#云打印功能的集成,包含通用工具类、请求响应契约、文件上传处理及自定义异常机制。核心功能涵盖日期格式化、API请求标准化、多文件上传支持等,适用于物流电子面单自动
天猫宝贝入驻菜鸟注意事项
- **异常处理**:对于无法由菜鸟处理的特殊订单,商家应及时跟进处理。- **技术支持**:遇到技术问题时,应联系E店宝或菜鸟的技术支持团队寻求帮助。
菜鸟驿站包裹管理系统.zip
通过学习和分析这个系统,不仅可以加深对C语言的理解,还能了解到如何运用编程解决实际问题,提升自身的编程技能和项目经验。


非技术区
