所以我基本上有两种方法可以运行,但我想要一个JButton我已经做过两次。
我基本上有一个GUI。我有手机,MP3和小工具类。我遇到麻烦的是Shop for the Gadget,在那里制作GUI。它们包含按钮。
我想运行一个方法来拨打电话,但我不知道该怎么做。我一直收到Cast错误。我还必须在行中插入'0',因为我的方法需要一个int。有没有办法让它从名为“持续时间”的GUI文本框中获取持续时间?
所以我的商店代码在这里:
public void makeCall()
{
int index = 0;
Gadget Gadgets = GadgetList.get(index);
if (index!= -1)
{
Mobile mobile = (Mobile) GadgetList.get(index);
mobile.makePhoneCall();
mobile.insertDuration(0);
}
else if(Gadgets instanceof Mobile)
{
Mobile mobile = (Mobile) Gadgets;
}
else
{
System.out.println("This not a mobile phone");
}
}
My Mobile Phone类有我要运行的方法:
public void makePhoneCall()
{
if(credit == 0)
System.out.println("Insert more than 0 credit to make a phone call!");
else {
if(credit >= duration) {
System.out.println("The phone number " + number + " has been dialed and is being called for " + duration + " minutes");
credit = credit - duration;
duration = 0;
}
else {
if(credit < duration)
System.out.println("You do not have enough credit to make a phone call! Your credit is " + credit + " pounds");
}
帮助我将了解其余工作的概念!非常感谢我得到的任何帮助。