牧场java源代码 牧场玩法( 四 )


temp=value1;
}
else
{
value2=value2+4;
temp=value2;
}
text.setText(temp);
}
});
final JButton button5=new JButton("5");
c.add(button5);
button5.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+5;
temp=value1;
}
else
{
value2=value2+5;
temp=value2;
}
text.setText(temp);
}
});
final JButton button6=new JButton("6");
c.add(button6);
button6.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+6;
temp=value1;
}
else
{
value2=value2+6;
temp=value2;
}
text.setText(temp);
}
});
final JButton button7=new JButton("7");
c.add(button7);
button7.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+7;
temp=value1;
}
else
{
value2=value2+7;
temp=value2;
}
text.setText(temp);
}
});
final JButton button8=new JButton("8");
c.add(button8);
button8.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+8;
temp=value1;
}
else
{
value2=value2+8;
temp=value2;
}
text.setText(temp);
}
});
final JButton button9=new JButton("9");
c.add(button9);
button9.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+9;
temp=value1;
}
else
{
value2=value2+9;
temp=value2;
}
text.setText(temp);
}
});
final JButton button0=new JButton("0");
c.add(button0);
button0.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
String temp;
if(flag==0)
{
value1=value1+0;
temp=value1;
}
else
{
value2=value2+0;
temp=value2;
}
text.setText(temp);
}
});
final JButton buttonadd=new JButton(" + ");
c.add(buttonadd);
buttonadd.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
fix=1;
flagsum=0;
}
});
final JButton buttonsubtract=new JButton(" - ");
c.add(buttonsubtract);
buttonsubtract.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
fix=2;
flagsum=0;
}
});
final JButton buttoncheng=new JButton(" * ");
c.add(buttoncheng);
buttoncheng.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
fix=3;
flagsum=0;
}
});
final JButton buttonchu=new JButton(" / ");
c.add(buttonchu);
buttonchu.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
flag=1;
flagsum=0;
fix=4;
}
});
final JButton buttonequal=new JButton(" = ");
c.add(buttonequal);
buttonequal.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
double temp1,temp2;
double temp=0;
flagsum=0;
temp1=Double.parseDouble(value1);
temp2=Double.parseDouble(value2);
flag=0;
switch(fix)
{
case 1: temp=temp1+temp2;break;
case 2: temp=temp1-temp2;break;

推荐阅读