我正在开发一个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) 我想迭代一个包含<s:select>列表源名称的字符串列表,但HTML输出不是预期的:它是显示的列表的名称,而不是内容.
我的Action代码:
public class DescriptionTabArchiveAction extends ActionSupport {
private List<String> vegetables = new ArrayList<String>();
private List<String> devices = new ArrayList<String>();
// contain "vegetables" and "devices".
private List<String> selectList = new ArrayList<String>();
@Action("multipleSelect")
public String multipleSelect() {
vegetables.add("tomato");
vegetables.add("potato");
devices.add("mouse");
devices.add("keyboard");
selectList.add("vegetables");
selectList.add("devices");
return SUCCES;
}
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
JSP:
<s:iterator value="selectList" var="listName">
<s:select list="%{#listName}" />
<!-- I tried with this line too : same behaviour. -->
<%-- <s:select list="#listName" /> --%>
</s:iterator> …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个简单的jdbc数据库调用应用程序.我在buildpath中有jar并且我的sqljdbc_Auth.dll在文件夹中:
C:\ Program Files(x86)\ jdbc\sqljdbc_4.0\enu\auth\x64
我收到此错误消息
错误:无法找到或加载主类文件
我的VM参数:看起来像这样......
-Djava.library.path = C:\ Program Files(x86)\ jdbc\sqljdbc_4.0\enu\auth\x64
这就是我目前所知道的.是否加载sqljdbc_auth.dll文件java.library.path比参与更多?
我有一个运行在Tomcat 7.0.43上的Struts2 Web应用程序,该应用程序使用Rest和Convention插件来映射所有请求。Struts尝试自己映射所有请求。
JSR 356使用如下注释来定义服务器端点
@ServerEndpoint(value = "/websocket/chat")
Run Code Online (Sandbox Code Playgroud)
现在,当浏览器尝试连接时ws:/127.0.0.1:8080/websocket/chat,由于Struts映射器拦截了该请求,因此请求失败。
我可以在XML文件中指定什么内容,以使请求到达正确的位置?
编辑:
按照建议,我添加了
<constant name="struts.action.excludePattern" value="/websocket.*?" />
Run Code Online (Sandbox Code Playgroud)
到我的Struts配置中,然后URL / websocket / chat开始出现404错误。
后来我了解到我需要配置一个ServerApplicationConfig实现。这样做之后,websocket开始正常运行,但是我的应用程序的其余部分无法加载,并给出了错误:
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
Run Code Online (Sandbox Code Playgroud)
这是我的课:
public class Socket implements ServerApplicationConfig {
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> scanned) {
Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();
return result;
}
@Override
public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
Set<Class<?>> results = new HashSet<Class<?>>();
for (Class<?> clazz : scanned) {
results.add(clazz);
}
return results; …Run Code Online (Sandbox Code Playgroud) 我知道有关于此主题的几个主题,但找到的解决方案特定于特定问题,并且基于改进Regex字符串.
无论如何,我需要处理一个文本输入文件,其中包含的数据将图形结构建模为相邻列表.每行n包含与n相邻的顶点列表(每个都标记为整数),由一个或多个空格字符分隔.我决定在解析之前使用正则表达式字符串检查每一行,而不是NumberFormatExceptions在数据不良的情况下抛出和捕获.
所以这就是代码在这一点上松散的样子:
line = line.trim(); //Remove whitespace in the beginning and in the end of line
if (Pattern.matches("(\\d+\\s*)*", line)){
//split string and parse vertices
}
Run Code Online (Sandbox Code Playgroud)
一行也可能为空,这意味着它的度数为0.
它适用于大多数实例,但是当解析具有~1000个相邻顶点的线(StackOverflow)时失败.我想知道我可以解决这个问题的各种方法.我不想增加JVM堆栈大小,因为程序应保持可移植性.此外,我想继续使用RegEx模式匹配,因为嘿,这就是它的用途!所以希望有人有个好主意.
现在,如果我<s:if>在Struts2中使用标记,我可以得到任何想要的结果
<s:if test="status==1">
//do some stuff
</s:if>
Run Code Online (Sandbox Code Playgroud)
但我不知道如何获得当前执行的动作,我期待着
<s:if test="action==addaction">
//do some stuff
</s:if>
Run Code Online (Sandbox Code Playgroud) 我想在Struts2中以两行显示错误消息
User Name is not valid
Password is not valid
Run Code Online (Sandbox Code Playgroud)
我的财产是:
username.password.errrorMsg: User Name is not valid \n Password is not valid.
Run Code Online (Sandbox Code Playgroud)
我添加\n但它以单行显示.
你能建议用两行显示吗?
我在这里找不到任何帮助,所以我只想问.
public Ride(String n, int tr, double hr , int nr){
String name = n;
int ticketsRequired = tr;
double heightRequirement = hr;
int numberOfRiders = nr;
}
public String toString(){
String info;
info = this.name + " Requiring " + this.ticketsRequired +
" tickets with a height restriction of " + heightRequirement;
return info;
}
Run Code Online (Sandbox Code Playgroud)
这是一次类,然后我尝试通过这个在我的包中的另一个程序中的main方法中调用它:
r1 = new Ride("Death run",0, 5.2, 5);
System.out.println( r1.toString());
Run Code Online (Sandbox Code Playgroud)
哪个会归还这个
null Requiring 0 tickets with a height restriction of 0.0
Run Code Online (Sandbox Code Playgroud)
我确信我错过了一些简单但却让我疯狂的事情.
我在GlassFish上运行我的应用程序,我使用Spring Security和Hibernate.当我运行应用程序时,GlassFish控制台上将显示以下警告和错误.我该如何避免它们?
WARNING: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@1087985b]) and a value of type [org.hibernate.internal.SessionImpl] (value [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])]) but failed to remove it when the web application was stopped. Threads are going to be …Run Code Online (Sandbox Code Playgroud) 我理解与此相关的问题已得到解答,但我没有遇到在我的搜索中回答的这个特定问题.
我一直在尝试将我的导入JAR文件包含在我的构建(如下所示)的spring应用程序中,但我所做的任何事情都不是解决方案.我在使用Tomcat和Ant在Eclipse中构建时收到'package not exists'错误,因为它无法在web-inf/lib文件夹中找到JAR文件(显然).Eclipse不允许我将文件从Referenced Library实用程序库中删除并拖动到任何所需的文件夹.当我尝试配置构建路径时,我添加了外部JAR,文件所在的目录路径显示在库选项卡中的JAR旁边.发布/导出依赖项设置为WEB-INF/lib文件夹我读过将所有JAR文件直接添加到Tomcat/lib文件夹(不应该这样做)可以解决问题,但对我来说情况并非如此.我为JAR设置了/ WEB-INF/lib的部署程序集路径,没有运气.我试过重启Eclipse,没有运气.我创建了一个新的动态Web项目,没有运气.我解压缩了war文件,没有找到JAR文件,这是预期的.我相信我的环境变量是正确添加的
我使用Eclipse和Spring应用程序已经好几年了,所以我希望我错过了一个重要的步骤.
注意:这是一个Spring教程,我一直在努力让我重新站起来.Eclipse版本4.3.0 Tomcat版本6 Ant版本1.8.4 - 作为Eclipse下载的插件包含在内
任何帮助将不胜感激,因为我会喜欢再次使用Web应用程序.
<project name="springapp1" basedir="." default="usage">
<property file="build.properties"/>
<property name="lib.dir" value="C:/Eclipse/Tomcat/lib"/>
<property name="webapps.dir" value="C:/Eclipse/Tomcat/webapps"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="WebContent"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="springapp1"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<!--<fileset dir="${appserver.lib}">-->
<fileset dir="${lib.dir}">
<include name="servlet*.jar"/>
</fileset>
<pathelement path="${build.dir}"/> …Run Code Online (Sandbox Code Playgroud)