Tag: java

将char放入每个N个字符的java字符串中

我有一个java字符串,它有一个可变长度。 我需要将片段””放入字符串中,比方说每10个字符。 例如,这是我的字符串: `this is my string which I need to modify…I love stackoverlow:)` 我怎样才能获得这个字符串?: `this is my string which I need to modify…I love stackoverflow:)` 谢谢

元素MyElement在点(x,y)处不可点击…其他元素将收到点击

我正在尝试使用基于selenium的Katalon Studio进行一些测试。 在我的一个测试中,我必须在textarea内写。 问题是我收到以下错误: …Element MyElement is not clickable at point (x, y)… Other element would receive the click… 实际上我的元素放在其他可能隐藏它的diva中,但是如何让click事件命中我的textarea呢?

有效的gif /图像颜色量化?

所以我试图在我的Java应用程序中编码一些动画gif文件。 我一直在使用在线发现的一些类/算法,但似乎没有一个工作得很好。 现在我正在使用这个量化类将图像的颜色减少到256: http : //www.java2s.com/Code/Java/2D-Graphics-GUI/Anefficientcolorquantizationalgorithm.htm 问题是,它似乎并不是非常“聪明”。 如果我传入的图像超过256种颜色,它确实会减少颜色数,但效果不是很好。 (红色变成蓝色等 – 非常明显的错误就像这样)。 您可以推荐使用Java中的颜色量化的其他算法/库吗? 注意:我知道这个算法中使用的Neuquant: http : //www.java2s.com/Code/Java/2D-Graphics-GUI/AnimatedGifEncoder.htm 它非常慢并产生“eh”结果(帧之间的颜色闪烁)。

如何延迟Java?

我正在尝试用Java做一些事情,我需要在while循环中等待/延迟一段时间。 while (true) { if (i == 3) { i = 0; } ceva[i].setSelected(true); // I need to wait here ceva[i].setSelected(false); // I need to wait here i++; } 我想构建一个步序器,我是Java的新手。 有什么建议么?

JSch登录文件

我想将JSch日志保存在文件中,因为它在控制台中没有显示任何内容。 这是我的代码: public boolean openConnection() throws ItsSshException { boolean connectSuccess = false; JSch.setLogger(new MyLogger()); Properties config = new Properties(); config.put(“StrictHostKeyChecking”, “no”); jschSSH.setConfig(config); try { sshSession = jschSSH.getSession(username, hostname, port); sshSession.setPassword(password); sshSession.connect(connectionTimeout); LOGGER.info(“Connection timeout : ” + connectionTimeout); Thread.sleep(1000); sshHChannel = sshSession.openChannel(“shell”); sshHChannel.connect(); in = sshHChannel.getInputStream(); out = new PrintStream(sshHChannel.getOutputStream()); clearInitialSocketState(); connectSuccess = true; } catch […]

如何从文件夹中的图像将图标设置为JLabel?

每当从JComboBox中选择一个项目时,我都试图从图像文件夹中将图标设置为JLabel。 JComboBox中的项目名称和文件夹中图像的名称相同。 因此,无论何时从JComboBox中选择项目,都应将具有相同名称的相应图像设置为JLabel的图标。 我想做这样的事情。 private void cmb_movieselectPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt){ updateLabel(cmb_moviename.getSelectedItem().toString()); } protected void updateLabel(String name) { ImageIcon icon = createImageIcon(“C:\\Users\\xerof_000\\Pictures\\tmspictures\\” + name + “.jpg”); if(icon != null){ Image img = icon.getImage(); Image newimg = img.getScaledInstance(lbl_pic.getWidth(), lbl_pic.getHeight(), java.awt.Image.SCALE_SMOOTH); icon = new ImageIcon(newimg); lbl_pic.setIcon(icon); lbl_pic.setText(null); } else{ lbl_pic.setText(“Image not found”); lbl_pic.setIcon(null); } } protected static ImageIcon createImageIcon(String path) […]

Java:在构造函数中启动一个新线程

为什么在Java中(或者就任何地方而言)在构造函数中开始一个新线程。 我收到了Netbeans的警告,但它没有给我任何重构建议。 我正在编写一个客户端/服务器Swing应用程序,我正在启动的线程在服务器的JFrame构造函数中,以便持续监听客户端数据报。 为什么这不是好的做法,我该如何避免呢?

返回日期类型,格式为java

我正在尝试实现变量的get方法有类型“Date”。 但是当返回时,我想以格式“yyyy / MM / dd”返回它,并且必须是日期类型。 示例:原始日期:2018/01 / 01T15:00.00.000 + 0000 我想要返回:2018-01-01并且必须是日期,而不是字符串 在这种情况下你能帮帮我吗?

Java在不使用数组的情况下反转int值

任何人都可以向我解释如何在不使用数组或字符串的情况下反转整数。 我从网上得到了这个代码,但不是很明白为什么+输入%10并再次划分。 while (input != 0) { reversedNum = reversedNum * 10 + input % 10; input = input / 10; } 以及如何使用此示例代码仅反转奇数。 示例我得到了这个输入12345,然后它将奇数反转为输出531。

“错误:在MyClass类中找不到主要方法,请将主方法定义为……”

新Java程序员在尝试运行Java程序时经常会遇到这些消息。 Error: Main method not found in class MyClass, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application Error: Main method is not static in class MyClass, please define the main method as: public static void main(String[] args) Error: Main method must return a value […]