| | |
ActionListener
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2007
Posts: 10
Reputation:
Solved Threads: 0
Lemme first greet all my beloved fellows and i would love to give you all credits for helping each other with problems concerning java!!!
I have a problem with listening methods in my code.the only respond i get is the exit part of my buttons....please i would be happy to get help from you fellows with my actionlistening methods....i was testing with the exit method.
I have a problem with listening methods in my code.the only respond i get is the exit part of my buttons....please i would be happy to get help from you fellows with my actionlistening methods....i was testing with the exit method.
Java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Layers // driver function { public static void main(String args[]) { try {UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName());} catch (Exception e) {;} Layer_Model model = new Layer_Model(); Layer_View view = new Layer_View("TRAIN RESERVATION SYSTEM:RESERVATION"); Layer_Controller controller = new Layer_Controller(model,view); } } class Layer_View extends JFrame//set up GUI { String reservertions[] = {"Surname","Firstname", "ID Number","Email","Phone Number","Place of Departure","No-Of-Tickets", "Time of Departure","Time of Arrival"}; private JTextField input = new JTextField(7); private JTextField inputName = new JTextField(7); private JTextField inputID = new JTextField(7); private JTextField inputEmail = new JTextField(7); private JTextField inputNumber = new JTextField(7); private JTextField inputDeparture = new JTextField(7); private JTextField inputDestination = new JTextField(7); private JTextField inputTickets = new JTextField(7); private JTextField inputDepatime = new JTextField(7); private JTextField inputArrival = new JTextField(7); //declare button components JButton price = new JButton("PRICE"); JButton submit = new JButton("SUBMIT"); JButton cancel = new JButton("CANCEL"); JButton exit = new JButton("EXIT"); JPanel buttons = new JPanel(new GridLayout(4,1,2,2)); JPanel but = new JPanel(new GridLayout(4,1,2,2)); //BorderLayout pane to hold input/button JPanels //border layout to hold inputs and buttons JPanel report = new JPanel(new GridLayout(4,1,2,2)); JPanel main = new JPanel(new BorderLayout()); class Layer_Model // provides working functionality {;} public Layer_View(String title)// constructor method for GUI { super(title);setBounds(100,100,500,180);setResizable(true); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); //construct input fieldset for (int i=0; i<9;i++) { JLabel lab = new JLabel(reservertions[i]); lab.setForeground(Color.black); JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); p.add(lab); switch (i) { case 0: p.add(input); break; case 1: p.add(inputName); break; case 2: p.add(inputID); break; case 3: p.add(inputEmail); break; case 4: p.add(inputNumber); break; case 5: p.add(inputDeparture); break; case 6: p.add(inputDestination); break; case 7: p.add(inputTickets); break; case 8: p.add(inputDepatime); break; case 9: p.add(inputArrival); break; } report.add(p); } //constructing buttons //construct button controls buttons.add(price); but.add(cancel); buttons.add(submit); but.add(exit); //completing the panel assembly main.add("Center",report); main.add("West",buttons); main.add("East",but); this.getContentPane().add("Center",main);setVisible(true); } class Layer_Controller implements ActionListener { Layer_Model model; Layer_View view; public Layer_Controller(Layer_Model model, Layer_View view) { this.model = model; this.view = view; view.buttonActionListeners(this); } // methods to deal with the interactions performed on the panel. public void actionPerformed(ActionEvent ae) { String action_com = ae.getActionCommand(); if (action_com.equals("price")) {System.out.print("what price do you want to set");} else if (action_com.equals("exit")) {System.exit(0);} else if (action_com.equals("submit")) {System.exit(0);} else if (action_com.equals("cancel")) {System.exit(0);} } } public void buttonActionListeners(ActionListener al) { price.addActionListener(al);price.setActionCommand("price"); exit.addActionListener(al);exit.setActionCommand("exit"); submit.addActionListener(al);submit.setActionCommand("submit"); cancel.addActionListener(al);cancel.setActionCommand("cancel"); } }
Last edited by ~s.o.s~; Nov 8th, 2007 at 4:07 pm. Reason: Added code tags, learn to use them.
Please use code tags when you post code.
Reposting it for you here with tags and formatting, but it still will not compile as you have posted it. You mangled the class definitions by embedding them haphazardly in one another.
Reposting it for you here with tags and formatting, but it still will not compile as you have posted it. You mangled the class definitions by embedding them haphazardly in one another.
java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Layers // driver function { public static void main(String args[]) { try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch (Exception e) {;} Layer_Model model = new Layer_Model(); Layer_View view = new Layer_View("TRAIN RESERVATION SYSTEM:RESERVATION"); Layer_Controller controller = new Layer_Controller(model,view); } } class Layer_View extends JFrame//set up GUI { String reservertions[] = {"Surname","Firstname", "ID Number","Email","Phone Number","Place of Departure","No-Of-Tickets", "Time of Departure","Time of Arrival"}; private JTextField input = new JTextField(7); private JTextField inputName = new JTextField(7); private JTextField inputID = new JTextField(7); private JTextField inputEmail = new JTextField(7); private JTextField inputNumber = new JTextField(7); private JTextField inputDeparture = new JTextField(7); private JTextField inputDestination = new JTextField(7); private JTextField inputTickets = new JTextField(7); private JTextField inputDepatime = new JTextField(7); private JTextField inputArrival = new JTextField(7); //declare button components JButton price = new JButton("PRICE"); JButton submit = new JButton("SUBMIT"); JButton cancel = new JButton("CANCEL"); JButton exit = new JButton("EXIT"); JPanel buttons = new JPanel(new GridLayout(4,1,2,2)); JPanel but = new JPanel(new GridLayout(4,1,2,2)); //BorderLayout pane to hold input/button JPanels //border layout to hold inputs and buttons JPanel report = new JPanel(new GridLayout(4,1,2,2)); JPanel main = new JPanel(new BorderLayout()); class Layer_Model // provides working functionality {;} public Layer_View(String title)// constructor method for GUI { super(title);setBounds(100,100,500,180);setResizable(true); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); //construct input fieldset for (int i=0; i<9;i++) { JLabel lab = new JLabel(reservertions[i]); lab.setForeground(Color.black); JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); p.add(lab); switch (i) { case 0: p.add(input); break; case 1: p.add(inputName); break; case 2: p.add(inputID); break; case 3: p.add(inputEmail); break; case 4: p.add(inputNumber); break; case 5: p.add(inputDeparture); break; case 6: p.add(inputDestination); break; case 7: p.add(inputTickets); break; case 8: p.add(inputDepatime); break; case 9: p.add(inputArrival); break; } report.add(p); } //constructing buttons //construct button controls buttons.add(price); but.add(cancel); buttons.add(submit); but.add(exit); //completing the panel assembly main.add("Center",report); main.add("West",buttons); main.add("East",but); this.getContentPane().add("Center",main);setVisible(true); } class Layer_Controller implements ActionListener { Layer_Model model; Layer_View view; public Layer_Controller(Layer_Model model, Layer_View view) { this.model = model; this.view = view; view.buttonActionListeners(this); } // methods to deal with the interactions performed on the panel. public void actionPerformed(ActionEvent ae) { String action_com = ae.getActionCommand(); if (action_com.equals("price")) {System.out.print("what price do you want to set");} else if (action_com.equals("exit")) {System.exit(0);} else if (action_com.equals("submit")) {System.exit(0);} else if (action_com.equals("cancel")) {System.exit(0);} } } public void buttonActionListeners(ActionListener al) { price.addActionListener(al);price.setActionCommand("price"); exit.addActionListener(al);exit.setActionCommand("exit"); submit.addActionListener(al);submit.setActionCommand("submit"); cancel.addActionListener(al);cancel.setActionCommand("cancel"); } }
Last edited by Ezzaral; Nov 8th, 2007 at 12:22 pm.
![]() |
Similar Threads
- java and using observable class (Java)
- ActionListener (Java)
- Writing Applet ActionListener Mortgage Calculator (Java)
- Cannot figure out why I'm getting these Errors (Java)
- JTextField (Java)
Other Threads in the Java Forum
- Previous Thread: Java Applet Triangle, Need Help Please
- Next Thread: Game algorithm help
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arc arguments array arrays automation binary bluetooth c++ chat class classes client code codesnippet compiler component csv database doctype draw ebook eclipse error event exception fractal freeze game givemetehcodez graphics gui html ide image input integer intellij iphone j2me java java.xls javaprojects jmf jni jpanel jtable julia linux list login loop loops mac map method methods mobile netbeans newbie number online oracle page parameter print problem program programming project recursion reporting rotatetext scanner screen server set size sms socket sort sql string superclass swing system template test testautomation threads time title tree tutorial-sample windows working






