JButtons执行相同的任务

时间:2017-11-28 16:38:41

标签: java swing jbutton actionlistener actionevent

我正在尝试使用两个J按钮创建一个程序来完成不同的任务。但是当我运行程序时,两个按钮都做同样的事情。我猜它是因为它是因为“this”关键字。谁能告诉我哪里出错?

import javax.swing.*;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class NextPage extends JFrame implements ActionListener{
    NextPage()
    {
        JTabbedPane tabbedPane1 = new JTabbedPane();
        JLabel label = new JLabel();

        JButton docbutton = new JButton();   //second button
        JPanel panel1 = new JPanel();
        JPanel panel2 = new JPanel();
        JPanel panel3 = new JPanel();

        tabbedPane1.add("booking",panel1);
        tabbedPane1.add("Doctors Screen",panel2);
        tabbedPane1.add("Register",panel3);
        JFrame frame = new JFrame();
        frame.add(tabbedPane1);
        frame.setSize(600, 500);
        frame.setTitle("Welcome to DoctorsCare");

        frame.setVisible(true);

        JButton button = new JButton();         //first button  
        button.setLabel("Take Appointment");
        button.setPreferredSize(new Dimension(160,40));
        panel1.add(button);

        button.addActionListener(this);
        docbutton.setLabel("patient-1");
        panel2.add(docbutton);
        docbutton.addActionListener(this); 
    }

    public void actionPerformed(ActionEvent ae)
    {
            BookingPage page = new BookingPage();   
        }

    public void ap(ActionEvent ae)
    {
            DoctorsScreen dscrn = new DoctorsScreen();
        }
        }

0 个答案:

没有答案