• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with actionevent  RSS feed

trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my program why the control is not going to actionPerformed(ActionEvent ae)method. i have debugged by giving the System.out.println statements

import java.net.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.awt.event.*;

public class TestPanel1 extends JPanel {

private JLabel blankSpace;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JLabel jLabel7;
private JLabel jLabel8;
private JLabel jLabel9;
private JLabel jLabel10;
private JLabel jLabel11;

public JTextField tdomain;
public JTextField tserver;

public JButton create;

private JLabel welcomeTitle;
private JPanel contentPanel;

private JLabel iconLabel;
private ImageIcon icon;

public TestPanel1() {

iconLabel = new JLabel();
contentPanel = getContentPanel();
contentPanel.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10)));

icon = getImageIcon();

setLayout(new java.awt.BorderLayout());

if (icon != null)

iconLabel.setBorder(new EtchedBorder(EtchedBorder.RAISED));

add(iconLabel, BorderLayout.WEST);

JPanel secondaryPanel = new JPanel();
secondaryPanel.add(contentPanel, BorderLayout.NORTH);
add(secondaryPanel, BorderLayout.CENTER);

private JPanel getContentPanel() {

JPanel contentPanel1 = new JPanel();
JPanel jPanel1 = new JPanel();

welcomeTitle = new JLabel();
blankSpace = new JLabel();
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel7 = new JLabel();
jLabel6 = new JLabel();
jLabel8 = new JLabel();
jLabel9 = new JLabel();
jLabel10= new JLabel();
jLabel11= new JLabel();
tdomain = new JTextField(6);
tserver = new JTextField(5);
create = new JButton();

contentPanel1.setLayout(new java.awt.BorderLayout());

welcomeTitle.setFont(new java.awt.Font("MS Sans Serif", Font.BOLD, 11));
welcomeTitle.setText("Welcome to the Wizard Dialog!");
contentPanel1.add(welcomeTitle, java.awt.BorderLayout.NORTH);

jPanel1.setLayout(new java.awt.GridLayout(0, 1));

jLabel1.setText("This is an example of a wizard dialog, which allows a user to traverse");
jLabel2.setText("a number of panels (while entering data) until the wizard has enough ");
jLabel3.setText("information to perform whatever end function is necessary. Note that");
jLabel4.setText("panels are not necessarily ordered in a linear fashion, but instead in");
jLabel5.setText("a tree-like manner (e.g., there may be more than one panel with a");
jLabel7.setText("'Finish' button, and it depends on the user's entries as to how they ");
jLabel6.setText("traverse the path). That's not the case with this example, however.");
jLabel9.setText("Press the 'Next' button to continue....");
jLabel10.setText("Enter the domain name");
jLabel11.setText("Enter the server name");


contentPanel1.add(jPanel1, java.awt.BorderLayout.CENTER);

return contentPanel1;

public void actionPerformed(ActionEvent ae)
String s=ae.getActionCommand();
String s1=tdomain.getText();
String str1 = "java -Dweblogic.Domain=" + s1;
FileWriter f= new FileWriter("d:/puvvada/super.bat");
f.write(str1+ "weblogic.Server");
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd /c start d:/puvvada/super.bat");
System.out.println("after executing the batch file");
}catch(Exception e)


private ImageIcon getImageIcon() {
return new ImageIcon((URL)getResource("clouds.jpg"));

private Object getResource(String key) {

URL url = null;
String name = key;

if (name != null) {

try {
Class c = Class.forName("com.nexes.test.Main");
url = c.getResource(name);
} catch (ClassNotFoundException cnfe) {
System.err.println("Unable to find Main class");
return url;
} else
return null;


please see where i had done wrong
Campbell Ritchie
Posts: 55772
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only have an ActionEvent going to an ActionListener, so you have to get java.awt.event.ActionListener into your class.
Fortunately ActionListener is an interface . . . .
Ram Mohan
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class TestPanel1 extends JPanel implement ActionListener


Ram Mohan.
Campbell Ritchie
Posts: 55772
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is one way to do it. I had a long discussion with somebody on another forum last week, which I hope you will find on this thread, on java(intermediate) about implementing mvc model or observer. There are about three possible ways to implement ActionListeners, and I personally think getting the enclosing JFrame to implement it is an inelegant solution to the problem, although other people will doubtless disagree.

The thing about computing is, that there isn't a "right" way to do things, there can be lots fo "right" ways. But there are also lots of wrong ways.

To decide which format to put you ActionListener in (there are three,
  • addActionListener(this)
  • separate classes, usually private inner classes, but you could use a public class in a separate file for something like "CloseListener" which may be reused frequently
  • and the anonymous inner class
  • ) really depends on two things: will you be using the same listener more than once. If you have listeners which do similar things, eg GreenListener, RedListener, you might be better to add them as,
    Anyway, you pays your money and you takes your choice, as they say in London.
    I have never tried a public class in a different file for ExitListener; I presume it works.

    Try all the different options and see which works . . . .
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!