Java Swing GUI客户端和服务器聊天应用程序TextArea不更新

我正在使用Java和Swing类进行GUI的聊天应用程序。 ChatServer类将是服务器从客户端接收消息并回显给所有客户端,但我只打算为2个客户端进行聊天。 ChatClient类都是客户端。 它们显示文本区域上从服务器发送的内容。 并将文本字段中的文本发送到服务器。 ChatClient类 package chatclient; import java.net.Socket; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.InputStreamReader; public class ChatClient extends javax.swing.JFrame { public ChatClient() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method […]

未加权图的最短路径(最少节点)

我正在尝试构建一个方法,在未加权的图形中返回从一个节点到另一个节点的最短路径。 我考虑过使用Dijkstra,但这似乎有点矫枉过正,因为我只想要一对。 相反,我已经实现了广度优先搜索,但问题是我的返回列表包含一些我不想要的节点 – 如何修改我的代码以实现我的目标? public List getDirections(Node start, Node finish){ List directions = new LinkedList(); Queue q = new LinkedList(); Node current = start; q.add(current); while(!q.isEmpty()){ current = q.remove(); directions.add(current); if (current.equals(finish)){ break; }else{ for(Node node : current.getOutNodes()){ if(!q.contains(node)){ q.add(node); } } } } if (!current.equals(finish)){ System.out.println(“can’t reach destination”); } return directions; }

无法构造javafx.application.Application实例

我正在尝试Oracle网站上的JavaFX教程[fxml tutorial]( http://docs.oracle.com/javase/8/javafx/get-started-tutorial/fxml_tutorial.htm )。 package fxml; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; class Main extends Application { public Main() {} @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource(“welcome.fxml”)); Scene scene = new Scene(root); stage.setTitle(“FXML UI”); stage.setScene(scene); stage.show(); } public static void main(String args[]) { launch(args); } } […]

当子弹出窗口打开时,JPopupMenu关闭

我在JPopupMenu中有一个JComboBox(以及其他组件)。 事实certificate,每当我打开combobox的弹出窗口(选择一个项目)时,父JPopupMenu就会关闭。 我一直试图找到一种方法来覆盖这个function,但无济于事。 有没有人有任何建议,以防止关闭父JPopupMenu? 谢谢!

Java中的浮点数

任何人都可以请我为什么以下程序的输出不是“不同的”? public static void main(String[] args) { float f1=3.2f; float f2=6.5f; if(f1==3.2) System.out.println(“same”); else System.out.println(“different”); if(f2==6.5) System.out.println(“same”); else System.out.println(“different”); } o / p:不同的

如何使用在mockito中调用之间更改状态的相同参数来validation相同模拟方法的调用?

我有以下代码进行unit testing: public void foo() { Entity entity = //… persistence.save(entity); entity.setDate(new Date()); persistence.save(entity); } 我想validation在第一次调用persistence.save entity.getDate()返回null 。 因此,我无法使用Mockito.verify(/*…*/)因为那时方法foo已经完成,并且entity.setDate(Date) 。 所以我认为我需要在调用发生时对调用进行validation。 我如何使用Mockito做到这一点?

如何使用Spring Boot提供不同的数据库配置?

我目前看到它有5个可能的数据库配置文件 CI测试 – > h2 mem 开发人员环境(可以是测试或应用程序运行) – > h2 mem,或h2文件,或postgres 制作 – > postgres(理想情况下凭证不存储在git / war中) 目前我已经配置了运行应用程序的postgres,而h2配置为通过在java/resource s vs test/resources中使用不同的application.properties进行test/resources 在这些情况下,更新数据库连接信息的最简单方法是什么?

什么是辅助类?

我知道这些问题可能听起来很愚蠢,但在Java中,什么是辅助类,有些人如何编写,以及编译器如何知道某些东西是辅助类? 编辑:我问这个的原因是因为编译器正在生成关于外部库中对象的警告,我想知道原因。 编辑2: 以下是需要它的人的编译器警告: warning: auxiliary class Pattern in jregex/Pattern.java should not be accessed from outside its own source file

Tess4J:内存访问无效

我试图在我的项目中使用Tess4J从图像中提取文本。 我尝试运行OCR时收到以下错误:线程“main”中的exceptionjava.lang.Error:无效的内存访问 try { File imageFile = new File(“example4.jpg”); Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping //Tesseract1 instance = new Tesseract1(); String result = instance.doOCR(imageFile); System.out.println(result); } catch (Exception e) { e.printStackTrace(); }

为什么java中有两种不同的for循环?

我有一个for循环,我不知道它是如何工作的。 我熟悉: for(int i = 0; i <= 9; i++) { /* implementation */ } 我对以下forms的for循环感到困惑: String[] myString = new String[] {“one”, “two”, “three”, “some other stuff”}; String str1 = “”, str2 = “”; for (String s : myString) { /* implementation */ } 这些类型的for循环如何工作? 他们做什么不同然后定期循环?