草庐IT

java - 一个Java应用程序是如何配备的?

我从:EveryJavaapplicationstartswithamainmethodthatrunsinthemainthread.InaSwingprogram,themainthreadisshort-lived.Itschedulestheconstructionoftheuserinterfaceintheeventdispatchthreadandthenexits...Otherthreads,suchasthethreadthatpostseventsintotheeventqueue,arerunningbehindthescenes,butthosethreads

java - 如何取消 SwingWorker 的执行?

目前我有两个SwingWorker线程在后台工作。如果发生异常,该方法停止工作,但线程仍在运行。doInBackground()发生异常时如何停止执行并杀死线程?this.cancel(true)不要破坏/关闭线程。我怎样才能做到这一点?@OverrideprotectedBooleandoInBackground()throwsException{try{while(true){//somecodeherereturntrue;}}catch(Exceptione){this.cancel(true);//我在Netbeans的调试中看到了这些线程。'AWT-EventQueue-0

java - Play Framework : PersistenceException: The type is not a registered entity? (Ebean)

我正在学习适用于Java的PlayFramework2.0教程,但在尝试保存ebean模型(task.save())时遇到此错误。[PersistenceException:Thetype[classmodels.Task]isnotaregisteredentity?Ifyoudon'texplicitlylisttheentityclassestouseEbeanwillsearchforthemintheclasspath.IftheentityisinaJarchecktheebean.search.jarspropertyinebean.propertiesfileorche

Java - 编码风格 : What are the cons and pros of "ABC". 等于 ("SOMESTRING") 风格字符串比较?

这个问题在这里已经有了答案:Whatistheproperwaytousea.equalsmethodinJava?(2个答案)关闭9年前。让我先从示例代码开始...Stringpassword="";if("PIRATE".equals(password)){//Dosomething}看这里,字符串常量或字面量(无论什么)“PIRATE”用于检查两个字符串的相等性。而...Stringpassword="";if(password.equals("PIRATE")){//Dosomething}这也与之前的代码完全一样。现在,我看到很多第一种样式"STRING_LITERAL".e

java - 得到一个 The entity name must immediately follow the '&' in the entity reference error in java, 但我的 xml 文件中没有任何符号

我遇到了错误Theentitynamemustimmediatelyfollowthe'&'intheentityreference.但我的XML文档中没有任何符号!有谁知道为什么会发生这种情况?这是我要解析的XML文档:BestiPadstrategygameshttp://feedproxy.google.com/~r/TheIphoneBlog/~3/198mhX3FVmw/story01.htmShareyourlifewithfriendsinrealtimewithSpinhttp://feedproxy.google.com/~r/TheIphoneBlog/~3/9G8

java - (Java) 退出循环 "remotely"

我有一段Java程序主要执行以下操作:publicstaticvoidmain(String[]args){while(true){//doesstuff...}}无限循环是有意设计的——当任其发展时,程序将无限循环。在大多数情况下,它工作正常。但是,有时我想把程序拿下来维护,当我把它拿下来时,我想确保它运行完循环中的所有代码,直到结束然后退出。我想知道最好的解决方案是什么。我想到的一个想法是做这样的事情:publicstaticvoidmain(String[]args){Filef=newFile("C:\exit.txt");while(!f.exists()){//doesst

java - 打包时如何使maven "add directory entries"?

我有一个程序利用getClass().getClassLoader().getResource()获取目录的URL,它在eclipse中工作正常,但在jared之后,它返回空。根据这个网址:http://www.coderanch.com/t/385935/java/java/getResource-path-fails-JarTheproblemresultedbecausethepathitselfdidnotexistinthejar.Thefileswiththepathexisted,butnotthepathitself.Iwasusingthe"RunnableJARFi

java - 可缩放的 JScrollPane - setViewPosition 无法更新

我正在尝试在JScrollPane中编写可缩放图像。当图像完全缩小时,它应该水平和垂直居中。当两个滚动条都出现时,缩放应始终相对于鼠标坐标发生,即图像的同一点应在缩放事件前后位于鼠标下方。我的目标快要实现了。不幸的是,“scrollPane.getViewport().setViewPosition()”方法有时无法正确更新View位置。在大多数情况下调用该方法两次(hack!)可以解决该问题,但View仍然闪烁。我无法解释为什么会这样。但是我相信这不是数学问题。下面是一个MWE。要查看我的问题具体是什么,您可以执行以下操作:放大直到有一些滚动条(缩放200%左右)点击滚动条滚动到右下

java - 通过使用 java.util.Date 可能出现下溢错误

这段代码:packagetest;importjava.util.Date;publicclassDateUnderflow{publicstaticvoidmain(String[]args){Longtimestamp=-8120649749785140250L;System.out.println(newDate(timestamp));}}产生以下输出:"SatAug0310:00:59CET257325894"怎么会?无一异常(exception)的下溢?Doc说Date(longdate)的date参数是自纪元以来的毫秒数,所以我有点惊讶地发现自己如此深入future..我

java - Java 是否支持多行字符串?

来自Perl,我确实错过了在源代码中创建多行字符串的“here-document”方法:$string=在Java中,当我从头开始连接多行字符串时,我必须在每一行上使用繁琐的引号和加号。有哪些更好的选择?在属性文件中定义我的字符串?编辑:两个答案说StringBuilder.append()优于加号。谁能详细说明他们为什么这么认为?对我来说,它看起来并不更可取。我正在寻找解决多行字符串不是一流语言结构这一事实的方法,这意味着我绝对不想用方法调用替换一流语言结构(字符串与加号连接)。编辑:为了进一步澄清我的问题,我根本不关心性能。我担心可维护性和设计问题。 最