我正在尝试使用Eclipse创建Java 7地址簿,当我测试运行JFrame时,JLabel不可见并且JButton重叠.(按钮将占用整个JFrame)例如
add(saveButton);
add(cancelButton);
add(headingLabel);
headingLabel.setVisible(true);
cancelButton.setLocation(200,200);
saveButton.setLocation(400,200);
cancelButton.setSize(200,50);
saveButton.setSize(200,50);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
如何通过Java中的"StringIndexOutOfBounds"异常获取?以下是该程序的一些示例代码.
Scanner diskScanner = new Scanner (new File("C:\\Program Files\\SProjects\\temp\\test.ssc")); // opens file to read
line = diskScanner.nextLine();
if (line.substring(0,5).equals("PRINT")) { // Line 42
System.out.println(line.substring(8));
}
Run Code Online (Sandbox Code Playgroud)
它似乎来自"42"行或line.substring(),有人可以告诉我为什么抛出这个异常?
您如何将 JFrame.setIcon() 方法与 .ico 文件一起使用?我使用和 ImageIcon 作为参数。编译错误:
CodeBlocksMain.java:33: error: cannot find symbol
setIcon (icon);
^
symbol: method setIcon(ImageIcon)
location: class CodeBlocksMain
1 error
Run Code Online (Sandbox Code Playgroud)