简体   繁体   English

Java包。 每个文件不能使用多个软件包

[英]Java Package. Cannot use more than one package per file

I am a beginner programmer for the FRC team 1310.I use Java in the Netbeans IDE. 我是FRC团队1310的初级程序员。我在Netbeans IDE中使用Java。 I was trying to incorporate certain classes. 我试图合并某些类。 There is a package for FRC that is called edu.wpi.first.wpilibj.templates , it allows us to use speed controllers and sensors for our robot. FRC有一个名为edu.wpi.first.wpilibj.templates ,它使我们可以为机器人使用速度控制器和传感器。 I want to import java and javax classes along with the edu.wpi.first.wpilibj.templates package on the same file. 我想在同一文件上导入javajavax类以及edu.wpi.first.wpilibj.templates包。 i need this for Japplets to make it interactive. 我需要Japplets使其具有交互性。 I also need this for the URL function as I need to extract images from an AXIS camera. 我也需要URL功能,因为我需要从AXIS摄像机中提取图像。

How do I do this? 我该怎么做呢?

Help is really needed. 确实需要帮助。

Use import instead of package . 使用import而不是package My guess is you have multiple lines that start with the word package at the top of your file. 我的猜测是,您有多行以文件顶部的单词package开头。 To use classes from another package you import them. 要使用另一个包中的类,请import它们。

package com.myPackage.whatever;

import java.io.*;
import javax.whatever.you.Want;
import edu.wpi.first.wpilibj.templates.*;

Your question doesn't really make sense. 您的问题真的没有道理。

To import multiple packages just put multiple import statements at the top of your file... 要导入多个软件包,只需在文件顶部放置多个import语句即可。

If you mean you need to INHERIT multiple parent classes from one class then you can't do that. 如果您的意思是需要从一个类继承多个父类,则不能这样做。 Java only supports single inheritance. Java仅支持单一继承。 You need to use composition (create multiple classes, each inheriting one of the things you want, then have one single class containing all those). 您需要使用组合(创建多个类,每个类都继承您想要的事物之一,然后只有一个包含所有这些的类)。

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

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