用Java着色图像

我正在研究一些代码来用Java着色图像。 基本上我想要做的是GIMP的colorize命令,所以如果我有一个BufferedImage和Color,我可以用给定的颜色着色Image。 有人有任何想法吗? 我目前做这样的事情的最佳猜测是获取BufferedImage中每个像素的rgb值,并使用一些缩放因子将Color的RGB值添加到其中。

如何将图像添加到JFrame标题栏?

我想在javax.swing.JFrame标题栏中添加一个图像(小图标)。 我该怎么做?

JPanel添加但没有“及时”显示

我有一个显示JPanels的JFrame,具体取决于您单击的MenuItem。 它工作正常,但是现在我需要在将一个JPanel添加到框架并且正在显示它时调用一个方法(因为我在该面板中使用了JFreeChart,当JPanel可见时我必须调用chartPanel.repaint() ) : this.getContentPane().add( myjpanel, BorderLayout.CENTER ); //this = JFrame this.validate(); myjpanel.methodCalledOnceDisplayed(); 看起来好吗? myjpanel真的被展示了吗? 似乎不是: public void methodCalledOnceDisplayed() { chartPanel.repaint() } 这不起作用( chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0)抛出IndexOutOfBoundsException)。 这意味着调用重绘时JPanel不可见,我测试了以下内容: public void methodCalledOnceDisplayed() { JOptionPane.showMessageDialog(null,”You should see myjpanel now”); chartPanel.repaint() } 现在它工作了,我看到myjpanel在警报后面,正如预期的那样,chartPanel被重新绘制,并且没有发生exception。 编辑 :SSCCE(需要jfreechart和jcommon: http ://www.jfree.org/jfreechart/download.html) import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.Font; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; […]

在java中创建一个简单的规则引擎

我正在探索用Java创建简单业务规则引擎的不同方法。 我需要向客户端提供一个简单的webapp,让他配置一堆规则。 规则库的示例可能如下所示: 这是一个例子: IF (PATIENT_TYPE = “A” AND ADMISSION_TYPE=”O”) SEND TO OUTPATIENT ELSE IF PATIENT_TYPE = “B” SEND TO INPATIENT 规则引擎非常简单,最终操作可能只是两个操作中的一个,发送给住院病人或门诊病人。 表达式中涉及的运算符可以是=,>,<,!= ,表达式之间的逻辑运算符是AND, OR and NOT 。 我想构建一个Web应用程序,用户将在textarea中的小脚本中编写,我会评估表达式 – 这样,业务规则用简单的英语解释,业务用户可以完全控制逻辑。 从我到目前为止所做的研究中,我遇到了ANTLR并编写了自己的脚本语言作为解决这个问题的可能选项。 我没有探索像Drools规则引擎这样的选项,因为我觉得这可能是一种过度杀伤力。 你有解决这类问题的经验吗? 如果是的话,你是怎么做到的?

使用AuthenticationFailureHandler在Spring Security中自定义身份validation失败响应

目前,每当用户validation失败时,Spring安全性响应: {“error”: “invalid_grant”,”error_description”: “Bad credentials”} 我想通过以下响应代码来增强此响应: {“responsecode”: “XYZ”,”error”: “invalid_grant”,”error_description”: “Bad credentials”} 经过一番探讨,看起来我需要做的就是实现一个AuthenticationFailureHandler,我已经开始做了。 但是,每当我提交无效的登录凭据时,似乎都无法访问onAuthenticationFailure方法。 我已经逐步完成了代码,并在onAuthenticationFailure方法中进行了登录,以确认它未被访问。 我的失败处理程序是: @Component public class SSOAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler{ @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { super.onAuthenticationFailure(request, response, exception); response.addHeader(“responsecode”, “XYZ”); } } 我的WebSecurityConfigurerAdapter包含: @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired SSOAuthenticationFailureHandler authenticationFailureHandler; @Override protected […]

使用keySet()从JSONObject中提取键

我正在尝试从JSON对象中提取密钥。 在这种情况下,JSON对象是通过对名为SkyRock的社交网站进行API调用获得的,如下所示: { “max_page”: 2, “posts”: { “3111623007”: { “id_post”: 3111623007, “media_align”: “float_left”, “tags”: [], “nb_comments”: 24 }, “3114564209”: { “id_post”: 3114564209, “media_align”: “float_left”, “tags”: [], “nb_comments”: 33 }, “3116902311”: { “id_post”: 3116902311, “media_align”: “float_left”, “tags”: [], “nb_comments”: 29 } } } 我基本上想要将所有post_id值存储在ArrayList中。 为了做到这一点,我试图从JSON对象中提取密钥 ,并按如下方式执行此操作: JSONObject posts = (JSONObject) jo.get(“posts”); ArrayList keys = (ArrayString) posts.keyset(); […]

单击按钮后GUI冻结

我正在尝试创建一个客户端/服务器应用程序。 问题是客户端的确认按钮第一次输入工作,但如果我为另一个输入点击相同的按钮,客户端GUI将冻结。 为什么GUI会冻结? 客户: public class ClientGui { private JFrame frmBookPointOf; private JTextField txtRm; private JTextArea txtrBookDetails; private JTextField textField; private JTextField textField_1; private JTextField textField_2; private JTextField textField_3; private JTextField textField_4; private JTextField textField_5; private JComboBox comboBox_1; private JComboBox comboBox; private dbController dbCtrl; private Connection conn; private static Socket client; private static BufferedReader fromServer […]

如何使用Java 5获取主机mac地址?

我知道你可以使用java.net.NetworkInterface->getHardwareAddress()在Java 6中完成这项工作。 但是我部署的环境仅限于Java 5。 有人知道如何在Java 5或更早版本中执行此操作吗? 非常感谢。

Spring-Hibernate – 找不到当前线程的Session

我有一个使用spring和hibernate的java stuts2 web应用程序。 我得到org.hibernate.HibernateException: No Session found for current thread 。 SpringBean.xml org.hibernate.dialect.MySQLDialect true update hibernate.cfg.xml <!– –> 的hibernate.cfg.xml CustomerServiceImpl.java package org.rohith.service.impl; import org.rohith.dao.impl.CustomerDaoImpl; import org.rohith.model.Customer; import org.rohith.service.CustomerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class CustomerServiceImpl implements CustomerService { @Autowired private CustomerDaoImpl customerDaoImpl; @Override public void saveCustomer(Customer customer) { customerDaoImpl.saveCustomer(customer); } public CustomerDaoImpl getCustomerDaoImpl() { […]

什么是这种类型的初始化调用,为什么使用它?

Animal是一个用户定义的类。 Animal D = new Animal(“Leo”) { @Override public void makeNoise() { System.out.println(“Roar!”); } }; D.makeNoise();