Wats wrong with ActioListener and ........ in this code

i m declaring a method with syntax .....
public void addWidgets() {
but the error comes .. illegal start of expression ..... ???
also i m using actionlistener interface in class definition ...
but the error comes .. no actionperformmed method defined ... although i have defined it ..???
''''' i wanna show 2 text fields and when user enters the no. n press swap button the swaped values r shoen in labels '''''''''''
----------------------------- here is the code -----------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Swap1 implements ActionListener {
   private static String lbl = " becomes : " ;
   JFrame frame;
    JPanel panel;
   JLabel aLabel, blabel;
  JTextField aText, bText;
  JButton button ;
// Constructor
  public Swap1() {
// Create the frame and container
  frame = new JFrame ("Swapping two values");
  panel = new JPanel();
  panel.setLayout(new GridLayout(3,2));
  addWidgets();
  frame.getContentPane().add(panel,BorderLayout.CENTER);
  frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
// show frame
   frame.pack();
  frame.setVisible(true);
// Create and add the widgets to the panel
  private void addWidgets() {
    aLabel = new JLabel(lbl, SwingConstants.CENTER);
    bLabel = new JLabel(lbl, SwingConstants.CENTER);
    aText = new JTextField(2);
    bText = new JTextField(2);
   button = new JButton("Swap...");
  button.addActionListener(this);
//Adding the widgets to the panel
  panel.add(aText);
  panel.add(aLabel);
  panel.add(bText);
  panel.add(bLabel);
panel.add(button);
  aLabel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  bLabel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
// Implementing the actionlistener
  public void actionPerformed(ActionEvent event) {
  int a = (int)(Double.parseDouble(aText.getText()));
  int b = (int)(Double.parseDouble(bText.getText()));
  int c = a;
  a = b;
  b = c;
  aLabel.setText(lbl + a);
  bLabel.setText(lbl + b);
// main method
public void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {}
Swap1 sp = new Swap1();
}

i m declaring a method with syntax .....
public void addWidgets() {
no you have private but either way you can't throw in code for one method all willy-nilly inside of another method or constructor.
take the code for your addWidgets out an put it at the end of your file and then where you call it in the constuctor is should just be addWidgets();

Similar Messages

  • My phone has been asked to be plugged into itunes for the past hour or so, and it has been plugged in the whole time... i have tried holding in both buttons too turn it on and nothing is happening... whats wrong with it and how do i fix this :(?

    My phone has been asked to be plugged into itunes for the past hour or so, and it has been plugged in the whole time... i have tried holding in both buttons too turn it on and nothing is happening... whats wrong with it and how do i fix this :(?

    Does iTunes see your phone?
    Do you have a PC or a Mac?
    ~Lyssa

  • I bought my i pod touch from us but i live in india .i have been using this from many days fr just a few days before something went wrong with it and the date and time has changed what do i do?

    i bought my i pod touch from us but i live in india .i have been using this from many days fr just a few days before something went wrong with it and the date and time has changed what do i do?

    Have you went to Settings>General Time&Date and correct the time.  Make sure the time zone is correct too.  Also go to Settings>General>Inernational and make sure the Gergorian calender is selected.

  • Safari tries repeatedly to open a page. The page partially opens but then Safari reports that there's something wrong with page and I get an error message. This is happening at too many web sites for one site to be having issues.

    Safari tries repeatedly to open a page. The page partially opens but then Safari reports that there's something wrong with page and I get an error message. This is happening at too many web sites for one site to be having issues.

    I have a similar problem, Safari cannot load a complet page. It stalls e.g. ["38 of 42"]. sometimes it will complete loading after a long wait. just as often it will never complete the page,
    The same thing happens in chrome and firefox but safari on my iPad works just fine.
    I have the latest version of everything
    I assume there is a system problem but cleaning up permissions does not help

  • HT4623 After updated to iOS 7.1.1, my iPad went wrong with time and date. How can I solve this?

    I have updated my iPad mini to iOS 7.1.1 recently. After updated, it went wrong with time and date even I tried to restart it or set manual time/date or set auto time/date. How can I solve this problem?

    Hello Phirum OL,
    Here is an article that will help you adjust the date and time settings on your iPad:
    iOS: Troubleshooting issues with date and time
    http://support.apple.com/kb/ts3920
    Learn the steps to take if your device has any of the following issues with the date and time.
    Incorrect date or time
    Wrong time zone being set automatically
    Issues related to automatically switching with daylight savings time
    Thank you for contributing to Apple Support Communities.
    Cheers,
    BobbyD

  • TS2570 My Mac is stuck on grey screen what's wrong with it and am I going to lose everything

    My Mac is stuck on grey screen what's wrong with it and am I going to lose everything

    Hopefully you have a backup, but...
    Could be many things, we should start with this...
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)
    If perchance you can't find your install Disc, at least try it from the Safe Boot part onward.

  • My iPhone 5 screen is black and will not come back on. The phone still works when paired with my vehicles Bluetooth what's wrong with it, and can I fix it?

    My iPhone 5 screen is black and will not come back on. The phone still works when paired with my vehicles Bluetooth what's wrong with it, and can I fix it?

    I have a similar problem.  I restored my iPhone 5 to the latest available OS.  After completing the process the phone never restarted.  The phone was fully charged when I restored it but now refuses to charge past the red battery icon.  I have been able to get the phone in UFD mode several times and have been able to load the new OS on the phone.  The Apple logo does come on and the software fully loads.  iTunes tells me the phone will restart but never does.  I left it to charge all night but it never appeared to load the battery.  This morning I went to the Grand Central Terminal apple store for help.  A woman at the store plugged the phone in but it never charged.  She absolutely refused to believe that I got my phone in UFD mode and loaded any software on.  I don't think it is a battery issue.  The only solution I was given was to buy a new phone.  Repairing it was out of the question.  At this point the phone is completely useless.  Thanks in advance for the help.

  • Trying to register with ePrint and getting error code.Ajax submit failed: error = 403, Forbidden.

    Trying to register with ePrint and getting error code.Ajax submit failed: error = 403, Forbidden. I need help??

    To bypass this error attempt either a restart of your computer, or use an alernate broser such as firefox or chrome. If you already have another browser the latter may be the easier fix.
    Jon-W
    I work on behalf of HP
    Please click “Accept as Solution ” on the post that solves your issue to help others find the solution.
    Click the KUDOS STAR on the left to say “Thanks” for helping!

  • My gen 4 ipod shuffle is not showing the green light when I switch it on (Green area shown). But when I plug it into the computer there initial orange blink and then solid orange. What wrong with it and how can I fix it.

    My gen 4 ipod shuffle is not showing the green light when I switch it on (Green area shown). But when I plug it into the computer there initial orange blink and then solid orange. What wrong with it and how can I fix it. 

    Hello Korawees,
    I was researching the issue you are describing and had a recommendation. The device is very simple, so the software troubleshooting for it is pretty limitted so I think you shoud restore the iPod shuffle and re sync the content. That way, if it is a software issue, this will fix it. Here is the article named Restoring iPod shuffle to factory settings found here: http://support.apple.com/kb/HT1481.
    Before Starting
    It is important to understand the difference between "update" and "restore." Update does not affect your settings or songs, it simply installs updated software that controls iPod shuffle. Restore erases the disk and restores iPod shuffle to its original factory condition with updated software. If you only need to update iPod shuffle, this should be done on the computer where music is normally synced. Updating on another computer will result in all songs being removed from iPod shuffle.
    Warning: Because Restore erases all songs and files on iPod shuffle, make sure to back up any files you've saved on iPod shuffle. Your songs, podcasts, and audiobooks can be synced back to your iPod shuffle if the items are part of your iTunes library.
    How to restore iPod shuffle
    Ensure that you have an active Internet connection as new versions of iTunes and iPod Software may need to be downloaded to your computer.
    Download and install the latest version of iTunes if you do not already have it installed.
    Open iTunes, and then connect iPod shuffle to your computer.
    After a few moments, iPod shuffle will appear in the Devices section on the left side of the Tunes window.
    Select iPod shuffle under Devices and you will see information about it appear in the main iTunes window under the Summary tab/button for iPod shuffle (3rd and 4th generation) or the Settings tab/button for iPod shuffle (1st or 2nd generation).
    The Version section tells you whether iPod shuffle is up to date or needs a newer version of the software.
    Click the Restore button. You will be presented with one or more restore options that may prompt iTunes to automatically download the latest iPod Software. The 4-possible restore options are:
    Restore Option 1: Restore - Restores with same iPod Software version already on iPod.
    Restore Option 2: Use Same Version - Restores with same iPod Software version already on iPod even though a newer version is available.
    Restore Option 3: Use Newest Version - Restores with the latest iPod Software currently on your computer.
    Restore Option 4: Restore and Update - Restores after downloading the latest iPod Software on your computer.
    If you are using a Mac, a message will appear prompting you to enter an administrator’s name and password.
    A progress indicator will appear on the computer screen indicating that the restore process has started. Do not disconnect iPod shuffle during the restore process.
    After the restore process is complete, the iPod shuffle's status light will flash orange continuously. The iPod Setup Assistant window will appear asking you to name your iPod and choose your syncing preferences as you did when you connected your iPod shuffle for the first time.
    When you come to step 7, I recommend Restore Option 4.
    Take care,
    Sterling

  • HT1688 My iphone 5 won't charge and it's in perfect condition, I dont drop it and it's not cracked. I tried multiple chargers, none of them are damaged and my outlets work with other things so the problem is my phone. What's wrong with it and what should

    My iphone 5 won't charge and it's in perfect condition, I dont drop it and it's not cracked. I tried multiple chargers, none of them are damaged and my outlets work with other things so the problem is my phone. What's wrong with it and what should I do? Please help me I need my phone for work.

    Make sure there's nothing blocking a contact in the charging port of the phone.

  • My optical drive will not read any music cds now or recognize a blank cd in the drive. it might read some data discs. what is wrong with it and how do i fix it?

    My optical drive will not read any music cds or recognize a blank cd. it might read some data cds. what is wrong with it and how can i fix it?

    The optics might be dirty. Try running a cleaning CD through it and see if that makes a difference.
    If not, it will have to be replace.
    Allan

  • I have been trying to open itunes that has already been installed. But, the thing is it never opens and when i do right click and trouble shoot also, it doesnt open. I dont whats wrong with itunes and my comp is 64 bit windows 7. Can somebody please help

    I have been trying to open itunes that has already been installed. But, the thing is it never opens and when i do right click and trouble shoot also, it doesnt open. I dont whats wrong with itunes and my comp is 64 bit windows 7. Can somebody please help

    no its 64 bit version of itunes. Can you please help me. I am not able to sync my iphone.

  • I bought 120 gold in Haypi dragon on Mar 12 and 15 2012 , but I havenot received them yet.What is wrong with it ,and when i can reveive them ?

    I bought 120 gold in Haypi dragon on Mar 12 and 15 2012 , but I havenot received them yet.What is wrong with it ,and when i can reveive them ?

    For in-app purchases you should contact the developer's customer support, assuming there is one.

  • My ipod comes up with a green screen when i turn it on. I did once eject it safely like a flash drive instead of through itunes. What exactly is wrong with it and can it be fixed?

    My ipod comes up with a green screen when i turn it on. I did once eject it safely like a flash drive instead of through itunes. What exactly is wrong with it and can it be fixed?

    What exactly is wrong with it and can it be fixed?
    If you have AppleCare and/or iPod Nano is still under warranty, give them a call.  If not, take the computer to your local Apple Store or AASP.  The staff will tell you what is wrong w/it and let you know if it can be fixed after it is examined.

  • Right now I am working in a temporary site format. I am hosting the website on my own computer. How to I take it from a temporary site to a live site? Do I need to upgrade my service with abode and does this cost more per month?

    Right now I am working in a temporary site format. I am hosting the website on my own computer. How to I take it from a temporary site to a live site? Do I need to upgrade my service with abode and does this cost more per month?

    Hi Traci,
    To push the site live, you will need to:
    Publish a trial site on BC (File menu> Publish)
    Then, go to the admin dashboard of your site and the launch the site live by paying for it or redeeming a free site.
    Add domain to the site
    Change name-servers at domain registrar
    For steps 3 and 4, kindly refer to the following link:
    http://docs.businesscatalyst.com/user-manual#!/site-settings/site-domains/change-the-domai n-name-of-your-site
    The following link might also be helpful:
    Launching a Muse Site | Adobe Muse CC
    Regards,
    Sonam

Maybe you are looking for