Results 1 to 5 of 5
  1. #1
    beginnerprog is offline Member
    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Default When I click on Jbutton i want to display a Jcombobox(reposted in correct forum)

    When i click on the TimeButton A Jlabel appears. But instead of this JLabel i want to display a JComboBox with a list of string. Been working at this for 4 hours and still no luck can someone give me an idea please. My code below :


    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
     public class events extends JFrame {
      private JLabel label;
      private JButton timeButton;
      private JButton moneyButton;
      private JButton hotelButton;
      private JButton exitButton;
      private JPanel testPanel;
      
      public events() {
          setLayout(new BorderLayout());
    	  JPanel testPanel = new JPanel();
    	  add(testPanel,BorderLayout.WEST);
    
          testPanel.setBackground(Color.RED);
    	  
    	 
    	  timeButton = new JButton("Time");
    	  testPanel.add(timeButton);
    	  
    	  moneyButton = new JButton("Price");
    	  testPanel.add(moneyButton);
    	  
    	  hotelButton = new JButton("Price");
    	  testPanel.add(hotelButton);
    	  
    	  exitButton = new JButton("Exit");
    	  testPanel.add(exitButton);
    	  
    	  
    	  
    	  
    	  label = new JLabel("");
    	  add(label);
    	  
    	  
    	  event e = new event();
    	  timeButton.addActionListener(e);
    	  
    	  }
      
         public class event implements ActionListener {
    	  public void actionPerformed(ActionEvent e)  {
    	  label.setText("Now yoy can see words");
    	  }
    	
    	}
    	public static void main (String args[]) {
    	events gui = new events();
    	gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	gui.setSize(600,400);
    	gui.setVisible(true);
    	gui.setLayout(new BorderLayout());
    	gui.setTitle("Travel Agent System");
    
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: When I click on Jbutton i want to display a Jcombobox(reposted in correct forum)

    JComponents have a setVisible() function that you might want to check out.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    beginnerprog is offline Member
    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Default Re: When I click on Jbutton i want to display a Jcombobox(reposted in correct forum)

    Quote Originally Posted by KevinWorkman View Post
    JComponents have a setVisible() function that you might want to check out.
    Ok thank you is ActionListener the right way of going about it or is there anything else i can read up on?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: When I click on Jbutton i want to display a Jcombobox(reposted in correct forum)

    Quote Originally Posted by beginnerprog View Post
    Ok thank you is ActionListener the right way of going about it or is there anything else i can read up on?
    ActionListener seems reasonable to me. What happened when you tried it?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    beginnerprog is offline Member
    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Default Re: When I click on Jbutton i want to display a Jcombobox(reposted in correct forum)

    Quote Originally Posted by KevinWorkman View Post
    ActionListener seems reasonable to me. What happened when you tried it?
    Thank you very much it works!

Similar Threads

  1. Replies: 2
    Last Post: 03-12-2013, 02:26 AM
  2. Replies: 8
    Last Post: 12-29-2008, 08:12 AM
  3. Move to correct forum
    By JavaJunkie1983 in forum Introductions
    Replies: 7
    Last Post: 01-23-2008, 04:04 AM
  4. Move to correct forum...
    By Winarto in forum Introductions
    Replies: 3
    Last Post: 01-18-2008, 04:00 AM
  5. To correct forum
    By Jman in forum Introductions
    Replies: 3
    Last Post: 01-18-2008, 03:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •