解决方案 »

  1.   

    你可以自定义一个按钮类,这个类只要是继承自AbstractButton就可以了
    然后你可以在这个类中重写paintComponent,paintBorder等方法
    就可以实现你自己喜欢的按钮的类型了
      

  2.   

    测试成功,代码如下://需要下载alloy的包,自己到网上找找,很容易找到
    import javax.swing.*;
    import com.incors.plaf.alloy.AlloyLookAndFeel;
    import java.awt.event.*;class MyFrame extends JFrame{
    JButton BB1 = new JButton("button1");
    JButton BB2 = new JButton("button2");
    public MyFrame(String title){
    super(title);
            try {
                AlloyLookAndFeel.setProperty("alloy.isLookAndFeelFrameDecoration", "true");
                LookAndFeel alloyLnF = new AlloyLookAndFeel();  
                JFrame.setDefaultLookAndFeelDecorated(true);  
                UIManager.setLookAndFeel(alloyLnF);
             } catch (UnsupportedLookAndFeelException ex) {
             // You may handle the exception here
             }
             UIManager.getLookAndFeelDefaults().put("ClassLoader", getClass().getClassLoader());
             BB1.addMouseListener(new MouseAdapter(){
              public void mouseClicked(MouseEvent e){
              JOptionPane.showMessageDialog(MyFrame.this, "BB1 Click!","Info",JOptionPane.INFORMATION_MESSAGE);
              }
             });
             setLayout(null);
             add(BB1);
             BB1.setBounds(0, 0, 100, 50);
             add(BB2);
             BB2.setBounds(100, 0, 100, 50);
    }
    }public class Haluo{
    public static void main(String args[]){
    MyFrame KK = new MyFrame("hello");
    KK.setBounds(100, 100, 400, 300);
    KK.setVisible(true);
    KK.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }