Reputation: 10575
How do i execute the Java Program when i select the radio button
class abc implements ActionListener {
public static void main (String args[]){
JFrame frame = new JFrame("Test Frame");
JPanel panel = new JPanel();
Container contpane; contpane = frame.getContentPane();
//added all Radio Buttons
JRadiobutton jb = new
JRadioButton("test1"); JRadiobutton
jb1 = new JRadioButton("test2");
jb.addActionListener( this );
jb.addActionListener( this );//when i say "this" it is giving complie time
error becaus this keyword will not be accesible
}
public void actionPerformed(ActionEvent evt){
How do i create the JTextArea and
Execute the Java class abc.java in
that JTextArea How do i add the
JTextArea to the panel and Frame
what should i write inorder to execute
the java class say abc.java
}
}
Upvotes: 1
Views: 156
Reputation: 109027
To answer your first question, restructure you code to create the frame and it's contents in your class's constructor like this
class abc implements ActionListener {
public static void main(String args[]) {
new abc();
}
abc() {
JFrame frame = new JFrame("Test Frame");
JPanel panel = new JPanel();
Container contpane;
contpane = frame.getContentPane();
// added all Radio Buttons
JRadiobutton jb = new JRadioButton("test1");
JRadiobutton jb1 = new JRadioButton("test2");
jb.addActionListener(this);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
}
}
and I don't understand the other questions.
Upvotes: 2