I am trying to open up a file and add it to a textarea, but the textfile wont work not sure what exactly isnt working but i know that the compiler reaches the function/method where i implement the read in file code. Here is the code
public class PictureAndButton extends JFrame implements ActionListener
{
private JMenuItem menuOptionOne = new JMenuItem("Lägg till text", KeyEvent.VK_L);
private JTextField textFalt = new JTextField();
public PictureAndButton()
{
menuInfo.add(menuOptionOne);
menuOptionOne.addActionListener(this);
textField.addActionListener(this);
setSize(350, 150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == menuOptionOne)
{
readInFile(textField.getText());
}
}
private void readInFile(String hej)
{
try
{
BufferedReader inFile = new BufferedReader(new FileReader(hej));
while(true)
{
String rad = inFile.readLine();
if(rad == null)
break;
textArea.append(rad);
}
}
catch(IOException e){}
}
public static void main(String[] args)
{
PictureAndButton peanutButter = new PictureAndButton();
}
}
I am running it on Eclipse and I am not getting any errors, the input text in the textfield doesnt change at all. Nothing is added to the text area. Really need some help on this