We help IT Professionals succeed at work.

Invalid Method of Declaration?

whocaresaboutit
on
453 Views
Last Modified: 2013-11-23
Hello Experts

I am trying to compile the code bellow, and the compiler returns ALLOT of "class, interface, or enum expected", "<identifier> expected>", "invalid method declaration; return type required" and a few 'illegal start of type"
Thanks!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*; 
public class Reversible extends JApplet implements ActionListener
{
	int time;
	Container c;
	JButton j1,j2,j3;
	JButton show;
	private JTextField t,b;
	String msTop, msBot;
	boolean right = true;
	
	public void int()
	{
		msTop = "ABCDEFGHI";
		msBot = "123456789";
		time = 0;
		Timer clock = new Timer (1000, this);
		clock.start();
		c = getContentPane();
		FlowLayout fx = new FlowLayout();
		fx.setAlignment(fx.CENTER);
		c.setLayout(fx);
		show = new JButton("change");
		show.addActionListener(this);
		t=new JTextField(msTop);
		b=new JTextField(msBot);
		t.setBackround(Color.WHITE);
		b.setBackround(Color.BLACK);
		add(t);
		add(b);
		add(show);
			
	}
	public void paint(Graphics g) 
	{
		
		g.drawString("Welcome to Java!!", 50, 60 );
		
	}
	public void actionPerformed(ActionEvent e)
	{
		String lt,rt,lb,rb;
		
		String command = e.getActionCommand();
		if (command==null);
		{
			if (right)
			{
				lt = msTop.substring(0,1);
				rt = msTop.substring(1);
				lb = msBot.substring(0,msBot.lenght()-1);
				rb = msBot.substring(msBot.lenght()-1);
				msTop = rt+rb;
				msBot = lt+lb;
				System.out.println(msTop+"\n"+msBot);
				t.seText(msTop);
				b.setText(msBot);
			}
			else
			{
				lb = msBot.substring(0,1);
				rb = msBot.substring(1);
				lt = msTop.substring(0,msTop.lenght()-1);
				rt = msTop.substring(msTop.lenght()-1);
				msTop = lb+lt;
				msBot = rb+rt;
				System.out.println(msTop+"\n"+msBot);
				t.setText(msTop);
				b.setText(msBot);
			}
		}
		else
		{
			right = !right;
			System.out.printin("Presed");
		}
	}
}

Open in new window

Comment
Watch Question

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016

Commented:
Typos corrected
import java.awt.*;
import java.awt.event.*; 
import javax.swing.*; 

public class Reversible extends JApplet implements ActionListener {
    int time;
    Container c;
    JButton j1;
    JButton j2;
    JButton j3;
    JButton show;
    private JTextField t;
    private JTextField b;
    String msTop;
    String msBot;
    boolean right = true; 
    public void init() {
	msTop = "ABCDEFGHI";
	msBot = "123456789";
	time = 0; 
	Timer clock = new Timer(1000, this);
	clock.start();
	c = getContentPane(); 
	FlowLayout fx = new FlowLayout();
	fx.setAlignment(fx.CENTER);
	c.setLayout(fx);
	show = new JButton("change");
	show.addActionListener(this);
	t = new JTextField(msTop);
	b = new JTextField(msBot);
	t.setBackground(Color.WHITE);
	b.setBackground(Color.BLACK);
	add(t);
	add(b);
	add(show);
    } 
    public void paint(Graphics g) {
	g.drawString("Welcome to Java!!", 50, 60);
    } 
    public void actionPerformed(ActionEvent e) {
	String lt;
	String rt;
	String lb;
	String rb; 
	String command = e.getActionCommand(); 
	if (command == null) {
	    if (right) {
		lt = msTop.substring(0, 1);
		rt = msTop.substring(1);
		lb = msBot.substring(0, msBot.length() - 1);
		rb = msBot.substring(msBot.length() - 1);
		msTop = rt + rb;
		msBot = lt + lb;
		System.out.println(msTop + "\n" + msBot);
		t.setText(msTop);
		b.setText(msBot);
	    } else {
		lb = msBot.substring(0, 1);
		rb = msBot.substring(1);
		lt = msTop.substring(0, msTop.length() - 1);
		rt = msTop.substring(msTop.length() - 1);
		msTop = lb + lt;
		msBot = rb + rt;
		System.out.println(msTop + "\n" + msBot);
		t.setText(msTop);
		b.setText(msBot);
	    }
	} else {
	    right = !right;
	    System.out.println("Presed");
	}
    }
}

Open in new window

Commented:
-line 14: you are not allowed to name a method using a reserved word (int)
-lines 29, 30: the correct name of the method is setBackground()
-line 47: remove the last semicolon on this line
-lines 53, 54, 65, 66: the correct name of the method is length()
-line 77: the correct name of the method is println()

Please pay more attention when writing the code.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.