if(e.getResource()==button1){........}
else if(e.getResource()==button2){........}
else if(e.getResource()==button3){........}

解决方案 »

  1.   

    ==啊~~~~~~~~~~~没成功啊~~~~~~~~~~它说:
    cannot resolve symbol 
    symbol:method getResoure()
    location:calss java.awt.event.ActionEvent
          if(e.getResource()==b1){
              ^
      

  2.   

    那位不小心写错了,是getSource不是getResource
      

  3.   

    你引进包了么
    import java.awt.event.*;
      

  4.   

    还可以用String getActionCommand()
      

  5.   

    package testapp;
    /**
     * <p>Title: Cell测试学习</p>
     * <p>Description: 有一个表格、两个按钮。
     * 双击表格中的某一个cell,cell变成蓝色、按钮一变灰;
     * 如果点击按钮二,cell颜色复原、按钮一复原、按钮二变灰;
     * 点击按钮一,cell重变蓝并把信息存入vector中、按钮一变灰、按钮二复原;
     * 双击蓝色的cell,cell变回原色、按钮一复原、按钮二变灰;</p>
     * <p>Copyright: 雨天看天晴 Copyright (c) 2002</p>
     * <p>Company: 人间天工作组</p>
     * @author 雨天看天晴
     * @version 1.0
     */import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Vector;interface MyInitScheme {
    void initVarient();
    void initFace();
    }
    class MyMenu extends JMenu implements MyInitScheme {
    public MyMenu(String text) {
    super(text);
    initVarient();
    initFace();
    }
    public void initFace() {
    setBackground(SystemColor.desktop);
    setFont(new Font("Serif", 0, 16));
    setForeground(SystemColor.info);
    setBorder(BorderFactory.createEtchedBorder());
    }
    public void initVarient(){};
    }
    class MyMenuItem extends JMenuItem implements MyInitScheme {
    public MyMenuItem(String text) {
    super(text);
    initVarient();
    initFace();
    }
    public void initFace() {
    setBackground(SystemColor.desktop);
    setFont(new Font("Serif", 0, 16));
    setForeground(SystemColor.info);
    setBorder(BorderFactory.createEtchedBorder());
    }
    public void initVarient(){};
    }
    class MyButton extends JButton implements MyInitScheme {
    public MyButton(String text) {
    super(text);
    initVarient();
    initFace();
    }
    public void initFace() {
    setBackground(SystemColor.desktop);
    setFont(new Font("Serif", 0, 16));
    setForeground(SystemColor.info);
    setBorder(BorderFactory.createEtchedBorder());
    }
    public void initVarient(){};
    }
    class MyList extends JList implements MyInitScheme {
    public MyList(final Object[] listData) {
    super(listData);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    initVarient();
    initFace();
    }
    public void initFace() {
    setFont(new Font("Serif", 0, 16));
    setSelectionBackground(SystemColor.activeCaption);
    setFixedCellHeight(20);
    setForeground(SystemColor.info);
    setBackground(SystemColor.desktop);
    }
    public void initVarient(){};
    public void unSelected(int index) {
    int[] selIndices=getSelectedIndices();
    clearSelection();
    for(int i=0;i<selIndices.length;i++) {
    if (selIndices[i]!=index) setSelectedIndex(selIndices[i]);
    }
    }
    }class CellFrame extends JFrame implements MyInitScheme,ActionListener,MouseListener {
    private Vector vector=new Vector();
    private int lastSel=-1;
    private JMenuBar mnuBar = new JMenuBar();
    private MyMenu mnuFile = new MyMenu("File");
    private JMenuItem mnuFileExit = new MyMenuItem("Exit");
    private JMenu mnuHelp = new MyMenu("Help");
    private JMenuItem mnuHelpContact = new MyMenuItem("Contact Me");
    private JButton btnChs = new MyButton("Reselect");
    private JButton btnUndo = new MyButton("Unselect");
    private String[] data = {"one", "two", "three", "four","five",
    "six","seven","eight","nine","ten","eleven","twelve","thirteen"};
    private MyList lstData = new MyList(data);
    private JScrollPane scrollPane = new JScrollPane(lstData); public void initVarient(){};
    public void initFace() {
    this.setTitle("Cell测试学习");
    this.setSize(new Dimension(320, 240));
    this.setResizable(false);
    this.getContentPane().setLayout(null);
    this.getContentPane().setBackground(SystemColor.activeCaption);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mnuBar.setBackground(SystemColor.desktop);
    mnuBar.setBorder(BorderFactory.createRaisedBevelBorder()); mnuFile.setMnemonic('F');
    mnuFileExit.setMnemonic('x');
    mnuFileExit.addActionListener(new ActionListener () {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    }
    } ); mnuHelp.setMnemonic('H');
    mnuHelpContact.setMnemonic('M');
    mnuHelpContact.addActionListener(new ActionListener () {
    public void actionPerformed(ActionEvent e) {
    try {
    Process p=Runtime.getRuntime().exec("C:/Program Files/"
    +"Internet Explorer/IExplore.EXE"
    +" mailto:[email protected]");
    } catch (Exception ex) {
    System.out.println(ex);
    }
    }
    } ); btnChs.setBounds(new Rectangle(220, 50, 75, 30));
    btnChs.setMnemonic('S');
    btnChs.addActionListener(this); btnUndo.setBounds(new Rectangle(220, 100, 75, 30));
    btnUndo.setMnemonic('U');
    btnUndo.addActionListener(this); lstData.addMouseListener(this); scrollPane.setBounds(new Rectangle(10, 10, 190, 160)); mnuFile.add(mnuFileExit);
    mnuHelp.add(mnuHelpContact);
    mnuBar.add(mnuFile);
    mnuBar.add(mnuHelp); this.setJMenuBar(mnuBar);
    this.getContentPane().add(scrollPane, null);
    this.getContentPane().add(btnChs, null);
    this.getContentPane().add(btnUndo, null);
    } public void actionPerformed(ActionEvent e){
    Object src=e.getSource();
    if(src==btnChs) {
    lstData.setSelectedIndex(lastSel);
    // vector.add(data[lastSel]);
    btnChs.setEnabled(false);
    btnUndo.setEnabled(true);
    } else if(src==btnUndo) {
    lstData.unSelected(lastSel);
    btnChs.setEnabled(true);
    btnUndo.setEnabled(false);
    }
    }
    public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
     lastSel = lstData.locationToIndex(e.getPoint());
     if(lstData.isSelectedIndex(lastSel)) {
     lstData.unSelected(lastSel);
     btnChs.setEnabled(true);
     btnUndo.setEnabled(false);
     } else {
     lstData.setSelectedIndex(lastSel);
     btnChs.setEnabled(false);
     btnUndo.setEnabled(true);
     }
    }
    }
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {} public CellFrame() {
    initVarient();
    initFace();
    show();
    }
    }public class CellLearnApp {
    public static void main(String[] args) {
    CellFrame frame = new CellFrame();
    }
    }里面有你要的代码,当然这个程序有问题啊,可以运行、但功能有问题。
      

  6.   

    好了~~~~~~~!!!谢谢大家啊~~~~~~~~~顺便问问~`在哪儿下API文档的HELP版啊~~我是HTML版的~~`还有在哪儿下UE编辑器和它的补丁啊~我这个用不起~`听说要补丁~
      

  7.   

    用个人版的Jbuilder7吧。直接在www.inprise.com有或www.java.com.cn也有(在论坛里找)帮助html版的最新,winhelp格式的只有1.3的,都在java.sun.com有下的。
      

  8.   

    我去了java.sun.com的~~没找到`~:(