如何激活Java小程序中的“提交"按钮以总计所有总计并显示更改 [英] How do i activate the submit button in a java applet to add up all totals and display change
本文介绍了如何激活Java小程序中的“提交"按钮以总计所有总计并显示更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个提交按钮sButton;那应该从3个盒子中取出所有总数,如果那个总数大于1,那么应该从1中减去它,其余的应该显示为变化...这就是我所拥有的
Hi ,
I have created a submit button sButton; that should take all totals from 3 boxes and if that total is greater than 1, then it should be subtracted from 1 and the remainder is suppose to be displayed as change...this is what i have
if(evt.getSource()==sButton)
{
change.setText(---'I DON'T KNOW WHAT TO PUT HERE')
selections.setText('Vending....');
}
并在另一个课程中将我拥有的3个总数相加
and in another class to add up the 3 totals i have
public String total5()
{
total5=total+total2+total3+total4;
String blank =new String();
blank=''+total5;
return blank;
}
所以我的问题是我该如何使用total5来比较它是否大于或小于1并在"change.setText()"中显示它是否结束;
so my question is how do i use the total5 to compare if it''s over 1 or less and display if it''s over in the "change.setText( )"; text box?
推荐答案
如果更改total方法以返回数字:
If you change total method to return a number:
double getTotal()
{
return (total+total2+total3+total4);
}
然后可以在事件处理程序中使用它:
You can then use it in your event handler:
if(evt.getSource()==sButton)
{
double total = obj.getTotal();
if (total < 1)
{
change.setText("Not enough");
return;
}
change.setText("Change
" +(总计- 1 ); selections.setText(" ); }
" + (total-1); selections.setText("Vending...."); }
这篇关于如何激活Java小程序中的“提交"按钮以总计所有总计并显示更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文