Swing error in code

Swing error in code

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

public class SClientsr extends JFrame 
{       
        TextField t1=new TextField(20);
        Label rs=new Label("0");
        JButton b=new JButton("ANS :");
       Panel f=new Panel(new GridLayout(2,2));

        SInterface i;

   public SClientsr()
    {
         super("Client Side");
         setSize(250, 250);
         setLocation(300, 300); 
         getContentPane().add(f,"NORTH");
        f.add("Summation limit");
        f.add(t1);
        f.add(b);
        f.add(rs);
        f.pack();
    }

 b.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
      int n=Integer.parseInt(t1.getText());
            try
            {
                int m=i.summation(n);
                rs.setText(m);
            }
                catch (Exception epx){}
        }
    });
}

    public class SClient
    {
    public static void main(String args[])
        {
         SClientsr sc=new SClientsr();
         sc.setDefaultCloseOperation(EXIT_ON_CLOSE);
         sc.setVisible(true);
        }
    }

I am getting the following errors:

C:\tjm>javac SClient.java
SClient.java:29: error: <identifier> expected
 b.addActionListener(new ActionListener() {
                    ^
SClient.java:29: error: illegal start of type
 b.addActionListener(new ActionListener() {
                     ^
SClient.java:29: error: ')' expected
 b.addActionListener(new ActionListener() {
                        ^
SClient.java:29: error: ';' expected
 b.addActionListener(new ActionListener() {
                                       ^
SClient.java:29: error: illegal start of type
 b.addActionListener(new ActionListener() {
                                        ^
SClient.java:29: error: <identifier> expected
 b.addActionListener(new ActionListener() {
                                         ^
SClient.java:29: error: ';' expected
 b.addActionListener(new ActionListener() {
                                           ^
SClient.java:39: error: class, interface, or enum expected
        });
         ^
SClient.java:40: error: class, interface, or enum expected
}
^
9 errors

PLEASE HELP

View Answers

February 13, 2012 at 10:44 AM

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

 class SClientsr extends JFrame 
{       
        JTextField t1=new JTextField(20);
        JLabel rs=new JLabel("0");
        JButton b=new JButton("ANS :");
       JPanel f=new JPanel(new GridLayout(2,2));

        SInterface i;

   public SClientsr()
    {
         super("Client Side");
         setSize(250, 250);
         setLocation(300, 300); 
         getContentPane().add(f,"NORTH");
        f.add(new JLabel("Summation limit"));
        f.add(t1);
        f.add(b);
        f.add(rs);
        add(f);
        pack();


 b.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
      int n=Integer.parseInt(t1.getText());
            try
            {
                int m=i.summation(n);
                rs.setText(Integer.toString(m));
            }
                catch (Exception epx){}
        }
    });
}
}

    public class SClient
    {
    public static void main(String args[])
        {
         SClientsr sc=new SClientsr();
         sc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         sc.setVisible(true);
        }
    }

Ads









Related Tutorials/Questions & Answers:
Swing error in code
Swing error in code  import java.rmi.*; import java.awt.*; import... the following errors: C:\tjm>javac SClient.java SClient.java:29: error: <...() { ^ SClient.java:29: error: illegal start of type b.addActionListener(new
swing login code
swing login code  code for the login form
Advertisements
Code error
Code error  package trail; import...) read.close(); } } } While using this it shows error as: run... seconds) Hw can i correct this code????????   Basically, the Exception
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form
Java swing code
Java swing code  can any one send me the java swing code for the following: "A confirmation message after the successful registration of login form...(null,"Error!"); text1.setText(""); text2.setText
Java Swing code for zoom in and out
Java Swing code for zoom in and out  hi.......... I require a code in java swing for image zoom in and zoom out can u tell me how it can be done or what is the code plz help
Causing Deadlocks in Swing Code
Causing Deadlocks in Swing At First Consider the Deadlocks A deadlock... that resources. It is a common problem in multithreading. Consider the Sample code... and by adding  the new DesktopPain to the Content Pain it starts the Swing Thread
Java Code Color Function Error
Java Code Color Function Error  Java Code Color Function Error
Java code error - Java Beginners
Java code error  Hi, I am using a MooreQuery to look for neighbors in a grid: MooreQuery query = new MooreQuery(grid, this,(int) (2*myHomeRangeRadius), (int) (2*myHomeRangeRadius)); if(query != null){ for (Object
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
getting error in your login form code
getting error in your login form code  i tried your code for login form but i am getting an error.the error is undefined index userid and password.the code is $fuser=$POST["userid"];. how to solve this problem please help me
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter
can i know the error in this code... am unable to run this code
can i know the error in this code... am unable to run this code  ... code like < >. The for is improper and not completed. Moreover, you have open and close braces properly. Anyways, we have modified your code. Here
<errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors>
for uploading video, today I am getting following error: <errors><...? Thanks   Hi, If your application is receiving such error, then stop... 10-15 minutes error will go away. Thanks   Hi, Such error comes
swing
swing  How to make swing component auto-resizable when JFrame resize
swing
swing  Write a java swing program to delete a selected record from a table
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example
Sending error code to access log of tomcat server from Action class
Sending error code to access log of tomcat server from Action class  How to send an error code (500) to access log file when we get null value in an if condition in Action class? Is anyone aware of this! Thanks
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException
this code gives addition of 2 numbers in j2me..but the code is not executing ..can u pls find out the error...??
this code gives addition of 2 numbers in j2me..but the code is not executing ..can u pls find out the error...??  import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class add1 extends MIDlet implements
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code

Ads