java的Swing点击Button左键,右键,双击

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
public class Frame extends JFrame {
    private JButton b[];
    private JTextArea text;
    // 构造方法
    public Frame(String s) {
       // 设置标题栏内容
         setTitle(s);
       // 设置初始化窗口位置
         setBounds(100, 100, 500, 350);
         text=new JTextArea(1,8);
         text.setText("");
         add(text);
       // 设置窗口布局
         setLayout(new FlowLayout());
        // 创建按钮对象
         b=new JButton[4];
         FlowLayout flow=new FlowLayout();
         flow.setAlignment(FlowLayout.LEFT);
         flow.setHgap(2);
         flow.setVgap(8);
         setLayout(flow);
         b[1]=new JButton("button");
         add(b[1]);
         b[1].addMouseListener(new EventListener1());
//         b[2]=new JButton("button2");
//         b[3]=new JButton("button3");
//       for(int i=1;i

你可能感兴趣的:(Java基础)