java swing鼠标事件_Swing 鼠标单击事件?

3c760f2467383fd9ba2a60adff7af4ba.png

Cats萌萌

想必你是初学者,为了让你更好的理解看一下这个程序吧import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextField;public class Moble extends JFrame {// Java实现一个简单的手机面板及数字输入功能private static final long serialVersionUID = 1L;private JTextField txtView;public static void main(String args[]) {new Moble();}public Moble() {setTitle("Moble");setBounds(100, 100, 200, 300);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);final JPanel panel = new JPanel();getContentPane().add(panel, BorderLayout.CENTER);setResizable(false);txtView = new JTextField();panel.setLayout(null);panel.add(txtView);final JButton btn1 = new JButton();btn1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("1"));}});btn1.setText("1");btn1.setBounds(0, 73, 59, 23);panel.add(btn1);final JButton btn2 = new JButton();btn2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("2"));}});btn2.setText("2");btn2.setBounds(65, 73, 59, 23);panel.add(btn2);final JButton btn3 = new JButton();btn3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("3"));}});btn3.setText("3");btn3.setBounds(130, 73, 59, 23);panel.add(btn3);final JButton btn4 = new JButton();btn4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("4"));}});btn4.setText("4");btn4.setBounds(0, 102, 59, 23);panel.add(btn4);final JButton btn5 = new JButton();btn5.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("5"));}});btn5.setText("5");btn5.setBounds(65, 102, 59, 23);panel.add(btn5);final JButton btn6 = new JButton();btn6.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("6"));}});btn6.setText("6");btn6.setBounds(130, 102, 59, 23);panel.add(btn6);final JButton btn7 = new JButton();btn7.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("7"));}});btn7.setText("7");btn7.setBounds(0, 131, 59, 23);panel.add(btn7);final JButton btn8 = new JButton();btn8.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("8"));}});btn8.setText("8");btn8.setBounds(65, 131, 59, 23);panel.add(btn8);final JButton btn9 = new JButton();btn9.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("9"));}});btn9.setText("9");btn9.setBounds(130, 131, 59, 23);panel.add(btn9);final JButton btn0 = new JButton();btn0.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText(txtView.getText().concat("0"));}});btn0.setText("0");btn0.setBounds(68, 160, 57, 23);panel.add(btn0);txtView = new JTextField();txtView.setBounds(59, 24, 90, 21);panel.add(txtView);final JButton btnSend = new JButton();btnSend.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {if (txtView.getText().indexOf("calling...") == -1) {txtView.setText(txtView.getText().concat("calling..."));} else {return;}}});btnSend.setText("Send");btnSend.setBounds(40, 189, 127, 23);panel.add(btnSend);final JButton btnclear = new JButton();btnclear.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {txtView.setText("");}});btnclear.setText("Clear");btnclear.setBounds(40, 212, 127, 23);panel.add(btnclear);final JButton btnOff = new JButton();btnOff.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {System.exit(0);}});btnOff.setText("Exit");btnOff.setBounds(40, 232, 127, 23);panel.add(btnOff);setVisible(true);}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值