| Author |
Problem in Relation to Action Listener
|
Derek Duggan
Greenhorn
Joined: Jan 14, 2005
Posts: 5
|
|
Hey Small Probelm in the code below i can't get the action listener to work. I've tried using the e.getcommand method on the button also just won't pick up anything for me. Any help with this would be great Cheers Derek import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Create_Mail extends JPanel implements ActionListener { private JButton jcomp1; private JButton b1; private JButton jcomp2; private JButton jcomp3; private JLabel jcomp4; private JLabel jcomp5; private JTextArea jcomp6; private JComboBox jcomp7; private JTextField jcomp8; private JTextField jcomp9; private JButton jcomp10; public Create_Mail() { //construct preComponents String[] jcomp7Items = {"Ireland", "IP 1", "IP 2", "IP 3", "IP 4", "IP 5", "America", "IP1", "IP2", "IP3"}; //construct components jcomp1 = new JButton ("Save E-Mail"); b1 = new JButton ("a"); jcomp2 = new JButton ("Exit System"); jcomp3 = new JButton ("Main Menu"); jcomp4 = new JLabel (" To :"); jcomp5 = new JLabel (" Sublect :"); jcomp6 = new JTextArea (5, 5); jcomp7 = new JComboBox (jcomp7Items); jcomp8 = new JTextField (5); jcomp9 = new JTextField (5); jcomp10 = new JButton ("Calculate Size of E-Mail"); //adjust size and set layout setPreferredSize (new Dimension (482, 488)); setLayout (null); //add components add (b1); add (jcomp1); add (jcomp2); add (jcomp3); add (jcomp4); add (jcomp5); add (jcomp6); add (jcomp7); add (jcomp8); add (jcomp9); add (jcomp10); //set component bounds (only needed by Absolute Positioning) jcomp1.setBounds (35, 360, 100, 20); jcomp2.setBounds (160, 395, 105, 20); jcomp3.setBounds (160, 360, 100, 20); jcomp4.setBounds (25, 30, 100, 25); jcomp5.setBounds (25, 80, 100, 25); jcomp6.setBounds (30, 150, 435, 165); jcomp7.setBounds (365, 35, 95, 20); jcomp8.setBounds (135, 85, 210, 20); jcomp9.setBounds (135, 35, 210, 20); jcomp10.setBounds (285, 360, 180, 20); b1.setBounds (100, 460, 95, 20); } public void actionPerformed( ActionEvent e ) { Object Target = e.getSource(); if(Target == b1) { //System.out.println("fgfd"); System.exit(0); } } public static void main (String[] args) { JFrame frame = new JFrame ("Create_Mail"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); System.out.println("fgfd"); frame.getContentPane().add (new Create_Mail()); frame.pack(); frame.setVisible (true); } }
|
 |
testa lucida
Greenhorn
Joined: Jan 06, 2005
Posts: 5
|
|
Hi Derek, your JPanel is to be the ActionListener - then you should insert code like b1.addActionListener( this ) Regards testalucida
|
 |
 |
|
|
subject: Problem in Relation to Action Listener
|
|
|