麻烦高手帮我改一下这个程序import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class ccc extends JFrame implements ActionListener {JPanel n1;JButton n2;JButton n3;JButton n4
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 20:30:09
麻烦高手帮我改一下这个程序import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class ccc extends JFrame implements ActionListener {JPanel n1;JButton n2;JButton n3;JButton n4
麻烦高手帮我改一下这个程序
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ccc extends JFrame implements ActionListener {
JPanel n1;
JButton n2;
JButton n3;
JButton n4;
JButton n5;
JButton n6;
JButton n7;
JButton n8;
JButton n9;
public ccc(){
super("省份");
n1=new JPanel();
n2=new JButton("广东");
n3=new JButton("江苏");
n4=new JButton("浙江");
n5=new JButton("山东");
n6=new JButton("福建");
n7=new JButton("山西");
n8=new JButton("湖北");
n9=new JButton("湖南");
n1.setLayout(new GridLayout(2,4));
n1.add(n2);
n1.add(n3);
n1.add(n4);
n1.add(n5);
n1.add(n6);
n1.add(n7);
n1.add(n8);
n1.add(n9);
n2.addActionListener(this);
this.add(n1);
this.setSize(800,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new ccc(); }
public void actionPerformed(ActionEvent e){
\x05 System.out.println("广州");
}
当点击到“广东”时,打印出“广州”
当点击到江苏时,打印出“南京”
当点击到山东时,打印出济南
麻烦高手帮我改一下这个程序import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class ccc extends JFrame implements ActionListener {JPanel n1;JButton n2;JButton n3;JButton n4
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ccc extends JFrame implements ActionListener {
JPanel n1;
// JButton n2;
// JButton n3;
// JButton n4;
// JButton n5;
// JButton n6;
// JButton n7;
// JButton n8;
// JButton n9;
JButton n[]=new JButton[8];
String s[]={"广东","江苏","浙江","山东","福建","山西","湖北","湖南"};
public ccc(){
super("省份");
n1=new JPanel();
// n2=new JButton("广东");
// n3=new JButton("江苏");
// n4=new JButton("浙江");
// n5=new JButton("山东");
// n6=new JButton("福建");
// n7=new JButton("山西");
// n8=new JButton("湖北");
// n9=new JButton("湖南");
n1.setLayout(new GridLayout(2,4));
// n1.add(n2);
// n1.add(n3);
// n1.add(n4);
// n1.add(n5);
// n1.add(n6);
// n1.add(n7);
// n1.add(n8);
// n1.add(n9);
// n2.addActionListener(this);
for(int i=0;i<n.length;i++){
n[i]=new JButton(s[i]);
n1.add(n[i]);
n[i].addActionListener(this);
}
this.add(n1);
this.setSize(800,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new ccc(); }
public void actionPerformed(ActionEvent e){
JButton b=(JButton) e.getSource();
System.out.println(b.getText());
}
}