我写了三个小程序:DrwOval.java,DrwTriangle.java,DrwRectangle.java,怎样再写一个图形界面用它上面三个按钮访问那三个小程序?有那个高手详细写出来,小弟不胜感激:'(  
我已经搞了几天都弄不好,不知是哪里出问题了.注意:这四个程序是分开的.我写的源代码入下: 
import java.awt.*; 
import javax.swing.event.*; 
import java.awt.event.*; 
import javax.swing.*; 
public class ShowGraphics extends JFrame implements ActionListener { 
Frame f=new Frame("画图小程序"); 
Button a1=new Button("画三角形"); 
Button a2=new Button("画矩形"); 
Button a3=new Button("画圆形"); 
public ShowGraphics() 

setLayout(new FlowLayout()); 
add(a1);
add(a2);
add(a3); 
setSize(300,200); 
setVisible(true); 

a1.addActionListener(new ActionListener)
a2.addActionListener(new ActionListener)
a3.addActionListener(new ActionListener){ 
public void actionPerformed(ActionEvent e) 

DrwTriangle a=new DrwTriangle(); 
a.getName() 
DrwRectangle b=new DrwRectangle(); 
b.getName() 
DrwOval c=new DrwOval(); 
c.getName() 



有那个好心人告诉我上面哪里错了? 

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【RINTO】截止到2008-06-26 10:15:52的历史汇总数据(不包括此帖):
    发帖数:0                  发帖分:0                  
    结贴数:0                  结贴分:0                  
    未结数:0                  未结分:0                  
    结贴率:-------------------结分率:-------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    a3.addActionListener(new ActionListener){ 
      public void actionPerformed(ActionEvent e) {}
    }
    这个不对吧?
    内部类的写法有问题
    应该是
    a3.addActionListener(new ActionListener{ 
      public void actionPerformed(ActionEvent e) {}
    });
      

  3.   

    是改成这样吗?
    public void actionPerformed(ActionEvent e) 

    DrwTriangle a=new DrwTriangle(); 
    a.getName() 
    DrwRectangle b=new DrwRectangle(); 
    b.getName() 
    DrwOval c=new DrwOval(); 
    c.getName() 

    }); 
      

  4.   

    就是说addActionListener的参数是
    new ActionListener(){ 
      public void actionPerformed(ActionEvent e) {
      } 
    }
      

  5.   

    为什么还是编译不了:
    E:\j\ShowGraphics.java:19: 需要 <标识符>
    a1.addActionListener(new ActionListener)
                        ^
    E:\j\ShowGraphics.java:19: 非法的类型开始
    a1.addActionListener(new ActionListener)
                         ^
    E:\j\ShowGraphics.java:22: 非法的表达式开始
    public void actionPerformed(ActionEvent e)
    ^
    E:\j\ShowGraphics.java:25: 需要 ';'
    a.getName()
               ^
    E:\j\ShowGraphics.java:27: 需要 ';'
    b.getName()
               ^
    E:\j\ShowGraphics.java:29: 需要 ';'
    c.getName()
               ^
    E:\j\ShowGraphics.java:31: 需要为 class、interface 或 enum
    });
     ^
    E:\j\ShowGraphics.java:32: 需要为 class、interface 或 enum
    }
    ^
    8 错误处理已完成。
      

  6.   


    JButton button = new JButton();
    JButton button1 = new JButton();
    JButton button2 = new JButton();
    button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
                                              //调用的你的功能方法!
    }
    });
    button2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
                                             //调用的你的功能方法!
    }
    });
    button1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
                             //调用的你的功能方法!
    }
    });
                                    JButton button = new JButton();
    JButton button1 = new JButton();
    JButton button2 = new JButton(); button.addActionListener(new myActionListener());
    button1.addActionListener(new myActionListener());
    button2.addActionListener(new myActionListener());                                class myActionListener implements ActionListener{
                                  public void actionPerformed(ActionEvent e) {
                                            //调用的你的功能方法!
                                  }
                                    }
      

  7.   

    改成这样:
    import java.awt.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ShowGraphics extends JFrame implements ActionListener {
    JButton a1 = new JButton("画三角形");
    JButton a2 = new JButton("画矩形");
    JButton a3 = new JButton("画圆形");
    public ShowGraphics()
    {
    super("画图小程序");
    setLayout(new FlowLayout());
    add(a1);
    add(a2);
    add(a3);
    setSize(300,200);
    setVisible(true);a1.addActionListener(new ActionListener);{
    public void actionPerformed(ActionEvent e)
    {
    DrwTriangle a=new DrwTriangle();
    a.getName()}
    });
    a2.addActionListener(new ActionListener);{
    public void actionPerformed(ActionEvent e)
    {
    DrwRectangle b=new DrwRectangle();
    b.getName()}
    });
    a3.addActionListener(new ActionListener);{
    public void actionPerformed(ActionEvent e)
    {
    CircleFrame c=new CircleFrame();
    c.getName()
    }
    });
    }
    }
    为什么错误更多了?错误提示:E:\j\ShowGraphics.java:19: 需要为 '(' 或 '['
    a1.addActionListener(new ActionListener);{
                                           ^
    E:\j\ShowGraphics.java:20: 非法的表达式开始
    public void actionPerformed(ActionEvent e)
    ^
    E:\j\ShowGraphics.java:23: 需要 ';'
    a.getName()}
               ^
    E:\j\ShowGraphics.java:24: 需要为 class、interface 或 enum
    });
     ^
    E:\j\ShowGraphics.java:25: 需要为 class、interface 或 enum
    a2.addActionListener(new ActionListener);{
    ^
    E:\j\ShowGraphics.java:25: 需要为 class、interface 或 enum
    a2.addActionListener(new ActionListener);{
                                             ^
    E:\j\ShowGraphics.java:26: 需要为 class、interface 或 enum
    public void actionPerformed(ActionEvent e)
           ^
    E:\j\ShowGraphics.java:29: 需要为 class、interface 或 enum
    b.getName()}
    ^
    E:\j\ShowGraphics.java:31: 需要为 class、interface 或 enum
    a3.addActionListener(new ActionListener);{
    ^
    E:\j\ShowGraphics.java:31: 需要为 class、interface 或 enum
    a3.addActionListener(new ActionListener);{
                                             ^
    E:\j\ShowGraphics.java:32: 需要为 class、interface 或 enum
    public void actionPerformed(ActionEvent e)
           ^
    E:\j\ShowGraphics.java:35: 需要为 class、interface 或 enum
    c.getName()
    ^
    E:\j\ShowGraphics.java:38: 需要为 class、interface 或 enum
    }
    ^
    13 错误处理已完成。这是为什么啊?我哪里又错了????
      

  8.   

    帮你改了一下!你去掉注释就可以了!
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JFrame;public class ShowGraphics extends JFrame {
    JButton a1 = new JButton("画三角形");
    JButton a2 = new JButton("画矩形");
    JButton a3 = new JButton("画圆形"); public ShowGraphics() {
    super("画图小程序");
    setLayout(new FlowLayout());
    add(a1);
    add(a2);
    add(a3);
    setSize(300, 200);
    setVisible(true); a1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // DrwTriangle a=new DrwTriangle();
    // a.getName();
    }
    }); a2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // DrwRectangle b=new DrwRectangle();
    // b.getName();}
    }
    });
    a3.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // CircleFrame c=new CircleFrame();
    // c.getName();
    }
    });
    }
    }