Stack Exchange
Swing code compilation error "missing ;"
How do I solve this compilation error? Note that I'm new to Swing.
http://prntscr.com/bpz2ve
package gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.*;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class GUI extends Frame {

    public static void main(String[] args) {
        JFrame frame = new JFrame("Hello World - YaBoiAce");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setSize(500, 300);

        // Layout //
        frame.setLayout(new BorderLayout());

        // Swing Component //
        final JTextArea textarea = new JTextArea();
        JButton jbutton = new JButton("Click me");

        // Add Component to content pane
        Container c = frame.getContentPane();

        c.add(textarea,BorderLayout.CENTER);
        c.add(jbutton, BorderLayout.SOUTH);

        // Action Listener
        jbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                textarea.append("Hello");
            } // Eclipse says 'missing ;' on this line.
        } 
            private static void setDefaultCloseOperation(int exitOnClose) {

            }

        }

Eclipse says "Missing ;" But when I put that in, It highlights the ; saying "Missing ;" again. It keeps on doing that. Any help?
It is on the line marked with:
// Eclipse says 'missing ;' on this line.


What is the error you are getting. may be self descriptive.

Looks like a missing ); but hard to tell without the error and rest of code since the formatting is off.

Your above has several newbie errors and suggests that you might not yet understand how to best use this site. Please have a look at [help], the [tour] as well as the how to ask good questions sections for more information on how to improve your questions and increase your chances of getting decent help. For one, post all pertinent code here with your question and not in a link. For another, please put in some effort in the asking -- explain your code and your problem so that we can easily understand both.

My apologies. sorry.

Rather than apologize, fix your question.

First of all i think you should make the:
final JTextArea textarea = new JTextArea(); 

into a private global variable
also what is the point of this:
private static void setDefaultCloseOperation(int exitOnClose) {

}

I recommend you delete this question and post a new one, after you  consider the comments. When you do, you can copy past your code into your question. After a few attempts you will get it right (0: Don't be discouraged by the comments.

You forgot to add a closing } on your code. You also are not formatting your code well, and this is preventing you from seeing that you're missing the } brace. Use good formatting as it helps you debug your code.

Once you fix this, you'll need to fix the several other errors that will show up. You shouldn't use Frame for instance but rather JFrame....

You should get most of that code out of the static main method, and into the class proper, and you'll want to read the tutorials, both the Swing tutorials and the basic Java tutorials on how to create classes.

@HovercraftFullOfEels I edited the code into question (I'm feeling very charitable at the moment, for some reason), and added a vote to reopen. Care to add another?

@AndrewThompson: done.

You're not matching closing parenthesis on your addActionListener method too. Again good code formatting will help you see this. Also, never add new code to bad -- always fix all compilation problems before trying to add more code to a program.

@AndrewThompson done, the post improved a lot now

Oh and OP should change the title of the question too, since it doesn't say much about the problem

Thanks @Frakcool, only two(?) more needed it seems.

There are many problems in your code:

As stated in the
comments
by @HovercraftFullOfEels:


You're not matching closing parenthesis on your addActionListener method too. Again good code formatting will help you see this.

// Action Listener
jbutton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        textarea.append("Hello");
    } // Eclipse says 'missing ;' on this line.
}); //HERE YOU NEED TO ADD: );


You're extending Frame (Maybe you were trying to extend JFrame)
and creating a JFrame object, choose which one you want to use
(Recommended to create the object instead of extending, because if
you extend a JFrame your class is a JFrame and cannot be
included somewhere else and you're not changing it's functionallity
either so, no need to extend).
You're creating a private static method
private static void setDefaultCloseOperation(int exitOnClose) {}


That method should be public and belongs to JFrame class, I guess your IDE wrote that when you extended Frame instead of JFrame.
Frame belongs to java.awt while JFrame belongs to javax.swing so, they are not the same.

You're creating your windows and every component inside your main
method instead of the constructor
You're adding your components to a Container but never add that container to your JFrame, so you need to call 
frame.setContentPane(c);


So your code should look like this:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.*;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class GUI {
    JFrame frame;
    public GUI() {
        frame = new JFrame("Hello World - YaBoiAce");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setSize(500, 300);

        // Layout //
        frame.setLayout(new BorderLayout());

        // Swing Component //
        final JTextArea textarea = new JTextArea();
        JButton jbutton = new JButton("Click me");

        frame.add(textarea,BorderLayout.CENTER);
        frame.add(jbutton, BorderLayout.SOUTH);

        // Add Component to content pane
        Container c = frame.getContentPane();

        c.add(textarea,BorderLayout.CENTER);
        c.add(jbutton, BorderLayout.SOUTH);

        frame.setContentPane(c);

        // Action Listener
        jbutton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                textarea.append("Hello");
            } // Eclipse says 'missing ;' on this line.
        });
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new GUI());
    }
}


@HovercraftFullOfEels thank you, I forgot to place the program on the EDT, I focused on the other details that I missed that one out

It's a very nice answer. 1+

Ditto the comment of @HovercraftFullOfEels :)

@AndrewThompson coming from both of you it's a honor to read "It's a very nice answer", thank you for that, I've learnt a lot by reading the answers you give :)
