關于Java容器,面板等自行百度學一下吧
1
2
3
4
5
6
7
8
9
10
11
12
13
|
</pre><pre name= "code" class = "java" > 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(); } }); |
LoginMain類的實現:
1
2
3
4
5
|
public class LoginMain extends JFrame { public static void main(String[] args) { new LoginMain( "登陸" ); } } |
具體想實現什么功能就自行實現!
以上這篇java中添加按鈕并添加響應事件的方法(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。