DI,Guice和战略模式

假设我有以下基类,Queen和Knight作为它的衍生物。 WeaponBehaviour是一个界面。 根据具体的GameCharacter类型,我无法弄清楚如何使用Guice注入武器。 public abstract class GameCharacter { @Inject protected WeaponBehaviour weapon; public GameCharacter() { } public void fight() { weapon.useWeapon(); } public void setWeapon(WeaponBehaviour weapon) { this.weapon = weapon; } }

Dijkstra无向图的最短路径

我的下面的代码对于有向图非常适用,当给定无向图时,它不会返回最短路径。 public void Djikstra(int s){ boolean[] marked = new boolean[V]; dist = new double[V]; for(int i = 0; i<V; i++){ # initializing array dist[i] = Double.POSITIVE_INFINITY; } dist[s] = 0.0; Queue pqs = new PriorityQueue(); pqs.add(s); while(!pqs.isEmpty()){ int v = pqs.poll(); if(marked[v]) continue; marked[v] = true; for(Edge e : get_list(v)){ # get_list(v) will return an […]

如何在Java中将数字格式化为格式为“xxx.xxx.xxx,yy”?

是否有一个Java类允许您将类似“102203345.32”的数字格式化为此“102.203.345,32”并返回字符串类型? 我想获得一个字符串,其中数千个被’。’分隔。 小数用逗号’,’分隔。 有人可以帮帮我吗? 我发现了一个DecimalFormat类,我尝试自定义它: public class CustomDecimalFormat { static public String customFormat(String pattern, double value ) { DecimalFormat myFormatter = new DecimalFormat(pattern); String output = myFormatter.format(value); return output; } } 但是当我像这样调用customFormat方法时:CustomDecimalFormat.customFormat(“###。###,00”)我得到一个exception…… 我该怎么办? 谢谢!

JLabel在睡觉前没有出现

我正在研究一个简单的Swing程序,它在框架上放置一个标签,睡眠一秒钟,然后在框架上放置另一个标签,如下所示: import javax.swing.*; import java.util.concurrent.*; public class SubmitLabelManipulationTask { public static void main(String[] args) throws Exception { JFrame frame = new JFrame(“Hello Swing”); final JLabel label = new JLabel(“A Label”); frame.add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 100); frame.setVisible(true); TimeUnit.SECONDS.sleep(1); SwingUtilities.invokeLater(new Runnable() { public void run() { label.setText(“Hey! This is Different!”); } }); } } 但是,我无法在睡眠前看到屏幕上的第一个标签。 睡觉时屏幕是空白的。 之后,我看到了原始标签的瞬间,然后是最后的标签“嘿!这是不同的!” 在屏幕上。 […]

如何在XDocReport中获取文档生成进度?

在我们的项目中,报告生成可能需要很长时间。 有没有办法在处理文档时获取生成的页数? 简单的进度条是不够的,我们需要向用户显示某些事情真的发生了。

异步写入GAE数据存储区

在我的Java应用程序中,有时我的用户会做一些需要数据存储区写入的工作,但我不想让用户在数据存储区写入时保持等待。 我希望在数据存储在后台时立即向用户返回响应。 似乎相当清楚我可以通过使用GAE任务队列来执行此操作,将任务排入队列以存储数据。 但我也看到有一个Async数据存储区API,看起来它比处理任务队列要容易得多。 我可以调用AsyncDatastoreService.put()然后从我的servlet返回吗? 该API会存储我的数据而不让用户等待吗?

Android:用Button更新UI?

所以我有一些简单的代码,但它似乎没有工作..任何建议? 我只想在按下按钮后显示图像,然后在2秒后变为不可见。 button.setOnClickListener(new OnClickListener() { public void onClick(View v) { firstImage.setVisibility(ImageView.VISIBLE); // delay of some sort firstImage.setVisibility(ImageView.INVISIBLE); } } 图像永远不会显示,它总是保持不可见,我应该以另一种方式实现吗? 我尝试过处理程序..但它没有用,除非我做错了。

如何在TestNg类之间传递WebDriver的单个实例

我无法在网上的任何地方找到一个不同的答案。 我有多个TestNg类来运行测试,BrowserFunctions,登录,搜索,过滤(测试亚马逊的实践)。 我还有一个BrowserLauncher类,它根据浏览器名称和testng.xml文件返回相应的webdriver。 BrowserFunctions.java public class BrowserFunctions { BrowserLauncher bl = new BrowserLauncher(); WebDriver driver; StringBuilder sb = new StringBuilder(); @BeforeSuite public void initialioseBrowser() { driver = bl.launchBrowser(“Firefox”); } @Parameters({ “URL” }) @BeforeSuite public void invokeURL(String URL) { driver.get(URL); } @AfterSuite public void closeBrowser() { driver.close(); } Login.java public class Login { BrowserLauncher bl = […]

java.lang.ClassNotFoundException:antlr.ANTLRException

我有一个方法来获得表的第一个结果。 public T LoadFirstData() { T object = null; try { startOperation(); Query query = session.createQuery(“from ” + type.getName()); object = (T) query.list().get(0); } catch (HibernateException e) { HandleException(e); } finally { HibernateUtil.Close(session); } return object; } 但是,当我运行该方法时,我有例外 Exception in thread “main” java.lang.NoClassDefFoundError: antlr/ANTLRException at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:58) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:98) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at […]

Java算法填充单元格,如“Android – Flow”游戏

我有一个问题。 我们有一个表2xN ,其链接节点为1,6 -> 1,1和2,6 -> 2,1就像一个cilinder。 —————————————————– (1)->| 1,1 | 1,2 | 1,3 | 1,4 | 1,5 | 1,6 | -> (1) —————————————————— (2)->| 2,1 | 2,2 | 2,3 | 2,4 | 2,5 | 2,6 | -> (2) —————————————————— 我有一个StartPoint1 – 是单元格1,1一个点和单元格2,6 EndPoint1 和一个StartPoint12 – 是单元格2,1一个点和单元格2,5 EndPoint2 我想在路上找到两个填充所有表格的组合。 例如上面是 (P1)=(1,1) – >(1,2) – >(1,3) […]