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
    10

    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
    10

    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,315
    Blog Entries
    1
    Rep Power
    29

    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-17-2008, 12:42 AM
  2. JButtons
    By fgasimzade in forum SWT / JFace
    Replies: 1
    Last Post: 12-25-2007, 06:39 AM
  3. how to change the appearance of jbuttons
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 11:26 PM
  4. JButtons in a straight line on the BOTTOM
    By paul in forum AWT / Swing
    Replies: 0
    Last Post: 07-16-2007, 05:47 PM
  5. disabling JButtons after win in TicTacToe
    By noisepoet in forum New To Java
    Replies: 1
    Last Post: 05-19-2007, 12:01 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
  •