我在 eclipse 中很新,并且在从其他方法调用变量时遇到问题,例如:
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showDialog(fc, null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File prnfile = new File(fc.getSelectedFile().toString());
}
}
});
btnNewButton.setBounds(54, 164, 89, 23);
frame.getContentPane().add(btnNewButton);
JButton btnNewButton_1 = new JButton("print");
btnNewButton_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
File file = new File(prnfile);
int ch;
StringBuffer strContent = new StringBuffer("");
FileInputStream fin = null;
try {
fin = new FileInputStream(file);
while ((ch = fin.read()) != -1)
strContent.append((char) ch);
fin.close();
} catch (Exception e1) {
System.out.println(e);
}
});
btnNewButton_1.setBounds(257, 164, 89, 23
现在,我如何从其他方法调用“prnfile”?通常我会在 C# 中创建一个公共对象,但它在 Eclipse 中不起作用,所以我不知道去哪里(作为一个完整的菜鸟 :))