基本上,我想知道如何在IntelliJ中执行此操作(Eclipse插件从当前打开文件获取代码).
我遇到了用于Java的Sphinx语音识别库的问题.我用它来获取输入并处理它.我第一次得到输入,它的工作原理.第二次,它在我有机会谈话之前立即回答.在那之后,它继续回答自己.我尝试在每次输入之前分配并在每次输入后解除分配,但这似乎不起作用.我能做什么?
代码:
这是处理输入的方法:
public void getInput() {
if (using) return;
using = true;
if (!allocated) {
JTalk.speak("Please hold.");
recognizer.allocate();
allocated = true;
}
JTalk.speak("Speak now.");
Result result = recognizer.recognize();
if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
JDispatcher.getInstance().matchInput(resultText);
}
else {
JTalk.speak("Try again.");
}
using = false;
}
Run Code Online (Sandbox Code Playgroud)
你需要知道的:
MouseListenerfor a TrayIcon.speak(String)运行say <text>从Runtime.matchInput(String) 迭代数组中所有已注册的侦听器并测试匹配.更新2:
根据Nikolay Shmyrev的回答,我尝试在构造函数中分配麦克风,并在适当的时间启动,然后停止麦克风getInput().
这是SphinxBridge类:
public class SphinxBridge {
private ConfigurationManager cm; …Run Code Online (Sandbox Code Playgroud) 我怎样才能在Eclipse当前打开的文件中的代码返回的String还是String[]?我需要这个用于我正在制作的插件.
假设我有以下代码:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我打开HelloWorld.java,如何获取返回的代码String[]?在String[]将包含:
我正在开发一个Swing应用程序,它将在后台有一些图像.我想知道以下哪种方式更有效(或更好),或者如果你有另一种方式建议:
getGraphics().drawImage(t.getImage().getImage(), i * 16, j * 16, this);
要么
JLabel tile = new JLabel(t.getImage());
tile.setBounds(i * 16, j * 16, t.getImage().getIconWidth(), t.getImage().getIconHeight());
add(tile);
Run Code Online (Sandbox Code Playgroud)
编辑:
这是事情发生的地方:
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 3; i++) {
Tile t = map.getTiles()[j][i];
if (t != null) {
// Draw it somehow.
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用程序中播放YouTube视频.一切正常.但是,当我尝试观看包含Vevo内容的视频时,它会失败.
我也试过传入el=vevoget_video_info:
http://www.youtube.com/get_video_info?video_id=uuZE_IRwLNI&el=vevo&ps=default&eurl=&gl=US&hl=en
stream
{
"fallback_host" = "tc.v12.cache7.googlevideo.com";
itag = 22;
quality = hd720;
s = "8E6E5D13EB65FB653B173B94CB0BCC3A20853F5EDE8.5E2E87DF33EEDE165FEA90109D3C7D5DADA06B6BB60";
type = "video/mp4; codecs=\"avc1.64001F, mp4a.40.2\"";
url = "http://r7---sn-cvh7zn7r.googlevideo.com/videoplayback?pcm2fr=yes&sver=3&expire=1393773646&itag=22&id=bae644fc84702cd2&upn=SjZd81MudQs&sparams=gcr%2Cid%2Cip%2Cipbits%2Citag%2Cpcm2fr%2Cratebypass%2Csource%2Cupn%2Cexpire&ms=au&gcr=in&mt=1393747698&source=youtube&ratebypass=yes&ipbits=0&fexp=935620%2C919120%2C912523%2C932288%2C914084%2C916626%2C937417%2C937416%2C913434%2C932289%2C936910%2C936913%2C902907&mv=m&key=yt5&ip=103.250.162.79";
}
Run Code Online (Sandbox Code Playgroud)
当我用url它不玩.有什么解决方案吗?
我想知道是否有办法编写一个catch语句,只要在程序中抛出任何异常就会激活它.谢谢!
我试图在网页上嵌入applet.我已将代码导出为IntelliJ中的压缩小程序.现在,当我尝试运行它时,我得到以下堆栈跟踪:
java.lang.IllegalArgumentException: white space not allowed
at java.net.URLPermission.normalizeHeaders(URLPermission.java:401)
at java.net.URLPermission.init(URLPermission.java:189)
at java.net.URLPermission.<init>(URLPermission.java:166)
at sun.net.www.protocol.http.HttpURLConnection.URLtoSocketPermission(HttpURLConnection.java:1031)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1424)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.sun.deploy.net.HttpUtils.followRedirects(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doGetRequestEX(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.checkUpdateAvailable(Unknown Source)
at com.sun.deploy.cache.ResourceProviderImpl.isUpdateAvailable(Unknown Source)
at com.sun.deploy.cache.DeployCacheHandler.get(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1048)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:987)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:985)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(AccessController.java:713)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:984)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2648)
at sun.net.www.protocol.http.HttpURLConnection.access$300(HttpURLConnection.java:90)
at sun.net.www.protocol.http.HttpURLConnection$12.run(HttpURLConnection.java:2565)
at sun.net.www.protocol.http.HttpURLConnection$12.run(HttpURLConnection.java:2563)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(AccessController.java:713)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2562)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1768)
at sun.net.www.protocol.http.HttpURLConnection.access$200(HttpURLConnection.java:90)
at sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1431)
at sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1429)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(AccessController.java:713)
at …Run Code Online (Sandbox Code Playgroud) 我一直在努力将我的应用程序从Swing切换到JavaFX.我一直在做一个房间逃脱游戏,它显示用户点击的项目的描述.在Swing中,我将子类化JComponent并覆盖该paintComponent(Graphics)方法.我可以在那里绘制文本,知道不断调用该方法来更新屏幕.但是,使用JavaFX Canvas时,没有不断调用的方法,这使得此任务更难.我尝试save()了GraphicsContext之后我画了图像并restore()在我想要删除文本时调用,但无济于事.这是重要的代码:
package me.nrubin29.jescape;
import javafx.application.Platform;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.shape.Rectangle;
import java.util.Timer;
import java.util.TimerTask;
public class RoomPane extends Canvas {
private Room room;
private Toast toast;
public RoomPane() {
super(640, 480);
setOnMouseClicked(e -> {
for (JObject o : room.getObjects()) {
if (o.getBounds().contains(e.getX(), e.getY())) {
toast = new Toast(o.getDescription());
}
}
});
new Timer().schedule(new TimerTask() {
@Override
public void run() {
if (toast == null) {
return;
}
if …Run Code Online (Sandbox Code Playgroud) 我的BufferedWriter有一个奇怪的问题.似乎每次我使用它写一些文本文件,它都会清除文本文件并写入一行.我需要它来添加线条,而不是每次打印都重新开始.这是我的代码:
public void write(String str) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(savefile));
out.write(str);
out.newLine();
out.flush();
}
catch (Exception e) { e.printStackTrace(); }
}
Run Code Online (Sandbox Code Playgroud)
没有例外.
我想知道如何在JTextArea中更改位置标记(闪烁的I)的颜色.我想这样做的原因是因为我将使用带有黑色背景和绿色文本(旧终端样式)的GUI.我想要一个白色或绿色的位置标记.谢谢!
为糟糕的头衔道歉.我正在开发一个使用JTextPane作为主文本视图的游戏.我使用以下代码打印到窗格:
public void write(String txt, MessageType t) {
try {
for (char c : txt.toCharArray()) {
text.getDocument().insertString(text.getDocument().getLength(), String.valueOf(c), t.getAttributes());
Utils.pause(30);
}
text.getDocument().insertString(text.getDocument().getLength(), "\n", t.getAttributes());
}
catch (Exception e) { e.printStackTrace(); }
}
Run Code Online (Sandbox Code Playgroud)
该代码一次写入一个字符,每次写入之间休眠30毫秒.然后它写一个新的行字符.如果您有兴趣,这是pause()方法:
public static void pause(int millis) {
try { Thread.sleep(millis); }
catch (InterruptedException e) { e.printStackTrace(); }
}
Run Code Online (Sandbox Code Playgroud)
大多数时候,这很好.它会在每个角色之间写入一些空格,给人一种打字的印象.但是,有一个例子它不起作用.
我有一个处理输入的JTextField.我将这个KeyListener添加到它:
input.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
CommandParser.getInstance().parse(input.getText());
input.setText("");
}
}
});
Run Code Online (Sandbox Code Playgroud)
在CommandParser的parse()方法结束时,如果找不到命令,则该行运行:
Game.getInstance().getGUI().write("Invalid command.", GUI.MessageType.BAD);
Run Code Online (Sandbox Code Playgroud)
但是,仅对于该行,程序等待一秒,然后立即打印所有内容,而不是每30毫秒打印一个字符.为什么是这样?这与内部类有关吗?