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