我希望有一个存储我的图像文件的地方,以便在我的Java项目中使用(一个非常简单的类,只是将图像加载到面板上).我到处寻找,无法找到如何做到这一点.我该怎么做呢?
我尝试将新文件夹添加到项目中,向项目添加新的类文件夹,并向项目添加新的源文件夹.不管我做什么,我总是得到一个IOException
.文件夹总是说它们在构建路径上,所以我不知道该怎么做.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class PracticeFrame extends JFrame{
private static BufferedImage image;
Thread thread;
public PracticeFrame() {
super();
setPreferredSize(new Dimension(640,480));
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main (String[] args) {
PracticeFrame pframe = new PracticeFrame();
try {
image = ImageIO.read(new File("/islands.png"));
} catch (IOException e) {
e.printStackTrace();
}
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将jar文件添加到sbt项目中,但我无法确定将它们存储在何处.sbt文档说"只需将它们放在lib文件夹中,你就好了!",但是不要提供有关实际放置此lib文件夹的位置的任何信息.lib文件夹是否在src下?在src文件夹所在的顶级层次结构中?我真的不确定,也会感激一些帮助.
我正在阅读Akka的一些例子,特别是Jonas Boner的ChatServer示例,我遇到了一些案例msg @ GetChatLog =>.我试图通过搜索akka文档以及关于scala中模式匹配的各种文章来找出@符号的含义,但没有运气.有没有人知道这意味着什么?
我正在尝试使用Scala访问文件io.Source.fromfile
.
我已指定完整路径,但我仍然收到no such directory or file
错误.
这是我的代码的一般版本:
val lines = io.Source.fromFile("~/top/next/source/resources/desiredFile.txt").getLines()
Run Code Online (Sandbox Code Playgroud)
我正在运行Ubuntu,如果这有任何区别.
我试图使用某种绘制方法将精灵图像绘制到我的JPanel子类名为AnimationPanel.我创建了一个Spritesheet类,它可以生成包含工作表中所有精灵的BufferedImage [].在我的AnimationPanel类中,它实现了Runnable,我从AnimationPanel构造函数中实例化的spritesheet中获取BufferedImage [].我希望能够循环遍历此数组并将每个精灵显示到屏幕上.我该怎么做?这是我的AnimationPanel和Spritesheet类.
AnimationPanel
package com.kahl.animation;
import javax.swing.JPanel;
public class AnimationPanel extends JPanel implements Runnable {
//Instance Variables
private Spritesheet sheet;
private int currentFrame;
private Thread animationThread;
private BufferedImage image;
public AnimationPanel(Spritesheet aSheet) {
super();
sheet = aSheet;
setPreferredSize(new Dimension(128,128));
setFocusable(true);
requestFocus();
}
public void run() {
BufferedImage[] frames = sheet.getAllSprites();
currentFrame = 0;
while (true) {
frames[currentFrame].draw(); //some implementation still necessary here
currentFrame++;
if (currentFrame >= frames.length) {
currentFrame = 0;
}
}
}
public void addNotify() {
super.addNotify(); …
Run Code Online (Sandbox Code Playgroud) 我试图用一个按钮更改段落标记的文本,我想测试不同的样式标记将如何影响该更改.我的HTML看起来像这样:
<p id="testParagraph"> This <strong> is </strong> a test </p>
<button id="button">Run Test</button>
Run Code Online (Sandbox Code Playgroud)
在我的js文件中,我正在通过其id抓取该标记,并尝试将其内部html设置为:
var button = document.getElementById("button");
button.onclick = function() {
document.getElementById("testParagraph").innerHtml = "I changed the inner html, but what do I look like?";
}
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时,我没有看到任何变化,我想知道这是否是由于我做错了,或者由于原始段落标签中的强标签而导致更改html时出现问题.
我有这两个函数,都生成一个从开始到结束的范围,其中start和end是整数.它们看起来像这样:
function range(start, end) {
var result = [];
for (var i = start; i <= end; i++) {
result.push(i);
}
return result;
}
console.log(range(1,5));
//Expected output [1, 2, 3, 4, 5]
function functional_range(start, end) {
function functional_range_helper(result, strt, nd) {
if (strt > nd) return [];
if (strt === nd) {
return result;
} else {
return functional_range_helper(result.push(strt), strt + 1, nd);
}
}
return functional_range_helper([], start, end);
}
console.log(functional_range(1,5));
//Expected output [1, 2, 3, 4, 5]
Run Code Online (Sandbox Code Playgroud)
第一个完美运行."TypeError:result.push不是函数"的第二个错误.我不明白为什么会发生这种情况,因为我将一个数组作为辅助函数的第一个参数传递,并使用辅助函数中的正确参数名来引用它.这是一个数组,为什么我会收到此错误?