Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: Buttons not working..

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Buttons not working..

    Please check my code.
    Attached Files Attached Files


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Buttons not working..

    Next time please post your code and surround it in [highlight=java][/highlight] tags. What problem are you experiencing, are there any errors?

    For anyone that is too lazy to open the link:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
     
    public class unitConversion {
        public static void main (String[] args) {
        	JFrameWithPanel panel = new JFrameWithPanel();
        	panel.setSize(305,250);
        	panel.setVisible(true);
        	panel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }
     
    class JFrameWithPanel extends JFrame implements ActionListener{
    	JLabel lbl = new JLabel("Enter choice (i.e. One, Two, Three, or Four)");
    	JLabel lbl2 = new JLabel("Enter value to convert:");
    	JTextField txt = new JTextField();
    	JTextField txt2 = new JTextField();
    	JLabel lbl3 = new JLabel();
    	JButton btn = new JButton("CLEAR");
    	JButton btn2 = new JButton("CONVERT");
    	JButton btnok = new JButton("OK");
    	JButton btncan = new JButton("CANCEL");
    	public static String u;
    	public static double i, mn;
    	public JFrameWithPanel(){
    		setTitle("Unit Conversion");
    		setLayout(null);
    		txt.setBounds(10,48,120,31);
    		lbl.setBounds(10,23,300,20);
    		txt2.setBounds(160,92,110,30);
    		lbl2.setBounds(10,96,130,20);
    		lbl3.setBounds(40,120,300,30);
    		lbl3.setHorizontalAlignment( SwingConstants.CENTER );
    		btnok.setBounds(135,48,60,30);
    		btnok.addActionListener(this);
    		btnok.setActionCommand("h");
    		btncan.setBounds(200,48,80,30);
    		btncan.addActionListener(this);
    		btncan.setActionCommand("r");
    		btn.setBounds(40,160,80,30);
    		btn.addActionListener(this);
    		btn.setActionCommand("g");
    		btn2.setBounds(132,160,120,30);
    		btn2.addActionListener(this);
    		btn2.setActionCommand("x");
    		add(btn);
    		add(btn2);
    		add(btnok);
    		add(btncan);
    		add(lbl);
    		add(txt);
    		add(lbl2);
    		add(txt2);
    		add(lbl3);
    		lbl2.setVisible(false);
    		lbl3.setVisible(false);
    		txt2.setVisible(false);
    		btn.setVisible(false);
    		btn2.setVisible(false);
    	}
    	public void actionPerformed(ActionEvent e){
    		if(e.getActionCommand().equals("h")){
    			u = txt.getText();
    			if(u.equalsIgnoreCase("one")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i/1000;
    						lbl3.setText(""+i+" meter/s is equivalent to "+mn+" kilometer/s.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("two")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i*0.0003048;
    						lbl3.setText(""+i+" foot/feet is equivalent to "+mn+" kilometer/s.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("three")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i*(-457.87);
    						lbl3.setText(""+i+" kelvin is equivalent to "+mn+" fahrenheit.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("four")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i*33.8;
    						lbl3.setText(""+i+" celsius is equivalent to "+mn+" fahrenheit.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("")){
    				txt.setText("default: one");
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i/1000;
    						lbl3.setText(""+i+" meter/s is equivalent to "+mn+" kilometer/s.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else{
    				txt.setText("Enter another choice.");
    			}if(e.getActionCommand().equals("r")){
    				txt.setText("");
    			}
    		}
    	}
    }
    Last edited by Brt93yoda; September 2nd, 2010 at 02:03 PM.

  3. The Following User Says Thank You to Brt93yoda For This Useful Post:

    khms (September 2nd, 2010)

  4. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Buttons not working..

    Quote Originally Posted by Brt93yoda View Post
    Next time please post your code and surround it in [highlight=java][/highlight] tags. What problem are you experiencing, are there any errors?

    For anyone that is too lazy to open the link:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
     
    public class unitConversion {
        public static void main (String[] args) {
        	JFrameWithPanel panel = new JFrameWithPanel();
        	panel.setSize(305,250);
        	panel.setVisible(true);
        	panel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }
     
    class JFrameWithPanel extends JFrame implements ActionListener{
    	JLabel lbl = new JLabel("Enter choice (i.e. One, Two, Three, or Four)");
    	JLabel lbl2 = new JLabel("Enter value to convert:");
    	JTextField txt = new JTextField();
    	JTextField txt2 = new JTextField();
    	JLabel lbl3 = new JLabel();
    	JButton btn = new JButton("CLEAR");
    	JButton btn2 = new JButton("CONVERT");
    	JButton btnok = new JButton("OK");
    	JButton btncan = new JButton("CANCEL");
    	public static String u;
    	public static double i, mn;
    	public JFrameWithPanel(){
    		setTitle("Unit Conversion");
    		setLayout(null);
    		txt.setBounds(10,48,120,31);
    		lbl.setBounds(10,23,300,20);
    		txt2.setBounds(160,92,110,30);
    		lbl2.setBounds(10,96,130,20);
    		lbl3.setBounds(40,120,300,30);
    		lbl3.setHorizontalAlignment( SwingConstants.CENTER );
    		btnok.setBounds(135,48,60,30);
    		btnok.addActionListener(this);
    		btnok.setActionCommand("h");
    		btncan.setBounds(200,48,80,30);
    		btncan.addActionListener(this);
    		btncan.setActionCommand("r");
    		btn.setBounds(40,160,80,30);
    		btn.addActionListener(this);
    		btn.setActionCommand("g");
    		btn2.setBounds(132,160,120,30);
    		btn2.addActionListener(this);
    		btn2.setActionCommand("x");
    		add(btn);
    		add(btn2);
    		add(btnok);
    		add(btncan);
    		add(lbl);
    		add(txt);
    		add(lbl2);
    		add(txt2);
    		add(lbl3);
    		lbl2.setVisible(false);
    		lbl3.setVisible(false);
    		txt2.setVisible(false);
    		btn.setVisible(false);
    		btn2.setVisible(false);
    	}
    	public void actionPerformed(ActionEvent e){
    		if(e.getActionCommand().equals("h")){
    			u = txt.getText();
    			if(u.equalsIgnoreCase("one")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i/1000;
    						lbl3.setText(""+i+" meter/s is equivalent to "+mn+" kilometer/s.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("two")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i*0.0003048;
    						lbl3.setText(""+i+" foot/feet is equivalent to "+mn+" kilometer/s.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("three")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i*(-457.87);
    						lbl3.setText(""+i+" kelvin is equivalent to "+mn+" fahrenheit.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("four")){
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i*33.8;
    						lbl3.setText(""+i+" celsius is equivalent to "+mn+" fahrenheit.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else if(u.equalsIgnoreCase("")){
    				txt.setText("default: one");
    				lbl2.setVisible(true);
    				lbl3.setVisible(true);
    				txt2.setVisible(true);
    				btn.setVisible(true);
    				btn2.setVisible(true);
    				if(e.getActionCommand().equals("x")){
    					try{
    						i = Double.parseDouble(txt2.getText());
    						mn = i/1000;
    						lbl3.setText(""+i+" meter/s is equivalent to "+mn+" kilometer/s.");
    					}catch(NumberFormatException t){
    						lbl3.setText("Invalid Input. Please try again.");
    					}
    				}
    				if(e.getActionCommand().equals("g")){
    					txt.setText("");
    					txt2.setText("");
    					lbl3.setText("");
    					lbl2.setVisible(false);
    					lbl3.setVisible(false);
    					txt2.setVisible(false);
    					btn.setVisible(false);
    					btn2.setVisible(false);
    				}
    			}else{
    				txt.setText("Enter another choice.");
    			}if(e.getActionCommand().equals("r")){
    				txt.setText("");
    			}
    		}
    	}
    }
    i can't get my convert and clear buttons to work properly.. can you help me out?

  5. #4
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Buttons not working..

    What is the correct input for the "convert value" textField?

  6. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Buttons not working..

    the input can be any number. the program is a unit converter. if you type 'one', that will enable you to convert meters to kilometers, typing 'two' will make you convert feet to kilometers, 'three' for kelvin to fahrenheit and 'four' for celsius to fahrenheit. if you choose one, and placed 10 as the convert value, that will be .01 kilometers.

  7. #6
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Buttons not working..

    but i can't seem to make the buttons to work. the output/answer is supposed to appear to lbl3 which is located between the convert textfield and the clear and convert buttons. i've been trying to figure out the problem with my code, but i can't seem to find any.

  8. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Buttons not working..

    Your code tries to capture those events in the action listener implementation within another caught event, which means they will never be seen. Add another else if along with the other 'outer' ones to implement the actions of those buttons.

  9. #8
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Buttons not working..

    I found your problem. On the beginning of your action listener you have
    if(e.getActionCommand().equals("h")){
    Which meant that the action performed had to magically be H AND X. Here is my fixed code (works perfectly fine for me):

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
     
    public class unitConversion {
        public static void main (String[] args) {
            JFrameWithPanel panel = new JFrameWithPanel();
            panel.setSize(305,250);
            panel.setVisible(true);
            panel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }
     
    class JFrameWithPanel extends JFrame implements ActionListener{
        JLabel lbl = new JLabel("Enter choice (i.e. One, Two, Three, or Four)");
        JLabel lbl2 = new JLabel("Enter value to convert:");
        JTextField txt = new JTextField();
        JTextField txt2 = new JTextField();
        JLabel lbl3 = new JLabel();
        JButton btn = new JButton("CLEAR");
        JButton btn2 = new JButton("CONVERT");
        JButton btnok = new JButton("OK");
        JButton btncan = new JButton("CANCEL");
        public static String u;
        public static double i, mn;
        public JFrameWithPanel(){
            setTitle("Unit Conversion");
            setLayout(null);
            txt.setBounds(10,48,120,31);
            lbl.setBounds(10,23,300,20);
            txt2.setBounds(160,92,110,30);
            lbl2.setBounds(10,96,130,20);
            lbl3.setBounds(40,120,300,30);
            lbl3.setHorizontalAlignment( SwingConstants.CENTER );
            btnok.setBounds(135,48,60,30);
            btnok.addActionListener(this);
            btnok.setActionCommand("h");
            btncan.setBounds(200,48,80,30);
            btncan.addActionListener(this);
            btncan.setActionCommand("r");
            btn.setBounds(40,160,80,30);
            btn.addActionListener(this);
            btn.setActionCommand("g");
            btn2.setBounds(132,160,120,30);
            btn2.addActionListener(this);
            btn2.setActionCommand("x");
            add(btn);
            add(btn2);
            add(btnok);
            add(btncan);
            add(lbl);
            add(txt);
            add(lbl2);
            add(txt2);
            add(lbl3);
            lbl2.setVisible(false);
            lbl3.setVisible(false);
            txt2.setVisible(false);
            btn.setVisible(false);
            btn2.setVisible(false);
        }
        public void actionPerformed(ActionEvent e){
                u = txt.getText();
                if(u.equalsIgnoreCase("one")){
                    lbl2.setVisible(true);
                    lbl3.setVisible(true);
                    txt2.setVisible(true);
                    btn.setVisible(true);
                    btn2.setVisible(true);
                    if(e.getActionCommand().equals("x")){
                        try{
                        	i = Double.parseDouble(txt2.getText());
                            mn = i/1000;
                            lbl3.setText(""+i+" meter/s is equivalent to "+mn+" kilometer/s.");
                        }catch(NumberFormatException t){
                            lbl3.setText("Invalid Input. Please try again.");
                        }
                    }
                    if(e.getActionCommand().equals("g")){
                        txt.setText("");
                        txt2.setText("");
                        lbl3.setText("");
                        lbl2.setVisible(false);
                        lbl3.setVisible(false);
                        txt2.setVisible(false);
                        btn.setVisible(false);
                        btn2.setVisible(false);
                    }
                }else if(u.equalsIgnoreCase("two")){
                    lbl2.setVisible(true);
                    lbl3.setVisible(true);
                    txt2.setVisible(true);
                    btn.setVisible(true);
                    btn2.setVisible(true);
                    if(e.getActionCommand().equals("x")){
                        try{
                            i = Double.parseDouble(txt2.getText());
                            mn = i*0.0003048;
                            lbl3.setText(""+i+" foot/feet is equivalent to "+mn+" kilometer/s.");
                        }catch(NumberFormatException t){
                            lbl3.setText("Invalid Input. Please try again.");
                        }
                    }
                    if(e.getActionCommand().equals("g")){
                        txt.setText("");
                        txt2.setText("");
                        lbl3.setText("");
                        lbl2.setVisible(false);
                        lbl3.setVisible(false);
                        txt2.setVisible(false);
                        btn.setVisible(false);
                        btn2.setVisible(false);
                    }
                }else if(u.equalsIgnoreCase("three")){
                    lbl2.setVisible(true);
                    lbl3.setVisible(true);
                    txt2.setVisible(true);
                    btn.setVisible(true);
                    btn2.setVisible(true);
                    if(e.getActionCommand().equals("x")){
                        try{
                            i = Double.parseDouble(txt2.getText());
                            mn = i*(-457.87);
                            lbl3.setText(""+i+" kelvin is equivalent to "+mn+" fahrenheit.");
                        }catch(NumberFormatException t){
                            lbl3.setText("Invalid Input. Please try again.");
                        }
                    }
                    if(e.getActionCommand().equals("g")){
                        txt.setText("");
                        txt2.setText("");
                        lbl3.setText("");
                        lbl2.setVisible(false);
                        lbl3.setVisible(false);
                        txt2.setVisible(false);
                        btn.setVisible(false);
                        btn2.setVisible(false);
                    }
                }else if(u.equalsIgnoreCase("four")){
                    lbl2.setVisible(true);
                    lbl3.setVisible(true);
                    txt2.setVisible(true);
                    btn.setVisible(true);
                    btn2.setVisible(true);
                    if(e.getActionCommand().equals("x")){
                        try{
                            i = Double.parseDouble(txt2.getText());
                            mn = i*33.8;
                            lbl3.setText(""+i+" celsius is equivalent to "+mn+" fahrenheit.");
                        }catch(NumberFormatException t){
                            lbl3.setText("Invalid Input. Please try again.");
                        }
                    }
                    if(e.getActionCommand().equals("g")){
                        txt.setText("");
                        txt2.setText("");
                        lbl3.setText("");
                        lbl2.setVisible(false);
                        lbl3.setVisible(false);
                        txt2.setVisible(false);
                        btn.setVisible(false);
                        btn2.setVisible(false);
                    }
                }else if(u.equalsIgnoreCase("")){
                    txt.setText("default: one");
                    lbl2.setVisible(true);
                    lbl3.setVisible(true);
                    txt2.setVisible(true);
                    btn.setVisible(true);
                    btn2.setVisible(true);
                    if(e.getActionCommand().equals("x")){
                        try{
                            i = Double.parseDouble(txt2.getText());
                            mn = i/1000;
                            lbl3.setText(""+i+" meter/s is equivalent to "+mn+" kilometer/s.");
                        }catch(NumberFormatException t){
                            lbl3.setText("Invalid Input. Please try again.");
                        }
                    }
                    if(e.getActionCommand().equals("g")){
                        txt.setText("");
                        txt2.setText("");
                        lbl3.setText("");
                        lbl2.setVisible(false);
                        lbl3.setVisible(false);
                        txt2.setVisible(false);
                        btn.setVisible(false);
                        btn2.setVisible(false);
                    }
                }else{
                    txt.setText("Enter another choice.");
                }if(e.getActionCommand().equals("r")){
                    txt.setText("");
                }
        }
    }

    PS: java.lang.* and java.awt.* are never used in your program.
    Last edited by Brt93yoda; September 2nd, 2010 at 03:05 PM.

  10. The Following User Says Thank You to Brt93yoda For This Useful Post:

    khms (September 2nd, 2010)

  11. #9
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Talking Re: Buttons not working..

    Quote Originally Posted by Brt93yoda View Post
    I found your problem. On the beginning of your action listener you have
    if(e.getActionCommand().equals("h")){
    Which meant that the action performed had to magically be H AND X.
    thank you so much! you're a great help! God bless!

  12. #10
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Buttons not working..

    You're welcome!

  13. #11
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Buttons not working..

    java.lang is actually being used, but it's always imported so you never need to explicitly tell Java you want to import it

  14. #12
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Buttons not working..

    Thanks for the info.

  15. #13
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Buttons not working..

    How do you get they get it to make a new Rectangle with the Rectangle class in Java? I can't figure that out for the life of me!

    I've tried trying for a long time.

    I need to somehow find the the upper-right and lower left point of the new Rectangle formed by the intersection of the two Rectangles. But how? I've tried and tried. Nothing works.

  16. #14
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Buttons not working..

    Rectangle rect = new Rectangle(x_Loc, y_Loc, width, height);

    Working on the intersection part atm

  17. The Following User Says Thank You to Brt93yoda For This Useful Post:

    javapenguin (September 2nd, 2010)

  18. #15
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Buttons not working..

    Dang! why ask the question here *and* start a new thread?

Similar Threads

  1. Create buttons at runtime
    By rtumatt in forum AWT / Java Swing
    Replies: 2
    Last Post: May 24th, 2010, 06:42 AM
  2. radio buttons stop working
    By tabutcher in forum AWT / Java Swing
    Replies: 2
    Last Post: March 5th, 2010, 09:28 AM
  3. JRadio buttons
    By chronoz13 in forum AWT / Java Swing
    Replies: 0
    Last Post: November 29th, 2009, 01:08 AM
  4. Need more buttons!
    By GotWankel? in forum AWT / Java Swing
    Replies: 0
    Last Post: October 5th, 2009, 01:08 AM
  5. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM