Java 在子类中强制转换2个单独的方法

Java 在子类中强制转换2个单独的方法,java,casting,Java,Casting,所以我基本上有两个方法要运行,但我想要一个JButton,我已经做了这两个 我基本上有一个GUI。我有一门手机、MP3和小工具课程。我遇到的麻烦是一家小工具店,GUI就是在那里制造的。它们包含按钮 我想运行一个方法来进行调用,但我不确定如何运行。我一直在犯演员错误。我还必须在行中插入“0”,因为我的方法需要一个int。是否有一种方法允许它从名为“duration”的GUI文本框中获取持续时间 因此,我的店铺代码如下: public void makeCall() { int ind

所以我基本上有两个方法要运行,但我想要一个JButton,我已经做了这两个

我基本上有一个GUI。我有一门手机、MP3和小工具课程。我遇到的麻烦是一家小工具店,GUI就是在那里制造的。它们包含按钮

我想运行一个方法来进行调用,但我不确定如何运行。我一直在犯演员错误。我还必须在行中插入“0”,因为我的方法需要一个int。是否有一种方法允许它从名为“duration”的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");
}

}
我的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");
}
public void makePhoneCall()
{
如果(信用==0)
System.out.println(“插入超过0的信用卡拨打电话!”);
否则{
如果(信用>=期限){
System.out.println(“电话号码“+number+”已拨出,正在通话“+duration+”分钟”);
信用=信用-期限;
持续时间=0;
}
否则{
如果(信用<期限)
System.out.println(“您没有足够的信用卡打电话!您的信用卡是“+信用卡+”英镑”);
}

这方面的帮助将使我能够理解其余工作的概念!非常感谢我得到的任何帮助。

您得到的具体错误是什么,具体发生在哪里?寻求调试帮助的问题(“为什么此代码不起作用?”)必须包括所需的行为、特定的问题或错误,以及在问题本身中重现该问题所需的最短代码。没有明确问题陈述的问题对其他读者来说没有用处。请参阅:如何创建问题。您应该遵守Java命名约定:变量名称不得以大写字母开头,除非常量;条件语句和重复语句,如
if
while
应该使用大括号。@Makoto我现在没有收到任何错误。但我只想知道如何在一个按钮中实际使用两个方法。我想从我的移动类中运行两个方法,并从GUI中的JTextField中获取文本。