0
我正在使用Java Swing。最初我想讀一個文件(這很大)。因此,在文件完全顯示後,幀會顯示出來。而我想要首先加載(顯示)框架,然後應該讀取文件。如何僅在顯示JFrame後纔讀取Java文件?
class Passwd {
JFrame jfrm;
// other elements
Passwd() {
start();
// Display frame.
jfrm.setVisible(true);
}
public void start() {
// Create a new JFrame container.
jfrm = new JFrame("Password Predictability & Strength Measure");
// Specify FlowLayout for the layout manager.
//jfrm.setLayout(new FlowLayout());
jfrm.setLayout(null);
// Give the frame an initial size.
jfrm.setSize(450, 300);
// align window to center of screen
jfrm.setLocationRelativeTo(null);
// Terminate the program when the user closes the application.
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// some elements
File file = new File("file.txt");
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
// operation
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
// Create the frame on the event dispatching thread.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Passwd();
}
});
}
}
如何在顯示框架後讀取文件?
爲什麼第一行代碼中有「 - >」? – user5155835
@ user5155835:Java 8的lambda語法的一部分。請閱讀[在Java中做什麼箭頭運算符,' - >'?](https://stackoverflow.com/questions/15146052/what-does-the-arrow-operator-do-in-java) –
請你能告訴Pre Java 8嗎? – user5155835