LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   outputting from menu in swing applet, saving to file... (https://www.linuxquestions.org/questions/programming-9/outputting-from-menu-in-swing-applet-saving-to-file-454596/)

Mcribs 06-14-2006 10:48 PM

Quote:

Code:

public class Bits extends JFrame
{

    public static void main (String args[])
        throws java.io.IOException
       
    {

       
        new Bits ();
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));

       
        try
        {
          fw = new FileWriter ("C:/textpage.html");
        }
        catch (IOException e)
        {}
    }
    public Bits ()
        throws java.io.IOException
    {
        FileWriter fw //here?
        setSize (500, 400);
        setLocation (350, 250);
        setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        obj ();
        //pack();
        setVisible (true);

    }
   
    FileWriter fw;

    //menu options
    JMenuBar menuBar = new JMenuBar ();
    JMenu menu1 = new JMenu ("Choose A Menu Option");
    JMenuItem menuItem1 = new JMenuItem ("Getting Started");
    JMenuItem menuItem2 = new JMenuItem ("Learn about html");
    JMenuItem menuItem3 = new JMenuItem ("Basic Codes");
    JMenuItem menuItem4 = newJMenuItem ("Tutorials");



    JMenuItem menuItem8 = new JMenuItem ("Create a basic page (header, text, one link) ");


    JMenuItem menuItem10 = new JMenuItem ("Quiz Yourself");
    JMenuItem menuItem9 = new JMenuItem ("Answers to the quiz");
    JMenuItem menuItem11 = new JMenuItem ("Exit");

    JTextField nameTxtFld = new JTextField (10);
    JButton submitBtn = new JButton ("Submit");


I put the corrections in red.

ohfaney 06-14-2006 10:51 PM

Quote:

Originally Posted by Mcribs
I put the corrections in red.


okay i am getting another error, "the field name "fw" is not static, and cannot be accessed in this static context"

is the error i'm getting, sorry i must be really annoying but you're a huge help

Mcribs 06-14-2006 11:01 PM

Oops my bad. Take everything except the line new Bits() out of main and put it into the Bits() constructor

ohfaney 06-14-2006 11:06 PM

Quote:

Originally Posted by Mcribs
Oops my bad. Take everything except the line new Bits() out of main and put it into the Bits() constructor

"The method "void write(java.lang.String $1) throws java.io.IOException;" can throw the checked exception "java.io.IOException", so its invocation must be enclosed in a try statement that catches the exception, or else this method must be declared to throw the exception."


i'm still getting an error =[

Mcribs 06-15-2006 09:03 AM

Post all of your code and i'll take a look at it.


All times are GMT -5. The time now is 05:53 AM.