Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 32

Thread: Can Somebody check this code?

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Can Somebody check this code?

    Hello,

    Can somebody check this code, cause I literally cant save or load anything ?! :S



    package pkgtry.catchexercises;

    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;

    public class FileDemo1 extends JFrame implements ActionListener{

    private TextField inputTextArea = new TextField(20);
    private TextField outputTextArea = new TextField(20);
    private JButton saveButton = new JButton("save");
    private JButton loadButton = new JButton("load");
    private FileWriter outFile;


    public static void main(String[] args){
    new FileDemo1();

    public FileDemo1(){
    setSize(350, 300);
    setTitle("File Output Demo");
    add("East", inputTextArea);
    add("West", outputTextArea);
    JPanel bottom = new JPanel();
    add("South", bottom);
    bottom.add(loadButton);
    bottom.add(saveButton);
    loadButton.addActionListener(this);
    saveButton.addActionListener(this);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);


    }
    @Override
    public void actionPerformed(ActionEvent evt){
    if(evt.getSource()==saveButton){
    try{
    outFile = new FileWriter("testout.txt", true);
    outFile.write(inputTextArea.getText());
    outFile.close();
    }catch(IOException e){
    System.err.println("File Error:"+e);
    System.exit(1);
    }
    }

    if(evt.getSource()==loadButton){
    try{
    inFile = new BufferedReader(new FileReader("FileDemo1.txt"));
    outFile.write(inputTextArea.getText());
    outArea.setText("");
    String line;

    while(line = inFile.readLine())! =null){
    outputArea.append(line + "\n");
    }
    inFile.close();
    }catch(IOException e){
    JOptionPane.showMessageDialog(this, "File Not Found");
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    I literally cant save or load anything
    What is the program supposed to do?
    Please explain what the program does and why that is not what you want it to do.
    Try debugging the code by adding printlns to show where the execution flow goes and the values of variables as they change.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Quote Originally Posted by Norm View Post
    What is the program supposed to do?
    Please explain what the program does and why that is not what you want it to do.
    Try debugging the code by adding printlns to show where the execution flow goes and the values of variables as they change.

    Well actually its suppose to be able to open up a GUI which already does and there are two individual columns of which one consists of save and the other load !

    And on the save column its suppose to save the text after clicking on save and when clicked on load button its supposed to load that saved text eventually !

    And I CANT DO THAT SOMEHOW :S !

    Thats my problem hope it helps .... for you to come up with a solution if you know the answer ?!

    Thanks

    Kind Regards,

    manager00104

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    I CANT DO THAT
    Please explain in some detail.
    What happens when you execute the code?

    Did you try this:
    Try debugging the code by adding printlns to show where the execution flow goes and the values of variables as they change.

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Quote Originally Posted by Norm View Post
    Please explain in some detail.
    What happens when you execute the code?

    Did you try this:
    Try debugging the code by adding printlns to show where the execution flow goes and the values of variables as they change.

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting


    Look man,

    When I execute the code it literally displays a GUI which I already told you one column a save one and the other load column. And WHAT ITS SUPPOSE TO DO IS .... ITS SUPPOSE TO SAVE THE FUCKING FILE THE (TEXT) AND THEN LOAD THE GOD DAMN FILE(TEXT) !!!!

    WHICH THE TEXT WILL BE DISPLAYED ON THOSE 2 COLUMNS THAT WERE CREATED WELL ITS ACTUALLY GOING TO BE SEEN IN LoAD COLUMN NORMALLY, CAUSE THE SAVE COLUMN IS EDITABLE !!!!

    DOES THAT ANSWER YOUR GOD DAMN QUESTION ?? ... CAUSE I REALLY DONT KNOW HOW TO SUMMARIZE THIS IN A WAY WHERE I CAN GET YOU TO UNDERSTAND THIS EVEN MORE SPECIFIC !

  6. #6
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Look dude,

    It displays these Exceptions !!!


    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
    at pkgtry.catchexercises.FileDemo1.main(FileDemo1.jav a:20)
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
    symbol: variable inFile
    location: class pkgtry.catchexercises.FileDemo1
    at pkgtry.catchexercises.FileDemo1.actionPerformed(Fi leDemo1.java:51)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6504)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:626 9)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4860)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 86)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713 )
    at java.awt.Component.dispatchEvent(Component.java:46 86)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101 )
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 677)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:90)
    BUILD SUCCESSFUL (total time: 11 seconds)

    OH BTW, IM WORKING ON NETBEANS !! (THE LATEST VERSION)

  7. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    IT NORMALLY DISPLAYS THIS !!!! FOR AN EXCEPTION THE OTHER ONE MIGHT BE THE WRONG ONE I SENT YOU !!!


    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
    at pkgtry.catchexercises.FileDemo1.main(FileDemo1.jav a:20)

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    I can not see what happens when you execute the code so I am asking you to tell me what you do and what happens when you do it. So far you have said the program starts and displays a GUI. Then what??? Do you do anything? If so, what do you do? What does the program do then?
    Are you expecting the program to read your mind about what you want it to do?
    Do you press any of the buttons shown on the GUI?

    If you don't press any of the buttons, the program will NOT do anything but wait for you.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    Uncompilable source code - illegal start of expression
    at pkgtry.catchexercises.FileDemo1.main(FileDemo1.jav a:20)
    That looks like a compiler error.
    What statement is on line 20?

  10. #10
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    look,

    when i press those buttons will not function thats my concern the problem is within those lines !! And i dont know where those problems are in the code i sent you in the very beginning ? if you know what i mean ...

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    What statement is on line 20?

  13. #13
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Its says public FileDemo1(){

  14. #14
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    public FileDemo1(){
    setSize(350, 300);
    setTitle("File Output Demo");
    add("East", inputTextArea);
    add("West", outputTextArea);
    JPanel bottom = new JPanel();
    add("South", bottom);
    bottom.add(loadButton);
    bottom.add(saveButton);
    loadButton.addActionListener(this);
    saveButton.addActionListener(this);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

  15. #15
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Did you try this on NetBeans ?????

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    That statement looks like the beginning of a constructor definition. However, it is inside of the main() method.
    You should end the main() method with a } before starting the definition of the constructor.

  17. #17
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Look at the attachment !!!
    Attached Files Attached Files

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    Please post your questions on the forum.

  19. #19
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Look dude we are learning now, btw im just a beginner ...

    about Exceptions in Java !
    and here is the ppt file that we looked through

    12ExceptionsAndFilesKate.zip

  20. #20
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    And that code is about this ppt file !

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    Do you have any questions or problems? If so, please post your specific questions here with some details about them.

  22. #22
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    Well, could you explain how I am going to solve that code, I GAVE YOU ... IN THE VERY BEGINNING I DONT SEE WHATS SO UNCLEAR ABOUT IT, IF YOU ARE AN EXPERT IN JAVA, YOU WONT BE HAVING ANY ISSUES OR PROBLEMS WHAT SO EVER TO TELL ME WHATS WRONG WITH IT ... AND YOU ARE ASKING ME WHAT THE CODE NEEDS TO DO ! ... SERIOUSLY MAN I TOLD YOU WHAT MY PROBLEMS WERE !!

    I REALLY HAD IT ... HERE IS ANOTHER TRY MY CODE IS BELOW AGAIN FOR YOU TO SEE AND MANIPULATE & IMPLEMENT IT !

    package pkgtry.catchexercises;

    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;

    public class SaveLoadBrowser extends JFrame implements ActionListener{

    private TextField inputTextArea = new TextField(20);
    private TextField outputTextArea = new TextField(20);
    private JButton saveButton = new JButton("save");
    private JButton loadButton = new JButton("load");
    private FileWriter outFile;


    public static void main(String[] args){
    new SaveLoadBrowser();

    public SaveLoadBrowser(){
    setSize(350, 300);
    setTitle("File Output Demo");
    add("East", inputTextArea);
    add("West", outputTextArea);
    JPanel bottom = new JPanel();
    add("South", bottom);
    bottom.add(loadButton);
    bottom.add(saveButton);
    loadButton.addActionListener(this);
    saveButton.addActionListener(this);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);


    }
    @Override
    public void actionPerformed(ActionEvent evt){
    if(evt.getSource()==saveButton){
    try{
    outFile = new FileWriter("testout.txt", true);
    outFile.write(inputTextArea.getText());
    outFile.close();
    }catch(IOException e){
    System.err.println("File Error:"+e);
    System.exit(1);
    }
    }

    if(evt.getSource()==loadButton){
    try{
    inFile = new BufferedReader(new FileReader("SaveLoadBrowser.txt"));
    outFile.write(inputTextArea.getText());
    outArea.setText("");
    String line;

    while(line = inFile.readLine())! =null){
    outputArea.append(line + "\n");
    }
    inFile.close();
    }catch(IOException e){
    JOptionPane.showMessageDialog(this, "File Not Found");
    }
    }
    }

  23. #23
    Junior Member
    Join Date
    Jan 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Somebody check this code?

    THIS IS FAR AS I CAN GO BY PUTTING IN THE CODE, AND FURTHER PROBLEMS OCCUR AS I SAID BEFORE ... SO IF YOU KNOW ANY OTHER SOLUTION TO THESE PROBLEMS TELL ME WHAT TO CODE NEXT OR CHANGE CODE(S) IF THERE IS SOMETHING WRONG WITH IT!

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    I guess you are going to have to fire me and hire someone else to help you.

    If you are not going to explain the problems you are having with the code, there is no way anyone can help you.

    If you want help post the full text of the error messages. Don't expect anyone to do your work for you. Your job is to tell us exactly what the problem is you are having. If you don't tell us, we can't see over your shoulder to see what you are seeing on your PC.

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can Somebody check this code?

    It's a waste of time for me to post coding suggestions. The code in post#22 does not contain the changes I suggested in post#16

Page 1 of 2 12 LastLast

Similar Threads

  1. How to code "check button"
    By Suni in forum AWT / Java Swing
    Replies: 1
    Last Post: December 28th, 2010, 09:21 AM
  2. Please check the code for the errors
    By nrao in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 16th, 2010, 05:37 PM
  3. Check this code out
    By jwill22 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 11th, 2010, 08:34 PM
  4. how to check the value
    By javaking in forum Java Servlet
    Replies: 2
    Last Post: July 22nd, 2010, 06:56 AM
  5. Problem in AWT and IFrame implementaion
    By AZBOY2000 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 24th, 2009, 03:41 AM