Class, interface, or enum expected errors in BULK

Solved/Closed
zlloyd1 Posts 10 Registration date Tuesday 11 December 2012 Status Member Last seen 4 February 2013 - 27 Jan 2013 à 19:49
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 - 29 Jan 2013 à 20:35
Hello, I am trying to get the following program to run, but when I try to compile it there are 43 errors, complaining about almost every line of code in it....
The errors are pretty much all the same error,
error: class, interface, or enum expected
This is the code:
public newclass2 extends JFrame implement ActionListener
{
  private String s1, s2;
  static String s3;
  private JFrame f = new JFrame("text testing");
  private JTextField txt = new JTextField(24);
  private JTextField txt2 = new JTextField(24);
  private JButton b1 = new JButton("Submit");
  private JButtonm b2 = new JButton("Exit");
  public newclass2(){
    f.setLayout(new BorderLayout());
   JPanel p = new JPanel();
    p.setLyout(new FlowLayout());
    p.add(new JLabel("text1"));
    p.add(txt);
    p.add(new JLabel("text2");
    p.add(txt2);
    f.add(p, BorderLayout.CENTER);
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(b1);
    p2.add(b2);
    add.addActionListener(this);
    open.addActionListener(this);
    f.add(p2, BorderLayout.SOUTH);
    f,setVisible(true);
    f.setSize(480,480);
}
    public void actionPerformed(ActionEvent e)
{
      if(e.getSource()==b1){
      txtemp1 = ("");
      txttemp2 = ("");
      txttemp1 =  txt.getText().trim();
      txttemp2 = txt2.getText().trim();
      s3 =("text here"+txttemp1) + (txttemps2);
      String data = newclass.s3;
    try{ BufferedWriter readz = BufferedWriter(new FileWriter(new File      

("C:/users/zlloyd1/desktop/test1.doc"));
      readz.write(data);
      readz.newLine();
      readz.close();
      System.out.rpintln("Done");
    }catch(Exception e2){System.out.println("Error message text"));
}
    if(e.getSOurce()==b2){
      JFileChooser choosa = new JFileCHooser("C:/users/zlloyd1/desktop/test1.doc"
      int x = choosa.showOpenDialog(null);
      if(x == JFileChooser.APPROVE_OPTION){
      File file = choosa.getSelectedFile();
    try(
      Desktop.getDesktop().open(file);}catch(Exception e3){System.out.println("Error text");}
}
    private static void main(String args[]){
      new newclass2();
  }
}

I cannot, for the life of me, see what it going wrong here, and I am hoping that an outside opinion would be better suited to tell me why this won't run??


Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
29 Jan 2013 à 07:29
stupid question but is your file named "newclass2.java" (case included)

Beside wrong calls, are you not missing

public class newclass2 extends JFrame implement ActionListener

I would suggest comment of every thing and start with empty shell of class

public class newclass2 extends JFrame implement ActionListener{
}


and one by one start adding lines. It will help you in identifying area where you have issues
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
29 Jan 2013 à 07:47
I have not tested it but here is the code
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class newclass2 extends JFrame implements ActionListener {

	private String s1, s2;
	private String s3;

	private JFrame f = new JFrame("text testing");

	private JTextField txt = new JTextField(24);
	private JTextField txt2 = new JTextField(24);
	private JButton b1 = new JButton("Submit");
	private JButton b2 = new JButton("Exit");

	public newclass2() {

		f.setLayout(new BorderLayout());

		JPanel p = new JPanel();
		p.setLayout(new FlowLayout());
		p.add(new JLabel("text1"));
		p.add(txt);
		p.add(new JLabel("text2"));
		p.add(txt2);
		f.add(p, BorderLayout.CENTER);

		JPanel p2 = new JPanel();
		p2.setLayout(new FlowLayout());
		p2.add(b1);
		p2.add(b2);

		b1.addActionListener(this);
		b2.addActionListener(this);

		f.add(p2, BorderLayout.SOUTH);
		f.setVisible(true);
		f.setSize(480, 480);

	}

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == b1) {
			// txtemp1 = ("");
			// txttemp2 = ("");
			String txttemp1 = txt.getText().trim();
			String txttemp2 = txt2.getText().trim();
			String s3 = ("text here" + txttemp1) + (txttemp2);
			String data = s3;
			try {
				BufferedWriter readz = new BufferedWriter(new FileWriter(
						new File("C:/users/zlloyd1/desktop/test1.doc")));
				readz.write(data);
				readz.newLine();
				readz.close();
				System.out.println("Done");
			} catch (Exception e2) {
				System.out.println("Error message text");
			}
		}

		if (e.getSource() == b2) {
			JFileChooser choosa = new JFileChooser(
					"C:/users/zlloyd1/desktop/test1.doc");
			int x = choosa.showOpenDialog(null);
			if (x == JFileChooser.APPROVE_OPTION) {
				File file = choosa.getSelectedFile();
				try {
					Desktop.getDesktop().open(file);
				} catch (Exception e3) {
					System.out.println("Error text");
				}
			}
		}
	}

	public static void main(String args[]) {
		new newclass2();
	}
}
Yes, it is newclass2.java file.
Beside wrong calls, are you not missing
public class newclass2 extends JFrame implement ActionListener
I am not sure exactly what you are saying here, but I have that line in my code??
Also, what wrong calls please??
Okay, I see what you mean, I think:
It should be public class newclass2 extends JFrame implements ActionListener
My stupid, but as I said, I knew it was something small I didn't see that I had done wrong!!
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
29 Jan 2013 à 20:35
There are many other issues too. Compare updated code and the one provided