Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Buttons lose function when detail of action event changed(Action event handler decoupled from action listener)
Buttons lose function when detail of action event changed [message #1787100] Fri, 18 May 2018 18:14 Go to next message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 42
Registered: March 2018
Member
I wanted to change a large number of JTextFields that are filled in response to JButtons. When I changed a few details, all of the buttons lost their functions. Is there any way to prevent this from happening:

The original was:
	
		JButton btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				
				try 
				{
					//String query = "select * from EmployeeInfo";
					String query = "insert into EmployeeInfo (EID, Name, Surname, Password, Age) values(?, ?, ?, ?, ?)";
					PreparedStatement pst = connection.prepareStatement(query);
					pst.setString(1, textFieldEID.getText());
					pst.setString(2, textFieldName.getText());
					pst.setString(3, textFieldSurname.getText());
					pst.setString(4, textFieldPassword.getText());
					pst.setString(5, textFieldAge.getText());				
					pst.execute();
					
				//	ResultSet rs = pst.executeQuery();
					JOptionPane.showMessageDialog(null, "Data saved");
					
					pst.close();
				//	rs.close();  
				}
				catch (Exception e1) 
				{
					JOptionPane.showMessageDialog(null, "Data save failed");
				}
				refreshTable();
			}
		});
		btnSave.setBounds(64, 80, 117, 29); 
		contentPane.add(btnSave);

Change the above to the following to the following and all function disappears. The textbox is still visible when the program runs, but the button does nothing.

		JButton btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) 
			{
				
				try 
				{
					//String query = "select * from TM";
					String query = "insert into TM (EID, BKG1, QUES1, ANSW1, RESP1 , ImageID) values(?, ?, ?, ?, ?)";
					PreparedStatement pst = connection.prepareStatement(query);
					pst.setString(1, textFieldEID.getText());
					pst.setString(2, textFieldBKG1.getText());
					pst.setString(3, textFieldSurname.getText());
					pst.setString(4, textFieldPassword.getText());
					pst.setString(5, textFieldAge.getText());	
					pst.setString(6, textFieldImageID.getText());
					pst.execute();
					
				//	ResultSet rs = pst.executeQuery();
					JOptionPane.showMessageDialog(null, "Data saved");
					
					pst.close();
				//	rs.close();  
				}
				catch (Exception e1) 
				{
					JOptionPane.showMessageDialog(null, "Data save failed");
				}
				refreshTable();
			}
		});
		btnSave.setBounds(64, 80, 117, 29); 
		contentPane.add(btnSave);


With lots of screen elements to replace and recode, I've wasted days of work. How can I prevent this unwanted change from happening?
Re: Buttons lose function when detail of action event changed [message #1787106 is a reply to message #1787100] Fri, 18 May 2018 19:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29384
Registered: July 2009
Senior Member
This isn't the best forum to ask about Swing controls. If Googling doesn't turn up and answer, try StackOverflow.
Re: Buttons lose function when detail of action event changed [message #1787108 is a reply to message #1787106] Fri, 18 May 2018 21:04 Go to previous message
Patrick Moran is currently offline Patrick MoranFriend
Messages: 42
Registered: March 2018
Member
It took me a very long time to figure out what was going on. I suspect that other new Eclipse users, being people who are trying to learn Java, will have the same question. There should at least be a FAQ or something to let new users know their computer is haunted. ;-)
Previous Topic:SSLHandshakeException unable to find valid certification
Next Topic:Can't Unzip All Eclipse Files: "Path too long"
Goto Forum:
  


Current Time: Sun Jun 17 22:20:39 GMT 2018

Powered by FUDForum. Page generated in 0.02604 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top