Add a button in java and add the method of recommended for responding to events

  • 2020-06-23 00:28:17
  • OfStack

About Java container, panel, etc


</pre><pre name="code" class="java">private Button LogInbtn = new Button(" landing "); 
final static JFrame buyerpagemain = new JFrame(); 
final Container contentPane = buyerpagemain.getContentPane(); 
contentPane.add(LogInbtn);//  Log in button  
    LogInbtn.setBounds(690, 12, 40, 30); 
    LogInbtn.setBackground(Color.green); 
    LogInbtn.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent e) { 
        new LoginMain(" landing "); 
 
        //buyerpagemain.dispose(); 
      } 
    }); 

Implementation of LoginMain class:


 public class LoginMain extends JFrame { 
    public static void main(String[] args) { 
    new LoginMain(" landing "); 
  } 
} 

Want to realize what function concretely to realize by oneself!


Related articles: