Results 1 to 5 of 5

Thread: JButtons

  1. #1
    jadaleus is offline Member
    Join Date
    Oct 2008
    Posts
    12
    Rep Power
    0

    Default JButtons

    what is the code that woul allow me to click on button that open a class existing with in a project

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Create a JButton ,add it to your JComponent,then add action listener to your JButton which will have the method actionPerformed(ActionEvent e) in which you will launch your preferred application

  3. #3
    jadaleus is offline Member
    Join Date
    Oct 2008
    Posts
    12
    Rep Power
    0

    Default

    The code I'm using is as follows:public void actionPerformed(ActionEvent event) {
    if(event.getSource() == homeButton){

    Search.setVisible(true);

    }

    Search is the class I would like to open from another class call register

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    When you run the application,so Search object is also created ,but you set it as unvisible, so it should be like this:

    Java Code:
    JButton homeButton=new JButton(
    "home button");
    Search s=new Search();
    
    homeButton.addActionListener(new ActionListener(){
    
       public void actionPerformed(ActionEvent e){
           s.setVisible(true);
       }
    });

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Sounds like you would benefit greatly by going through the Sun Swing tutorial. You can find it here: Trail: Graphical User Interfaces (The Java Tutorials)

Similar Threads

  1. 2D Array of JButtons
    By stevemcc in forum AWT / Swing
    Replies: 1
    Last Post: 02-16-2008, 11:42 PM
  2. JButtons
    By fgasimzade in forum SWT / JFace
    Replies: 1
    Last Post: 12-25-2007, 05:39 AM
  3. how to change the appearance of jbuttons
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 10:26 PM
  4. JButtons in a straight line on the BOTTOM
    By paul in forum AWT / Swing
    Replies: 0
    Last Post: 07-16-2007, 04:47 PM
  5. disabling JButtons after win in TicTacToe
    By noisepoet in forum New To Java
    Replies: 1
    Last Post: 05-18-2007, 11:01 PM

Posting Permissions

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