Tuesday, April 10, 2012

Calling a variable from another method

i'm quite new in eclipse and having a problems with calling variables from other methods,such as:



    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


Now,how can i call "prnfile" from the other method?Normally i would create a public object in c# but it doesnt work in Eclipse,so i dunno where to go (being a complete noob :) )





No comments:

Post a Comment