Swing代码分析(事件监听方法四)

package nau.ui; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; /** * 功能: * * @author wzj * */ public class SwingCommonActionListenerTestTool extends JFrame implements ActionListener { private JPanel jPanel = new JPanel(); private JButton jButtonO = new JButton("buttonOne"); private JButton jButtonT = new JButton("buttonTwo"); private JLabel jLabelO = new JLabel(); public SwingCommonActionListenerTestTool() { this.add(jPanel); jPanel.add(jButtonO); jPanel.add(jButtonT); jPanel.add(jLabelO); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("SwingCommonActionListenerTestTool"); this.setBounds(100, 100, 400, 200); this.setVisible(true); jButtonO.addActionListener(this); jButtonT.addActionListener(this); } /** * * @param args */ public static void main(String[] args) { new SwingCommonActionListenerTestTool(); } public void actionPerformed(ActionEvent e) { if (e.getSource() == jButtonO) { this.jLabelO.setText("click on jButtonO "); } else if (e.getSource() == jButtonT) { this.jLabelO.setText("click on jButtonT "); } else { this.jLabelO.setText("click any thing"); } } }

你可能感兴趣的:(swing,String,Class,代码分析)