importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassesextendsJFrameimplementsActionListener{JPaneln1;JButtonn2;JButtonn3;JButtonn4;JButtonn5;JButtonn6;...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class es extends JFrame implements ActionListener {
JPanel n1;
JButton n2;
JButton n3;
JButton n4;
JButton n5;
JButton n6;
JButton n7;
public es(){
super("科目");
n2=new JButton("语文");
n3=new JButton("数学");
n4=new JButton("英语");
n5=new JButton("物理");
n6=new JButton("化学");
n7=new JButton("生物");
n2.addActionListener(this);
n3.addActionListener(this);
n4.addActionListener(this);
n5.addActionListener(this);
n6.addActionListener(this);
n7.addActionListener(this);
n1.setLayout(new GridLayout(2,3));
n1.add(n2);
n1.add(n3);
n1.add(n4);
n1.add(n5);
n1.add(n6);
n1.add(n7);
this.add(n1);
this.setVisible(true);
this.setSize(600, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
public static void main(String[] args) {
new es();}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==n2){
System.out.println(e.getActionCommand()+"语文老师上");}
else if(e.getSource()==n3) {
System.out.println(e.getActionCommand() +"数学老师上");
} else if(e.getSource()==n4) {
System.out.println(e.getActionCommand() +"英语老师上");}
else if(e.getSource()==n5) {
System.out.println(e.getActionCommand()+"物理老师上");}
else if(e.getSource()==n6) {
System.out.println(e.getActionCommand()+"化学老师上");}
else if(e.getSource()==n7) {
System.out.println(e.getActionCommand()+"生物老师上");}
}}
展开