简体   繁体   English

实现jframe类的接口

[英]implementing an interface to jframe class

Been creating a bunch of JFrame classes using the appropriate wizard. 使用适当的向导创建了一堆JFrame类。

Created an interface and decided to make the JFrame classes implement this interface. 创建一个接口并决定使JFrame类实现此接口。 Usually, when adding an implements CaptureObserver statement to a class, the class declaration is underlined in red, the error is saying 通常,在向类中添加一个implements CaptureObserver语句时,该类声明用红色下划线表示,错误是

System.Bill.Operation.BillForm is not abstract and does not override abstract method onError(com.lti.civil.CaptureStream,com.lti.civil.CaptureException) in com.lti.civil.CaptureObserver System.Bill.Operation.BillForm不是抽象的,并且不会覆盖com.lti.civil.CaptureObserver中的抽象方法onError(com.lti.civil.CaptureStream,com.lti.civil.CaptureException)

How can I resolve this? 我该如何解决?

What that error means is that your class implements the interface but it does not contain all of the methods defined by that interface. 该错误的意思是您的类实现了该接口,但不包含该接口定义的所有方法。 Solution: give the class the missing methods. 解决方案:给类缺少的方法。 In your case, the error is telling you exactly what method of CaptureObserver that you're missing, onError(com.lti.civil.CaptureStream,com.lti.civil.CaptureException) . 就您而言,错误是告诉您确切缺少的CaptureObserver方法onError(com.lti.civil.CaptureStream,com.lti.civil.CaptureException)


A few unrelated issues and suggestions: 一些不相​​关的问题和建议:

been creating a bunch of JFrame classes using the appropriate wizard. 使用适当的向导创建了一堆JFrame类。

If you're new to Swing, avoid using "wizards" to create your GUI's, but instead try making them from hand. 如果您不熟悉Swing,请避免使用“向导”创建GUI,而应尝试手工制作。 It will give you a much better insight into using the library. 它将使您对使用该库有更好的了解。 Also, strive to create JPanels rather than JFrames as this will give your GUI classes much greater flexibility. 另外,请努力创建JPanels而不是JFrames,因为这将为您的GUI类提供更大的灵活性。 With a JPanel, you can put it into a JFrame, or if desired, a JDialog, a JOptionPane, a JApplet, another JPanel, a "view" of a CardLayout, etc... 使用JPanel,您可以将其放入JFrame,或者根据需要放入JDialog,JOptionPane,JApplet,另一个JPanel,CardLayout的“视图”等。

Created an interface and decided to make the JFrame classes implement this interface. 创建一个接口并决定使JFrame类实现此接口。

It's usually best to avoid having your GUI/view classes implementing listener interfaces as this gives one class too much disparate responsibility. 通常最好避免让GUI / view类实现侦听器接口,因为这会使一个类承担太多不同的责任。 Perhaps this should be an anonymous inner class or part of a separate conctrol class. 也许这应该是匿名的内部类或单独的控制类的一部分。

Usually, when adding an "implements CaptureObserver" statement to a class, the class declaration is underlined in red, the error is saying "System.Bill.Operation.BillForm is not abstract and does not override abstract method onError(com.lti.civil.CaptureStream,com.lti.civil.CaptureException) in com.lti.civil.CaptureObserver" how can i resolve it. 通常,在向类添加“ implements CaptureObserver”语句时,类声明用红色下划线标记,错误提示“ System.Bill.Operation.BillForm不是抽象的,并且不会覆盖抽象方法onError(com.lti.civil com.lti.civil.CaptureObserver中的“ .CaptureStream,com.lti.civil.CaptureException)”,我该如何解决。 pls help... 请帮助...

This we've discussed above. 我们上面已经讨论过了。

You need to implement the methods defined in your interface. 您需要实现接口中定义的方法。

If you have this: 如果您有这个:

public interface CaptureObserver {
    public void onError(CaptureStream stream, CaptureException exc);
}

Then you need this: 然后,您需要这样做:

public class BillForm extends JFrame implements CaptureObserver {
    // Don't forget your constructor
    public BillForm() {
        super();
    }

    @Override
    public void onError(CaptureStream stream, CaptureException exc) {
         // Code
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM