Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt regarding java gui events

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
i am new to java so i have lots of doubts coming up while i am reading and coding some basic programs in java .
my doubt is in the following code
[code=java]
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Testing {
static JTextArea ta;
static JButton b1;
static JButton b2;
static JButton b3;
public static void main(String []args)
{
JFrame f = new JFrame ("sample form");
ta= new JTextArea(20, 20);
b1 = new JButton("click here");
b2= new JButton("SUBMIT");
f.setLayout(new FlowLayout());
f.add(ta);
f.add(b1);
f.add(b2);
b1.addActionListener(new BHandler());
b2.addActionListener(new BHandler());
b1.setActionCommand("b1");
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


}
}
class BHandler implements ActionListener
{ int count;
public void ActionPerformed(ActionEvent e){
count++;
if(e.getActionCommand().equalsIgnoreCase("b1"))
{
ta.setText("BHandler"+ count +""+ e.getActionCommand());
} else
JOptionPane.showMessageDialog(null, e);
}
}
and in this error comes that ta symbol is not found in class BHandler .
please some one do reply what is wrong in the code
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
shweta, welcome to the Ranch! When you have a question, please CarfullyChooseOneforum <- link

I'm locking this thread. The discussion can continue in https://coderanch.com/t/607449/GUI/java/query-related-event-handling-gui
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic