我真的很困惑:当我在eclipse中正常运行我的程序时,我的一些代码无法正常工作,但是当我使用调试模式单独运行每个步骤时,它确实工作了.
码:
public void showConnectDialog() {
ConnectDialog connectDialog = new ConnectDialog();
connectDialog.setVisible(true);
//Until here, code runs
while(! connectDialog.getConnected()) {};
//The next line does only run in debug
JOptionPane.showMessageDialog(connectDialog, "Connected", "Connected", JOptionPane.INFORMATION_MESSAGE);
}
Run Code Online (Sandbox Code Playgroud)
连接器(一旦用户在对话框中点击"连接")就启动(作为线程):
private class ServerConnector implements ActionListener, Runnable {
@Override
public void actionPerformed(ActionEvent e) {
if (! IP_field.getText().equals("")) {
if (! isConnecting) {
new Thread(new ServerConnector(), "ServerConnector").start();
}
}
else {
JOptionPane.showMessageDialog(dialog,
"Enter an IP address",
"Enter IP",
JOptionPane.WARNING_MESSAGE);
}
}
@Override
public void run() {
try {
setConnecting(true); …Run Code Online (Sandbox Code Playgroud) 在我的程序中,我想使用JSpinner作为数字.这个数字稍后将用于计算某些东西.每次用户单击其中一个微调按钮(向上或向下)时,我希望结果自动更新.既然你不能将ActionListener添加到JSpinner(我认为这很奇怪),我在这里问如何做类似的事情(我已经准备好了一个ActionListener,可以在任何其他侦听器中更改)课程).
我需要将日期(随时间)存储在MySQL数据库中。我希望能够按照自己的喜好格式化这些格式。那么在MySQL数据库中存储日期的最佳方法是什么?DATETIME类型,TIMESTAMP类型还是数字数据类型中的unix时间戳?我将使用PHP检索日期。
我的程序中有一个设置选项卡.您可以在此处设置的数据不仅可以从此面板更改.这就是我想要每5秒重新加载这些数据的原因.我认为这必须使用额外的Thread完成,但我对Threads的了解很少.为此,我已经有了一个重载方法.
我该怎么做才能做到这一点(以及......)?
通常,在JTextArea中,文本从左上角开始.我希望它在左下角.你怎么能这样做?

(如果我的笔迹不可读,请道歉)
好吧,标题说明了一切:如果你return在run()实现的方法中使用会发生什么Runnable?它会不会造成Thread死亡?
我正在进行某种客户端 - 服务器连接.客户端可以连接到多个服务器,因此需要知道该服务器是否在线.我想要一个JLabel来显示服务器是否在线,而不是先输入所有登录信息.如何在不与服务器建立真正连接的情况下进行检查?
我正在尝试使用SimpleDateFormat做一些事情,但在我阅读Javadoc之后,我只会感到更加困惑.我想要两个方法,一个用于时区,一个用于当前时间和日期.我的格式应如下所示:
Time Zone: GMT +01:00
Time and Date: Wednesday 17/04/2013, 20:38:34
Run Code Online (Sandbox Code Playgroud)
我一次从互联网上获取代码.这工作得很好:
private String getFormattedTime() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
return sdf.format(cal.getTime());
}
Run Code Online (Sandbox Code Playgroud)
这将输出:20:41:34
现在我的其他格式,我尝试过这样的事情(我还没完成):
private static String getFormattedDate() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEEEEEEEE DD/MM/yyyy, HH:mm:ss");
return sdf.format(cal);
}
private static String getTimeZone() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("z");
return sdf.format(cal.getTimeZone());
}
Run Code Online (Sandbox Code Playgroud)
如果您运行此代码,则会在第一return行收到IllegalArgumentException .
似乎Javadocs没有给出如何使用它的任何示例.
我有一个在框内带有文字覆盖的图片。这是一种响应式设计,因此包装盒没有固定尺寸。我想将文本叠加层从顶部移动到底部,但是要用一个很好的平滑动画来做到这一点。动画必须悬停播放。我已经想出了如何做到这一点,但是我没有动画。
HTML大致如下所示:
<div class="box">
<div class="box_content">
<img class="inner_img" src="http://placehold.it/1000x1000" />
<div class="title">The Title</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是(剥离的)CSS:
.box {
position: relative;
}
.box_content {
position: absolute;
top: 0;
left: 0;
}
.title {
position: absolute;
bottom: 0; /* This moves it to the bottom (initial state) */
width: 100%;
height: 20%;
background: rgb(148, 193, 31);
background: rgba(148, 193, 31, 0.5);
}
.box:hover .title {
top: 0; /* This moves it to the top (only on hover) */
}
Run Code Online (Sandbox Code Playgroud)
现在可以使用,但是我想要一个视觉动画,将titlediv …