Home > Java > javaTutorial > Methods to add buttons and respond to events in java

Methods to add buttons and respond to events in java

Y2J
Release: 2017-04-17 10:59:07
Original
2751 people have browsed it

The editor below will bring you an article on how to add a button in Java and add a method to respond to the event (recommended). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look

Let’s learn about Java containers, panels, etc. from Baidu


private Button LogInbtn = new Button("登陆"); 
final static JFrame buyerpagemain = new JFrame(); 
final Container contentPane = buyerpagemain.getContentPane(); 
contentPane.add(LogInbtn);// 登陆按钮 
    LogInbtn.setBounds(690, 12, 40, 30); 
    LogInbtn.setBackground(Color.green); 
    LogInbtn.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        new LoginMain("登陆"); 
 
        //buyerpagemain.dispose(); 
      } 
    });
Copy after login

The implementation of the LoginMain class:


 public class LoginMain extends JFrame { 
    public static void main(String[] args) { 
    new LoginMain("登陆"); 
  } 
}
Copy after login

Just implement the specific functions you want to achieve by yourself!

The above is the detailed content of Methods to add buttons and respond to events in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template