我想用鼠标点击在我的应用程序中设置点.我使用JFreeChart并在ChartPanel鼠标监听器中使用.这看起来像这样:
panel.addChartMouseListener(new ThisMouseListener());
Run Code Online (Sandbox Code Playgroud)
和我的鼠标监听器ThisMouseListener()(它没有完成):
class ThisMouseListener implements ChartMouseListener{
@Override
public void chartMouseClicked(ChartMouseEvent event) {
int x = event.getTrigger().getX();
int y = event.getTrigger().getY();
System.out.println("X :" + x + " Y : " + y);
ChartEntity entity = event.getEntity();
if(entity != null && (entity instanceof XYItemEntity)){
XYItemEntity item = (XYItemEntity)entity;
}
new JOptionPane().showMessageDialog(null, "Hello", "Mouse Clicked event", JOptionPane.OK_OPTION);
}
@Override
public void chartMouseMoved(ChartMouseEvent arg0) {
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)
但是这个鼠标监听器会返回我的面板坐标,我想从我的图表中获取坐标.可能是我必须使用其他对象的监听器?或者我可以用某种方法变换坐标?
我不是很擅长创建Swing应用程序.所以我有问题如何设置图标JButton.
我的项目结构如下所示:

我JButton在MainWindow课堂上很简单:它看起来像这样:
tactButton = new JButton("next tact");
Run Code Online (Sandbox Code Playgroud)
我想使用方法将图像设置为此按钮setIcon.我的代码看起来像这样:
tactButton.setIcon(new ImageIcon(getClass().getResource("/images/button_next.jpg")));
Run Code Online (Sandbox Code Playgroud)
但是当我启动应用程序时,我有例外:
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at by.bulgak.conveyor.gui.MainWindow.<init>(MainWindow.java:117)
at by.bulgak.conveyor.gui.MainWindow$1.run(MainWindow.java:46)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Run Code Online (Sandbox Code Playgroud)
所以我尝试了不同的东西:
MainWindow的类tactButton.setIcon(new ImageIcon("/images/button_next.jpg")); 但我有这个例外,或者如果我使用tactButton.setIcon(new ImageIcon("/images/button_next.jpg"));我有简单的按钮没有图像.
最后,我写了我的图像的绝对路径,这很好(但绝对路径不是好主意).你能帮帮我吗?
我看了一个问题如何将图像添加到JButton并试图像那样做.
UPDATE
创建按钮和设置图标的完整代码:
tactButton = new JButton("next tact");
tactButton.setSize(100, …Run Code Online (Sandbox Code Playgroud) 嗨,我是JSF的新手,有这样的问题.在我的页面上,我有新闻列表,每个新闻都有复选框(我们可以选中此复选框,然后删除已检查的新闻).这很好用.但是在删除之后我返回到我的页面然后按F5然后我的应用程序认为检查了删除后的复选框并将其删除.例如我有这个:

按删除按钮,并具有:
按f5,我看到了这个:

所以我的删除方法如下所示:
Map<Integer, Boolean> allCheckboxes = newsForm.getCheckboxes();
Set<Integer> checkboxes = newsForm.getCheckboxes().keySet();
Set<Integer> checkedCheckboxes = new HashSet<>();
for(Integer id : checkboxes){
boolean value = allCheckboxes.get(id);
if(value){
checkedCheckboxes.add(id);
}
}
if (checkedCheckboxes.size() != 0) {
newsDao.deleteNewsById(checkedCheckboxes.toArray());
} else {
Integer[] delete = { newsForm.getNews().getId() };
newsDao.deleteNewsById(delete);
}
newsForm.setNewsList(newsDao.getNewsList());
return list() + REDIERCT;
Run Code Online (Sandbox Code Playgroud)
在我的页面我使用selectBooleanCheckbox:
<h:selectBooleanCheckbox id="checkbox"
value="#{newsForm.checkboxes[news.id]}" />
Run Code Online (Sandbox Code Playgroud)
所以我不明白为什么当我按f5时我的Map<Integer, Boolean> allCheckboxes一些元素值为true.每次删除后我都会重新创建Map<Integer, Boolean> allCheckboxes
更新 news.xhtml
<h:form id="main-form" onsubmit="return getSelectedCheckBoxes()">
<h:commandLink styleClass="news-link" action="#{controller.list}"
value="#{messages['body.news']}" />
>>
<h:outputText value="#{messages['body.news.titles.list']}" /> …Run Code Online (Sandbox Code Playgroud) 嗨,我想建立我的第一个Android项目.我是一个优秀的程序员,微控制器,php,bash等.
但是这个java语法正在想要爆炸.
package com.example.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
TextView tv1 = (TextView) findViewById(R.id.textView1);
tv1.setText("Text2");
}
Run Code Online (Sandbox Code Playgroud)
和
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable = …Run Code Online (Sandbox Code Playgroud) 我使用类型为“DELETE”的 jquery ajax 发送我的请求。在服务器端,我有适当的处理方法,如下所示:
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String delete(@RequestParam("hotel") String hotelCode, @PathVariable Long id, Model model){
//delete operation
return "redirect:/HotelTaxesAndCharges?hotel="+hotelCode;
}
Run Code Online (Sandbox Code Playgroud)
我想在删除后将调用重定向到的方法如下所示
@RequestMapping(method = RequestMethod.GET)
public String getAll(@RequestParam("hotel") String hotelCode, Model model){
//logic
return 'getAll';
}
Run Code Online (Sandbox Code Playgroud)
so when i call delete method during execution I'm getting error "you can redirect to JSP using only GET PUT or HEAD methods". I found solution using HiddenHttpMethodFilter, but result code looks little messy and I need to send request …
我是Spring的新手,想把spring ioc连接到我的小(测试)web-app.
我有这样的Servlet ProductServlet:
public class ProductServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
private RequestHelper requestHelper;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request);
}
private void processRequest(HttpServletRequest request){
requestHelper.process(request);
}
public RequestHelper getRequestHelper() {
return requestHelper;
}
public void setRequestHelper(RequestHelper requestHelper) {
this.requestHelper = requestHelper;
}
}
Run Code Online (Sandbox Code Playgroud)
和我的web.xml:
<servlet>
<servlet-name>ProductServlet</servlet-name>
<servlet-class>com.epam.productshop.controller.ProductShop</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProductServlet</servlet-name>
<url-pattern>/ProductServlet</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-config.xml
</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
而且我有这样的弹簧配置xml:
<bean id="factory" class="com.epam.productshop.readerfactory.ReaderFactory">
<property …Run Code Online (Sandbox Code Playgroud) 我遇到了一些以前没有想到的Maven行为。例如,我们有一个多模块项目A:
A
|
--- api
--- impl
Run Code Online (Sandbox Code Playgroud)
impl模块使用api作为依赖项:
<dependency>
<groupId>examle</groupId>
<artifactId>api</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我运行mvn clean test整个应用程序时,maven成功完成。当我为impl模块执行相同的命令时,它们的maven失败,并出现以下异常:
[ERROR] Failed to execute goal on project impl: Could not resolve
dependencies for project A:impl:jar:1.0-SNAPSHOT: Could not find artifact
A:api:jar:1.0-SNAPSHOT in maven-public
Run Code Online (Sandbox Code Playgroud)
因此,我的问题是maven如何解决未构建到jar文件中并推送到本地/远程存储库中的依赖项。在所有教程中,都说过maven在本地存储库中寻找依赖项,如果找不到,则在远程仓库中搜索,并且对于SNAPSHOTS几乎没有什么不同的行为。
但就我而言,我运行测试阶段,即使在目标存储库中也不构建jar文件
我正在编写小型图形编辑器,我想在按 Ctrl+A 时捕获事件
我使用这样的代码(这是测试版):
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Press");
switch (e.getKeyCode()){
case KeyEvent.VK_A :
System.out.println("A");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何捕捉 Ctrl+a
我试过这样的事情
case KeyEvent.VK_CONTROL+KeyEvent.VK_A :
System.out.println("A+CTRL");
break;
Run Code Online (Sandbox Code Playgroud)
但此代码KeyEvent.VK_CONTROL+KeyEvent.VK_A返回 int 并且可能另一个组合键返回相同的数字
所以有人可以帮助我吗
我多年没有用Java编写代码,但最近我被要求在工作中实现一个基于java的程序.长话短说,它做了我们需要的一切,除了它将用户ID放在报告而不是电话号码.我应该指出,我们是拥有该计划的公司的合作伙伴,我允许他们根据需要进行更改.但是,他们的网站不提供源代码.我已经要求了,但3周后没有运气.因此,我必须对代码进行反编译,并进行必要的更改.我已设法进行更改,并删除除三个以外的所有编译错误.它们在三个不同的For循环中都是相同的错误.当我尝试顶级编译时,我得到以下内容.
FraudDetectionTool.java:655: not a statement
for ( str3 : arrayOfString2 ) {
^
FraudDetectionTool.java:655: ';' expected
for ( str3 : arrayOfString2 ) {
^
FraudDetectionTool.java:655: illegal start of expression
for ( str3 : arrayOfString2 ) {
^
FraudDetectionTool.java:655: ';' expected
for ( str3 : arrayOfString2 ) {
^
FraudDetectionTool.java:681: not a statement
for (str3 : array3) {
^
FraudDetectionTool.java:681: ';' expected
for (str3 : array3) {
^
FraudDetectionTool.java:681: illegal start of expression
for (str3 : array3) {
^
FraudDetectionTool.java:681: ';' …Run Code Online (Sandbox Code Playgroud) java ×9
swing ×2
android ×1
for-loop ×1
image ×1
imageicon ×1
jfreechart ×1
jsf ×1
keylistener ×1
loops ×1
maven ×1
multi-module ×1
packaging ×1
servlets ×1
spring ×1
spring-mvc ×1
textview ×1