Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

ActionListener not recognized under Solaris

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I have an actionListener which runs under Windows but when I move the jar file to Solaris the only listener that works is the MouseEventListener.
I need help fast...thanks in advance.
-Jason
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the code of your ActionListener?

Because I know that the Solaris system supports ActionListeners... maybe there is a system dependent call being made in yours, or maybe there are different versions of Java installed on the machines...

-Nate
 
Jason Travis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What follows is the code you requested...
public class LoginFrame extends JFrame {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JLabel jLabelUserName = new JLabel();
JLabel jLabelPassword = new JLabel();
JPasswordField jPasswordField = new JPasswordField();
JTextField jUserNameField = new JTextField();
JButton QuitButton = new JButton();
JPanel jPanel2 = new JPanel();
JButton SubmitButton = new JButton();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
GridBagLayout gridBagLayout3 = new GridBagLayout();
GridBagLayout gridBagLayout4 = new GridBagLayout();
GridBagLayout gridBagLayout5 = new GridBagLayout();
private Object x = this;
boolean resizable = false;
boolean generateNotification90 = false;
boolean generateNotification91 = false;
boolean generateNotification92 = false;
/**Construct the frame*/
public LoginFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));
this.setResizable(resizable);
this.setTitle("Login");
jPanel1.setLayout(gridBagLayout2);
jLabelUserName.setToolTipText("");
jLabelUserName.setHorizontalAlignment(SwingConstants.CENTER);
jLabelUserName.setHorizontalTextPosition(SwingConstants.RIGHT);
jLabelUserName.setText("User Name");
jLabelPassword.setToolTipText("");
jLabelPassword.setHorizontalAlignment(SwingConstants.CENTER);
jLabelPassword.setHorizontalTextPosition(SwingConstants.CENTER);
jLabelPassword.setText("Password");
jPanel1.setToolTipText("");
QuitButton.setText("Exit");
QuitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
QuitButton_actionPerformed(e);
}
});
QuitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
QuitButton_mousePressed(e);
}
});
jPanel2.setLayout(gridBagLayout5);
SubmitButton.setText("Submit");
SubmitButton.setEnabled(true);
SubmitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submitButtonActivated();
}
});
SubmitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent f) {
if (f.getID() == f.MOUSE_PRESSED) {
submitButtonActivated();
}
}
});
jPanel3.setLayout(gridBagLayout4);
jPanel4.setLayout(gridBagLayout3);
contentPane.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(36, 29, 0, 67), 0, 13));
jPanel1.add(jLabelUserName, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(40, 22, 0, 0), 18, 5));
jPanel1.add(jLabelPassword, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(37, 22, 13, 0), 22, 5));
jPanel1.add(jPasswordField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(35, 18, 13, 1), 72, 3));
jPanel1.add(jUserNameField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(40, 17, 0, 1), 119, 2));
contentPane.add(jPanel2, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(26, 61, 34, 67), 0, 5));
jPanel2.add(jPanel3, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 0, 0), 0, 0));
jPanel3.add(SubmitButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(17, 9, 16, 9), 0, 0));
jPanel2.add(jPanel4, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 90, 0, 0), 0, 0));
jPanel4.add(QuitButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 9, 17, 9), 16, 0));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void QuitButton_mousePressed(MouseEvent e) {
ConfirmationsAndNotifications confirm = new ConfirmationsAndNotifications(this, 8);
this.setEnabled(false);
}
void QuitButton_actionPerformed(ActionEvent e) {
ConfirmationsAndNotifications confirm = new ConfirmationsAndNotifications(this, 8);
this.setEnabled(false);
}
void submitButtonActivated() {
try {
//-----------Added to replace deprecated getText() method------------------
jUserNameField.selectAll();
jPasswordField.selectAll();
String userName = jUserNameField.getSelectedText();
String passWord = jPasswordField.getSelectedText();
//---------End Added to replace deprecated getText() method-------------------
if (userName == null | | passWord == null) {
if (userName == null && passWord != null) {
// generate window telling user to supply a username
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 90);
} else if (userName != null && passWord == null) {
// generate window telling user to supply a password
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 91);
} else {
// generate window telling user to supply both a username
// and a password
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 92);
}
}else if (userName.equals("pervigil") && passWord.equals("pervigil")) {
this.hide();
MainFrame f = new MainFrame(this); // create a new MainFrame object
MainFrame currentMainFrame = f;
if (!f.imageFileDoesNotExistOrNotFile) {
f.dispose();
f.setJMenuBar(currentMainFrame.mb); // add the MenuBar object to this instance of MainFrame
this.dispose();
if (f.getConnectionStatus()) {
f.dispose();
} else {
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (com.pervigil.PingUI.packFrame) {
f.pack();
} else {
f.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = f.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
f.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
f.setVisible(true);
}
} else {
this.dispose();
}
} else {
System.exit(1);
} // end of if statment to check username and password fields text
} catch (Exception i) {
System.out.println("NullPointerException or ClassCastException occured during Submitbutton actionPerformed method" + i);
}
} // end of submitButtonActivated method
} // end of LoginFrame class
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK... I got your code running... had to comment out references to other classes... How exactly is the actionListener "not working"? I ran it on both a Windows NT machine and a Solaris machine and they both seemed to work the same... The problem may be in a class that the actionListener is calling...

-Nate
 
Jason Travis
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that under Win2K you can actually perform either a mouse click on say the Submit button or hit the enter key to perform the same event. However, I moved the jar file over to the Solaris 8 system and ran the program and the application would not recognize the enter key (when pressed) as an action event. The application would simply do nothing.
I appreciate all you help. Thank you for your suggestions.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under Solaris the space bar activates buttons and such... not the Enter key...

-Nate
 
There is no "i" in denial. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic