我正在尝试用Java播放*.wav文件.我希望它执行以下操作:
按下按钮时,播放一声短促的哔声.
我用谷歌搜索了它,但大部分代码都没有用.有人可以给我一个简单的代码片段来播放.wav文件吗?
我是Hibernate的新手,阅读本书"使用Hibernate进行Java持久化",我试图从那里实现这个例子.到目前为止,我的Ant构建是成功的,但是当我尝试执行包含main方法的类时,我收到此错误消息:
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.3
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
19-Nov-2011 18:40:09 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
19-Nov-2011 18:40:09 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at persistence.HibernateUtil.<clinit>(Unknown Source)
at hello.Driver.main(Unknown Source)
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
... 2 …
Run Code Online (Sandbox Code Playgroud) 如果在Windows系统上安装了程序,我该如何检查Java,例如检查Mozilla Firefox?
在PHP中检查数组是否递归的最佳方法是什么?
给出以下代码:
<?php
$myarray = array('test',123);
$myarray[] = &$myarray;
print_r($myarray);
?>
Run Code Online (Sandbox Code Playgroud)
当print_r()到达数组的第三个元素时,它将显示RECURSION.
似乎没有任何其他方法可以扫描数组以进行递归引用,因此如果需要检查它们,则必须使用print_r()及其第二个参数来捕获输出并查找单词RECURSION.
有更优雅的检查方式吗?
PS.这是我使用regex和print_r()检查并获取递归数组键的方法
$pattern = '/\n \[(\w+)\] => Array\s+\*RECURSION\*/';
preg_match_all($pattern, print_r($value, TRUE), $matches);
$recursiveKeys = array_unique($matches[1]);
Run Code Online (Sandbox Code Playgroud)
谢谢
您可以在titledBorder的标题中放置一个图标,例如以下代码:
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class TitledExample extends JPanel {
public TitledExample() {
super(true);
this.setLayout(new GridLayout(1, 1, 5, 5));
JLabel label = new JLabel("Titled Border");
label.setHorizontalAlignment(JLabel.CENTER);
TitledBorder titled = new TitledBorder("Image here ?? Title");
label.setBorder(titled);
add(label);
}
Run Code Online (Sandbox Code Playgroud)
谢谢,干杯
伙计们,首先让我告诉你我是狂热的新手,所以我的问题对大多数人来说可能听起来很愚蠢.我想自定义例如home_controller.rb中的"index"方法,我知道正确的方法是使用装饰器.所以我创建了这个文件app/controller/home_controller_decorator.rb.我在那里
#app/controller/home_controller_decorator.rb
HomeController.class_eval do
def index
# Empty method
end
end
Run Code Online (Sandbox Code Playgroud)
原始的狂欢索引方法看起来像
def index
@searcher = Spree::Config.searcher_class.new(params)
@products = @searcher.retrieve_products
respond_with(@products)
end
Run Code Online (Sandbox Code Playgroud)
我希望当我添加_decorator重新启动服务器时,它会在主页上显示没有产品,或者会崩溃.当应用这个装饰器并启动服务器时,我收到此消息
agop@linux-as2q:~/Desktop/spp> rails server -p 3000
/home/agop/Desktop/spp/app/controllers/home_controller_decorator.rb:1:in `<top (required)>': uninitialized constant Spree::BaseController (NameError)
from /home/agop/Desktop/spp/lib/spree_site.rb:5:in `block in <class:Engine>'
from /home/agop/Desktop/spp/lib/spree_site.rb:4:in `glob'
from /home/agop/Desktop/spp/lib/spree_site.rb:4:in `<class:Engine>'
from /home/agop/Desktop/spp/lib/spree_site.rb:2:in `<module:SpreeSite>'
from /home/agop/Desktop/spp/lib/spree_site.rb:1:in `<top (required)>'
from /home/agop/Desktop/spp/config/application.rb:11:in `<class:Application>'
from /home/agop/Desktop/spp/config/application.rb:10:in `<module:Spp>'
from /home/agop/Desktop/spp/config/application.rb:9:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:28:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:28:in `block in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from …
Run Code Online (Sandbox Code Playgroud) 我知道这样做的CI方法是验证控制器中的规则,但我认为这不是最终的方法.您建议我遵循CI方式或验证模型中的传入数据,因此我的模型将始终保护自己免受不良数据的影响.我对MVC的理解是控制器不必保留任何程序逻辑,所有逻辑都在模型中实现.如果你能详细解释为什么两种方法都是好的而不是推荐哪种方法,我将不胜感激?
干杯