在模拟器上,我从Google下载了一张图片.我可以在模拟器上找到图像,但我不知道图像的文件位置是什么.要调试我的应用程序,我需要知道该图像的位置.如何获得图像的完整路径?
我有一系列正/负的整数
int[] numbers = new int[10];
numbers[0] = 100;
numbers[1] = -34200;
numbers[2] = 3040;
numbers[3] = 400433;
numbers[4] = 500;
numbers[5] = -100;
numbers[6] = -200;
numbers[7] = 532;
numbers[8] = 6584;
numbers[9] = -945;
Run Code Online (Sandbox Code Playgroud)
现在,我想针对这个数组测试另一个int,并返回最接近int的数字.
例如,如果我使用数字,490
我会从数字中取回第4项500
,这样做的最佳方法是什么?
int myNumber = 490;
int distance = 0;
int idx = 0;
for(int c = 0; c < numbers.length; c++){
int cdistance = numbers[c] - myNumber;
if(cdistance < distance){
idx = c;
distance = cdistance;
}
}
int …
Run Code Online (Sandbox Code Playgroud) 我有一个JPanel
元素,我想添加一个阴影,我怎么能添加一个漂亮的褪色阴影到元素?我是否需要使用外部库或者是否有可以使用的内置库?
例:
如何将BufferedImage转换为ImageIcon?
我找不到任何关于此的文件.
可能重复:
Java全屏模式无法在Ubuntu上运行
我尝试做100%全屏模式,我使用Ubuntu 12.10,左边是侧栏,顶部是菜单.当我运行全屏模式时,它不会掩盖这两个菜单栏,它就在它们旁边:
它应该覆盖左侧菜单栏和顶部黑条.为什么不呢?
package sscce;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
public class Main extends JFrame{
public Main(){
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice myDevice = ge.getDefaultScreenDevice();
this.setUndecorated(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myDevice.setFullScreenWindow(this);
}
public static void main(String[] args){
Main main = new Main();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个Element
,我无法弄清楚如何从中得到HTMLElement
它.
例如:
<a href="">A link</a>
<a href="">Another link</a>
Run Code Online (Sandbox Code Playgroud)
然后我就这样得到它们:
var nodes: NodeListOf<Element> = document.querySelectorAll('a'); // Returns a NodeList of Elements
for (let i = 0; i < nodes.length; i++) {
var node = nodes.item(i);
// How can I get the HTMLElement here?
}
Run Code Online (Sandbox Code Playgroud)
编辑
这是代码:
let nodes: NodeListOf<Element> = document.querySelectorAll('a');
for (let i = 0; nodes[i]; i++) {
let node = nodes[i];
var c = nodes[i].style.backgroundColor = 'red';
}
Run Code Online (Sandbox Code Playgroud) 我正在使用phpExcel,我找不到任何东西来检查是否存在工作表.我想要完成的是这样的事情:
if(!$excel->sheetExists(1)){
$excel->createSheet(1);
$sheet = $excel->setSheet(1);
}
// Do some stuff with the sheet
Run Code Online (Sandbox Code Playgroud)
所以.我的问题:如何检查是否存在工作表?
编辑
这会有用吗?
try{
$sheet = $this->excel->setActiveSheetIndex(1);
}catch(Exception $e){
$excel->createSheet(1);
$sheet = $excel->setActiveSheetIndex(1);
}
Run Code Online (Sandbox Code Playgroud) 我写一个游戏循环,我发现在下面的示例代码在这里.我还研究了其他方法来进行游戏循环,例如本文.我无法让任何那些工作.所以我保留了第一个链接中的那个.
我想知道的是:
Thread.sleep();
在游戏循环中使用吗?这是我目前的代码:
public void run(){
long lastLoopTime = System.nanoTime();
final int TARGET_FPS = 60;
final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;
long lastFpsTime = 0;
while(true){
long now = System.nanoTime();
long updateLength = now - lastLoopTime;
lastLoopTime = now;
double delta = updateLength / ((double)OPTIMAL_TIME);
lastFpsTime += updateLength;
if(lastFpsTime >= 1000000000){
lastFpsTime = 0;
}
this.updateGame(delta);
this.repaint();
try{
Room.gameTime = (lastLoopTime - System.nanoTime() + OPTIMAL_TIME) / 1000000;
System.out.println(Room.gameTime);
Thread.sleep(Room.gameTime);
}catch(Exception …
Run Code Online (Sandbox Code Playgroud) 我试图获取文件的目录位置,我不知道如何得到它.我似乎找不到允许我这样做的模块.
所以例如说我有这个字符串:
/this/is/a/path/to/a/file.html
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个:
/this/is/a/path/to/a
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用这样的东西:
path.substr(0, path.lastIndexOf("/") - 1);
Run Code Online (Sandbox Code Playgroud)
但我不确定这是否与可能内置于节点的方法一样好.
我也尝试过:
var info = url.parse(full_path);
console.log(info);
Run Code Online (Sandbox Code Playgroud)
并且结果不会返回我要查找的内容,它会获得包含文件名的完整路径.
那么,节点中是否有内置功能可以做到这一点并做得好呢?
我有这个自定义事件设置,它适用于TypeScript 2.5.3
,但当我更新到2.6.1
我得到一个错误
window.addEventListener('OnRewards', (e: CustomEvent) => {
// my code here
})
Run Code Online (Sandbox Code Playgroud)
[ts]类型'(e:CustomEvent)=> void'的参数不能赋值给'EventListenerOrEventListenerObject'类型的参数.
类型'(e:CustomEvent)=> void'不能分配给'EventListenerObject'类型.
类型'(e:CustomEvent)=> void'中缺少属性'handleEvent'.
我不确定该怎么做才能解决这个问题.
java ×5
javascript ×3
swing ×3
typescript ×2
android ×1
android-file ×1
arrays ×1
game-engine ×1
imageicon ×1
jpanel ×1
node.js ×1
php ×1
phpexcel ×1
shadow ×1