java - 尝试导入我自己的包

标签 java import

package mainClasses;
    /*
     * Frame Info and all that ****,
     * mainFrame is the actual frame itself
     * it will refer to MainC.java a lot Main class = Main Class
     */
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import JavaGame.src.resources.*; //Problem Code
    import javax.swing.JButton;
    import javax.swing.JFrame;


    public class mainFrame extends JFrame {


private static final long serialVersionUID = 1L;

public mainFrame() {
    JButton playButton = new JButton();
    JButton infoButton = new JButton();
    JButton exitButton = new JButton();
    int x = 300, y = 300;
    setSize(x, y);
    setVisible(true);
    setLayout(new FlowLayout());
    setTitle("Kingdom Raider");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    /*Buttons and Properties*/

     playButton.setBounds(x, y, 200, 100);
     playButton.setText("Play!");
    add(playButton);

     infoButton.setBounds(x, y, 200, 100);
     infoButton.setText("Information");
    add(infoButton);

     exitButton.setBounds(x, y, 200, 100);
     exitButton.setText("Exit");
    add(exitButton);
            /* Add image here */

}

public void Painting (Graphics g) {
    //Me.
}
   }

我正在创建游戏,但遇到了导入问题。 如您所见,我想导入 JavaGame.src.resources,因为我正在尝试导入 img。 这是我的目录的样子:

enter image description here

我不需要知道 resourcesmanager.java 上的代码目前是空白的。 所以基本上,这里的这个类在 mainClasses 包中,但我想访问资源包。给了什么?

最佳答案

你的包名是resources,所以这样写:

import resources.*; // No-Problem Code

目录结构的其余部分是特定于 Eclipse 的,与 Java 类路径没有任何关系

关于java - 尝试导入我自己的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10283265/

相关文章:

java - Swing 中的对齐

java - 在java中将 boolean 对象转换为字符串的最佳方法

javascript - 什么会导出 JavaScript/Node.JS 文件?

android - org.apache.http 导入在更新到 Android M 后停止工作

java - Android 线程顺序/ontouch webview

java - 字符串[]数组错误

java - 交换字符串中的两个字母

sql-server - 将数据导入 MS SQL 数据库

Excel - 每天从在线 xls 文件导入数据

php - 避免\r\n\on mysql 导入