level 4
为啥我编的程序在别人电脑上可以运行,在自己电脑上时,JButton按钮没反应,可如果是bug在别人电脑上为啥可以跑,没任何问题
2015年10月29日 08点10分
1
level 4
代码
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Cal extends JFrame implements ActionListener {
JButton aadd;
JButton minus;
JButton multiply;
JButton divide;
JTextField numberone;
JTextField numbertwo;
JTextArea answer;
public Cal(){
super("计算器");
Container c=this.getContentPane();
c.setLayout(new GridLayout(4,1));
JPanel row1=new JPanel(new FlowLayout());
JPanel row2=new JPanel(new FlowLayout());
JPanel row3=new JPanel(new FlowLayout());
JLabel one=new JLabel("第一个数");
JLabel two=new JLabel("第二个数");
numberone=new JTextField(8);
numbertwo=new JTextField(8);
aadd=new JButton("+");
minus=new JButton("-");
multiply=new JButton("*");
divide=new JButton("/");
answer=new JTextArea("运算结果;",1,20);
row1.add(one);
row1.add(two);
row2.add(numberone);
row2.add(numbertwo);
row3.add(aadd);
row3.add(minus);
row3.add(multiply);
row3.add(divide);
c.add(row1);
c.add(row2);
c.add(row3);
c.add(answer);
aadd.addActionListener(this);
minus.addActionListener(this);
multiply.addActionListener(this);
divide.addActionListener(this);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300,300);
this.setVisible(true);
}
public static void main(String args[]){
new Cal();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==aadd)
{
addd();
}
if(e.getSource()==minus)
{
minuss();
}
if(e.getSource()==multiply)
{
multiplyy();
}
if(e.getSource()==divide)
{
dividee();
}
}
private void addd(){
float m;
String message1=numberone.getText();
String message2=numbertwo.getText();
float i=Float.parseFloat(message1);
float j=Float.parseFloat(message2);
Jisuan theJisuan=new Jisuan(i,j);
m=theJisuan.Add();
answer.setText("两数的和为:"+m);
}
private void minuss(){
float m;
String message1=numberone.getText();
String message2=numbertwo.getText();
float i=Float.parseFloat(message1);
float j=Float.parseFloat(message2);
Jisuan theJisuan=new Jisuan(i,j);
m=theJisuan.Minus();
answer.setText("两数的差为:"+m);
}
private void dividee(){
String message1=numberone.getText();
String message2=numbertwo.getText();
float i=Float.parseFloat(message1);
float j=Float.parseFloat(message2);
Jisuan theJisuan=new Jisuan(i,j);
float m;
if(j==0) answer.setText("除数不可以为0");
else {
m=theJisuan.Divide();
answer.setText("两数的商为:"+m);
}
}
private void multiplyy(){
float m;
String message1=numberone.getText();
String message2=numbertwo.getText();
float i=Float.parseFloat(message1);
float j=Float.parseFloat(message2);
Jisuan theJisuan=new Jisuan(i,j);
m=theJisuan.Multiply();
answer.setText("两数的积为:"+m);
}
}
2015年10月29日 08点10分
2
level 4
public class Jisuan {
private float firstnumber;
private float secondnumber;
public Jisuan(float firstnumber,float secondnumber){
setFirstnumber(firstnumber);
setSecondnumber(secondnumber);
}
public float getFirstnumber(){
return firstnumber;}
public float getSecondnumber(){
return secondnumber;
}
public void setFirstnumber(float firstnumber){
this.firstnumber=firstnumber;
}
public void setSecondnumber(float secondnumber){
this.secondnumber=secondnumber;
}
public float Add(){
return firstnumber+secondnumber;
}
public float Minus(){
return firstnumber-secondnumber;
}
public float Divide(){
return firstnumber/secondnumber;
}
public float Multiply(){
return firstnumber*secondnumber;
}
}
2015年10月29日 08点10分
3
level 3
是不是软件有问题 你重新下载试试看 我也遇见过这种情况
2015年11月03日 05点11分
6