what an earth have I done wrong here - I WAS sure that I was on the right track. This code compiles then error:
Code:import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class ExampleFrame2a extends JFrame implements WindowListener { public static void main (String [] args) { ExampleFrame2a demo = new ExampleFrame2a(); // create an instance of the ExampleFrame object demo.setLayout(new GridLayout(4,4)); // set Layout manager to Grid Layout demo.setSize(900,700); demo.addWindowListener(demo); // register listener for window events, eg close String s=readTextFile("poem.txt"); // read from the poem file to a String Label fnameL = new Label("First Name"); demo.add(fnameL); TextField fnameTF = new TextField(10); demo.add(fnameTF); Label SnameL = new Label("Surname"); demo.add(SnameL); TextField SnameTF = new TextField(10); demo.add(SnameTF); Label StreetL = new Label("Street"); demo.add(StreetL); TextField StreetTF = new TextField(10); demo.add(StreetTF); Label CityL = new Label("City"); demo.add(CityL); TextField CityTF = new TextField(10); demo.add(CityTF); Label CountyL = new Label("County"); demo.add(CountyL); TextField CountyTF = new TextField(10); demo.add(CountyTF); Label PCodeL = new Label("Post Code"); demo.add(PCodeL); TextField PCodeTF = new TextField(10); demo.add(PCodeTF); TextArea myTextArea = new TextArea("",10,50); // create a text area and add it to the frame demo.add(myTextArea); myTextArea.append(s); // append text from file to the text area demo.setVisible(true); // make Frame visible } public static String readTextFile(String filename) { BufferedReader inFile; String line, s = ""; // intialize s try { inFile = new BufferedReader(new FileReader(filename)); while ( (line = inFile.readLine()) != null ) { s = s + line + "\n"; // concatenate onto s, WITH // AN EXTRA NEW LINE } inFile.close(); } catch (IOException e) { System.out.println("Error in file " + filename + " : " + e.toString() ); System.exit(1); // better if -1, means standard error } return s; } public void windowClosing(WindowEvent e) { // code to handle closing the window System.exit(0); } //unused empty WindowListener Methods --- needed to enable a // compile public void windowIconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowDeactivated(WindowEvent e) { } }




Reply With Quote