目前我正在阅读"实践中的Java并发",其中包含以下句子:
由于访问无状态对象的线程的操作不会影响其他线程上的操作的正确性,因此无状态对象是线程安全的.
那么,什么是无状态对象?
ActionListener和ItemListener都用于使用JCheckBox触发事件?
那么,它们之间有什么区别呢?在这种情况下,其中一个比另一个更受欢迎?
我是c3op的新手,对以下内容的使用感到困惑:
c3p0.idle_test_period
Run Code Online (Sandbox Code Playgroud)
在此链接中:如何配置C3P0连接池
idleTestPeriod : Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default:
0, If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out
connections, every this number of seconds.
Run Code Online (Sandbox Code Playgroud)
什么是这种测试(IDEL,池连接)的目的,并c3p0.idle_test_period和c3p0.timeout之间的关系?
为什么我们可以通过Java中的对象引用访问静态变量,如下面的代码?
public class Static {
private static String x = "Static variable";
public String getX() {
return this.x; // Case #1
}
public static void main(String[] args) {
Static member = new Static();
System.out.println(member.x); // Case #2
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个Jwindow,当我添加一个Jtextfield时,文本字段变得无法编辑.
JWindow window = new JWindow();
window.setBounds(400, 100, 700,500);
window.setVisible(true);
window.setLayout(null);
JTextField text = new JTextField();
text.setBounds(300, 300, 150, 30);
text.setEditable(true);
window.getContentPane().add(text);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用Jframe作为Jwindow的所有者时,文本字段现在可以编辑,但框架与jwindow一起显示:
JFrame frame = new JFrame();
frame.setVisible(true);
JWindow window = new JWindow();
window.setBounds(400, 100, 700,500);
window.setVisible(true);
window.setLayout(null);
JTextField text = new JTextField();
text.setBounds(300, 300, 150, 30);
text.setEditable(true);
window.getContentPane().add(text);
Run Code Online (Sandbox Code Playgroud)
所以,我有两个问题:
我在这里遇到了同样的问题:Tomcat在eclipse中启动但无法连接到http:// localhost:8085 /,这意味着我无法在浏览器中打开http:// localhost:8080 /:
HTTP Status 404 - /
type Status report
message /
description The requested resource (/) is not available.
Apache Tomcat/7.0.27
//Console info when tomcat started//
Apr 10, 2012 4:26:32 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to org.eclipse.jst.jee.server:SimpleServletProject' did not find a matching property.
Apr 10, 2012 4:26:32 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Apr 10, 2012 4:26:33 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Apr 10, 2012 4:26:33 …Run Code Online (Sandbox Code Playgroud) 我有一个主JFrame.框架内有一个按钮.单击按钮时,将打开子框架.
但我只希望在任何时候只有1个子帧被打开,(相反,每当我再次单击该按钮时,它会给我第二个子帧,依此类推......).
所以,我将actionListener添加到按钮,使其在子框架打开时禁用,并将windowListener添加到子框架,这样当我单击右上角的关闭按钮时,它会生成按钮(在主框架)能够.
这是我的代码:
import java.awt.Button;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Form1 extends JFrame implements ActionListener{
JButton btn1=new JButton("help");
public Form1() {
super("Form 1");
this.add(btn1);
setSize(200, 200);
btn1.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btn1){
btn1.setEnabled(false);
final Form2 x= new Form2();
x.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
x.dispose();
btn1.setEnabled(true);
}
});
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
@Override
public void run() {
new …Run Code Online (Sandbox Code Playgroud) 我想JPanel在鼠标拖动时画上2条(或更多条)线。当我super.paintComponent(g)
在代码中使用时,无法在面板上绘制2条线,但是当我不使用时super.paintComponent(g);,结果很难看,如下图所示:

我了解行为什么会这样。
拖动鼠标时如何在面板上画线?
顺便说一句,g2d.draw(line2d)有时绘制的线不是平滑线(如下图所示)

到目前为止,我的代码:
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Line2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class LineDrawing extends JPanel implements MouseMotionListener, MouseListener{
Point point1;
Point point2;
Line2D line2d;
public LineDrawing(){
super();
addMouseListener(this);
addMouseMotionListener(this);
}
@Override
public void paintComponent(Graphics g){
//super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
if(point1!=null && point2!=null){
g2d.setPaint(Color.RED);
g2d.setStroke(new BasicStroke(1.5f));
g2d.draw(line2d);
}
}
@Override
public void mouseDragged(MouseEvent e) {
point2 …Run Code Online (Sandbox Code Playgroud) 当我尝试使用Tomcat(Tomcat 7.0.27,Eclipse Europa和Java 1.6.0_32)在Eclipse中创建一个小型演示时,我在启动页面时遇到此错误:
HTTP Status 404 - /Demo/
type Status report
message /Demo/
description The requested resource (/Demo/) is not available.
Apache Tomcat/7.0.27
Run Code Online (Sandbox Code Playgroud)
我录制了屏幕,请看一下这个视频(尝试高清播放):http://www.screenr.com/L5d8
我哪里错了?
我在JFrame上有2个Jpanel(leftpanel和rightpanel).当鼠标悬停在2个面板的交叉区域时,如何更改光标?
到目前为止,我尝试过:
...
public void mouseMoved(MouseEvent e) {
if (leftpanel.contains(e.getPoint()) && rightpanel.contains(e.getPoint())){
frame.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
}
else{ frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
};
Run Code Online (Sandbox Code Playgroud)
但它没有工作..