小编Aha*_*med的帖子

为什么char []比字符串更适合密码?

在Swing中,密码字段具有getPassword()(返回char[])方法而不是通常getText()(返回String)方法.同样,我遇到了一个不使用String来处理密码的建议.

为什么String在密码方面会对安全构成威胁?使用感觉不方便char[].

java security string passwords char

3298
推荐指数
16
解决办法
38万
查看次数

JOptionPane获取密码

JOptionPane可用于从用户获取字符串输入,但在我的情况下,我想在中显示密码字段showInputDialog.

我需要的方式是应该屏蔽用户给出的输入并且返回值必须在char[].我需要一个带有消息,密码字段和两个按钮的对话框.可以这样做吗?谢谢.

java passwords user-interface swing joptionpane

47
推荐指数
2
解决办法
6万
查看次数

如何将HH:mm:ss.SSS转换为毫秒?

我有一个00:01:30.500相当于90500毫秒的字符串.我尝试过使用SimpleDateFormat包含当前日期的毫秒数.我只需要字符串表示毫秒.我是否必须编写自定义方法,它将分割并计算毫秒数?或者还有其他办法吗?谢谢.

我试过如下:

        String startAfter = "00:01:30.555";
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
        Date date = dateFormat.parse(startAfter);
        System.out.println(date.getTime());
Run Code Online (Sandbox Code Playgroud)

java time timestamp simpledateformat

20
推荐指数
2
解决办法
12万
查看次数

写入文件的字符串不保留换行符

我想写一个String(冗长但包裹),来自JTextArea.当字符串打印到控制台时,格式化与它的格式相同Text Area,但是当我使用BufferedWriter将它们写入文件时,它正在String单行写入.

以下代码片段可以重现它:

public class BufferedWriterTest {
    public static void main(String[] args) throws IOException {
        String string = "This is lengthy string that contains many words. So\nI am wrapping it.";
        System.out.println(string);
        File file = new File("C:/Users/User/Desktop/text.txt");
        FileWriter fileWriter = new FileWriter(file);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write(string);
        bufferedWriter.close();
    }
}
Run Code Online (Sandbox Code Playgroud)

什么地方出了错?怎么解决这个?谢谢你的帮助!

java string newline file

19
推荐指数
2
解决办法
5万
查看次数

如何在JPA(eclipselink)中使用joda时间?

我试着DataTimeentity班上使用.@Temporal(TemporalType.DATE)在字段上方添加,我得到错误说"Temporal类型的持久字段或属性必须是java.util.Date,java.util.Calendar或java.util.GregorianCalendar类型".我可以来回介绍转换; 使用setter和getter如下:

@Temporal(TemporalType.DATE)
private Calendar attendanceDate;

public DateTime getAttendanceDate() {
    return new DateTime(this.attendanceDate);
}

public void setAttendanceDate(DateTime attendanceDate) {
    this.attendanceDate = attendanceDate.toCalendar(Locale.getDefault());
}
Run Code Online (Sandbox Code Playgroud)

但我希望eclipselink能为我做到这一点.我已经通过Hibernate去了' 坚持Joda-time的DateTime ' .答案建议使用hibernate,但我必须使用eclipselink.我可以DateTime在我的实体类中使用DB表示的对象BLOB,但我需要它Date.有什么相似的jodatime-eclipselink吗?还是其他任何建议?谢谢您的帮助.

java persistence jpa jodatime eclipselink

14
推荐指数
2
解决办法
1万
查看次数

如何获取Java中的所有窗口句柄列表(使用JNA)?

我是JNA的新手.我试图获得所有窗口的句柄,包括最小化的窗口.我需要HWND所有的窗户.我已经解决了Windows的问题:如何获取所有可见窗口的列表?这有助于我获取窗口列表,但它的hWnd类型为int.我不能将它com.sun.jna.platform.win32.User32用于要求hWnd类型的功能com.sun.jna.platform.win32.WinDef.HWND.那么,有没有办法获得类型的所有窗口句柄com.sun.jna.platform.win32.WinDef.HWND而不是int指针?最后,为什么差异intHWND?它如何接受两者?我有点困惑.谢谢.

我有以下代码(从Hovercreft的答案编辑):

    import com.sun.jna.Native;
    import com.sun.jna.Pointer;
    import com.sun.jna.platform.win32.User32;
    import com.sun.jna.platform.win32.WinDef.HWND;
    import com.sun.jna.platform.win32.WinDef.RECT;
    import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;

    public class TryWithHWND {

    public static void main(String[] args) {
        final User32 user32 = User32.INSTANCE;
        user32.EnumWindows(new WNDENUMPROC() {
            int count = 0;
            public boolean callback(HWND hWnd, Pointer arg1) {
                char[] windowText = new char[512];
                user32.GetWindowText(hWnd, windowText, 512);
                String wText = Native.toString(windowText);
                RECT rectangle = new RECT(); …
Run Code Online (Sandbox Code Playgroud)

java windows winapi jna

12
推荐指数
1
解决办法
2万
查看次数

Embeddable类中的外键映射

我使用eclipselinkJPA.我有一个实体,它有一个由两个字段组成的复合键.以下是我的可嵌入主键类'字段(成员).

    @Embeddable
    public class LeavePK {
       @ManyToOne(optional = false)
       @JoinColumn(name = "staffId", nullable = false)
       private Staff staff;
       @Temporal(TemporalType.TIMESTAMP)
       private Calendar date;
       //setters and getters
    }
Run Code Online (Sandbox Code Playgroud)

我的实体将保留与员工相关的休假数据,因此我尝试将员工对象和离开日期结合起来以生成组合键.除了我的逻辑,它不允许我在embeddable类中有一个外键映射.当我尝试使用JPA工具 - >从实体生成表时,它会给出如下错误,这解释了,但我没有得到它.

org.eclipse.persistence.exceptions.ValidationException
Exception Description: The mapping [staff] from the embedded ID class [class rs.stapp.entity.LeavePK] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [leavePK] from the source [class rs.stapp.entity.Leave]) can only contain …
Run Code Online (Sandbox Code Playgroud)

java entity-relationship jpa composite-key embeddable

12
推荐指数
1
解决办法
2万
查看次数

如果main方法在java文件的"非公开类"里面怎么办?

我有一个包含多个类的java文件,其中一个是公共的.如果main方法在非公共类中.我无法运行该java文件.这是为什么?并且没有编译错误.如果是这样,我该如何使用该主要方法?

java program-entry-point public

9
推荐指数
2
解决办法
2万
查看次数

以编程方式为从XML创建的现有Menu创建子菜单

我已经在xml中创建了我的父菜单,现在我不知道如何使用代码在这些父项下创建子菜单.这意味着,父项在menu.xml中编码,子数据将在数据可用时根据动态代码加载.

当我尝试使用menu.addSubMenu时,它正在创建一个新的父菜单项.

android menu

8
推荐指数
2
解决办法
1万
查看次数

方法在java.awt的Dimension类中返回类型

我很惊讶地看到吸气鬼heightwidth成员都有return类型double,尽管他们是int.此外,setSize具有双参数的方法具有以下定义:

/**
 * Sets the size of this <code>Dimension</code> object to
 * the specified width and height in double precision.
 * Note that if <code>width</code> or <code>height</code>
 * are larger than <code>Integer.MAX_VALUE</code>, they will
 * be reset to <code>Integer.MAX_VALUE</code>.
 *
 * @param width  the new width for the <code>Dimension</code> object
 * @param height the new height for the <code>Dimension</code> object
 */
public void setSize(double width, double height) { …
Run Code Online (Sandbox Code Playgroud)

java double awt dimension

8
推荐指数
1
解决办法
2897
查看次数