I am having issues with connecting components within Swing in a way where they would interact or exert a flow of action. My plan is to disable/enable a JTextPane when a button is pushed, and then input numbers so that the program can start the computation. So far here is where I am stuck at:
private JPanel contentPane;
protected JTextPane txtpnA;
protected JTextPane txtpnB;
protected JTextPane txtpnC;
/* Button 'a' **/
JButton btnA = new JButton("a");
btnA.setBackground(Color.YELLOW);
btnA.setBounds(47, 54, 89, 23);
btnA.setActionCommand("a");
btnA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
} {
}
});
contentPane.add(btnA);
/* TextPane 'a' **/
txtpnA = new JTextPane();
txtpnA.setBounds(47, 88, 89, 20);
contentPane.add(txtpnA);
txtpnA.setBorder(BorderFactory.createLineBorder(Color.black));
And here is the method:
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if(command.equals("a"))
{
txtpnA.setEnabled(false);
} else if(command.equals("b"))
{
txtpnB.setEnabled(false);
} else if(command.equals("c"))
{
txtpnC.setEnabled(false);
}
}
}
I am having hard time to find articles regarding communication between JComponents. If you could also suggest a verbose source, it'd be much appreciated.