我尝试了SLF4J FAQ中的简单示例:
package com.aed.tests.logging;
import org.slf4j.LoggerFactory;
public class TestLogging
{
public TestLogging()
{
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args)
{
String s = "Hello world";
try
{
Integer i = Integer.valueOf(s);
}
catch(NumberFormatException e)
{
LoggerFactory.getLogger("simplelogger").error("Failed to format {}", s, e);
LoggerFactory.getLogger("simplelogger").error("Without parametrized string", e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
15:33:51,248000000 [SEVERE]simplelogger: Failed to format Hello world
15:33:51,275000000 [SEVERE]simplelogger: Without parametrized string
Run Code Online (Sandbox Code Playgroud)
我使用java.util.logging作为日志记录实现,使用以下logging.properties
# Properties file which configures the …Run Code Online (Sandbox Code Playgroud) 是否可以知道以HDF5格式存储的矩阵是在RowMajor还是ColMajor?例如,当我从octave中保存矩阵时,它将它们内部存储为ColMajor,当我在C代码中读取它们时,我需要转置它们,其中矩阵存储在RowMajor中,反之亦然.
我想使用JSlider来浏览一些按时间顺序排列的事件,因此我设置了一个自定义LabelTable,以便它显示一些Dates而不是默认的整数值.我的代码是这样的:
JSlider slider = new JSlider();
...
Date[] dates = getDates();
slider.setModel(new DefaultBoundedRangeModel(0, 0, 0, dates.length - 1));
Hashtable<Integer, JLabel> ht = new Hashtable<Integer, JLabel>();
for (int i = 0; i < dates.length; ++i) {
JLabel label = new JLabel(DateFormat.getDateInstance().format(dates[i]));
ht.put(i, label);
}
slider.setLabelTable(ht);
slider.setPaintLabels(true);
slider.setInverted(true);
Run Code Online (Sandbox Code Playgroud)
这很好,你可以看到:

但是,如果我想更改滑块的方向,请说明slider.setOrientation(JSlider.HORIZONTAL);结果如下:

如果我想在每隔一个日期在滑块下方显示一个日期/一个日期,该怎么办?另外,我可以在垂直滑块上显示滑块左侧的标签吗?
问候,雷米
使用此示例代码,我的时间/日期会发生什么变化?
package date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateFormatTest
{
public static void main(String args[]) throws ParseException
{
final String pattern = "dd/MM/YYYY HH:mm";
final Locale locale = Locale.FRENCH;
final SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);
Date d = new Date();
System.out.println("Today: " + d);
String parsedDate = formatter.format(d);
System.out.println("Today as string:" + parsedDate);
Date d2 = formatter.parse(parsedDate);
System.out.println("Today parsed back:" + d2);
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
Today: Fri Jun 28 16:28:04 CEST 2013
Today as …Run Code Online (Sandbox Code Playgroud) 我有一个JMenuItem限制为一个我可以使用的Action item.getAction().在构造Action时设置动作名称,例如使用匿名new AbstractAction(String text, ...).根据ResourceBundle和本地化信息设置文本字段.现在,如果我想更改本地化,我想更改Action.NAME字段,以便显示正确的本地化名称.我只能获得名称,例如使用item.getAction().NAME但不能更改字段,因为它是最终的.
我怎么能改变它的名字?
假设以下类:
class A {
public static final String someString = "thisIsSomeString";
// then potentially lots of non static members and functions.
}
class B {
void foo1() {
String someStringFromA = A.someString;
}
// OR
void foo2() {
String someStringFromA = "thisIsSomeString";
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,b.foo可以是foo1或者foo2.好处foo1很简单:只需要一个地方来定义字符串名称,如果我们需要更改它,只需在此更改即可.但我被告知使用foo1将某种方式"导入"A的代码到B中,这样编译后的B类可能会使用foo1而不是代替foo2.这是真的?我假设使用foo1相当于C#define.
我编写了一个代表日期的 C++ 类,并使用 strptime/strftime 从字符串编写和实例化日期。
当我使用“示例输出”选项卡中的 bash 在 Linux 上运行它几次时,有时我会创建并解析回相同的日期,有时我会得到偏移一小时的日期(我的时区是 UTC+1) 。
所以,这里发生了什么,我不知道!
#ifndef DOLIPRANE_TIMEUNIT_HPP
#define DOLIPRANE_TIMEUNIT_HPP
enum TimeUnit {
DAY,
HOUR,
MINUTE,
SECOND
};
#endif
#ifndef DOLIPRANE_DATE_HPP
#define DOLIPRANE_DATE_HPP
#include <ctime>
#include <string>
class Date
{
public:
Date();
Date(time_t epoch);
/**
* Expected format: dd/MM/YYYY HH:mm:[ss]
*/
Date(const std::string &date);
~Date();
void
add(long val, TimeUnit u = SECOND);
bool
operator==(const Date &other) const;
bool
operator!=(const Date &other) const;
bool
operator<(const Date &other) const;
bool
operator<=(const Date &other) const; …Run Code Online (Sandbox Code Playgroud)