求解!
  • 浏览:242 评论:0 人

  • package 多个按钮;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Frame1 extends JFrame implements ActionListener {
    JButton button;
    JButton str;
    JButton st;
    JButton su;
    JButton h1;
    JButton h2;
    Frame2 frame;
    public Frame1(){
    setTitle("控制系统开关");
    button=new JButton("电风扇");
    str=new JButton("空调");
    st=new JButton("电脑");
    su=new JButton("手机");
    h1=new JButton("遥控器");
    h2=new JButton("插座");
    button.addActionListener(this);
    str.addActionListener(this);
    st.addActionListener(this);
    su.addActionListener(this);
    h1.addActionListener(this);
    h2.addActionListener(this);
    this.setSize(300,100);
    this.add(button);
    this.add(str);
    this.add(st);
    this.add(su);
    this.add(h1);
    this.add(h2);
    this.setLayout(new FlowLayout());
    this.setVisible(true);

    }
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==button)
    {
    frame=new Frame2();
    }
    else if(e.getSource()==str){
    frame=new Frame2();
    }
    else if(e.getSource()==st){
    frame=new Frame2();
    }
    else if(e.getSource()==su){
    frame=new Frame2();
    }
    else if(e.getSource()==h1){
    frame=new Frame2();
    }
    else if(e.getSource()==h2){
    frame=new Frame2();
    }
    }
    public static void main(String[] args) {
    new Frame1();
    }

    }

    package 多个按钮;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Frame2 extends JFrame implements ActionListener{
    JButton a;
    JButton b;
    public Frame2(){
    setTitle("控制器");
    this.setSize(300,100);
    this.setLayout(new FlowLayout());
    this.setVisible(true);
    a=new JButton("开");
    b=new JButton("关");
    a.addActionListener(this);
    b.addActionListener(this);
    this.add(a);
    this.add(b);
    }
    public void actionPerformed(ActionEvent e) {

    }

    }


    怎么把start()和stop()方法写到里面去啊?各位大神!