| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 302 人关注过本帖
标题:没看出错在哪里,请老司机帮看看,谢谢
只看楼主 加入收藏
notbad301
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2018-2-17
结帖率:100%
  已结贴   问题点数:20  回复次数:2   
没看出错在哪里,请老司机帮看看,谢谢
执行不了,但没看出来哪里有错,请老司机帮看看。

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

    public class Gaibianyanse extends JFrame implements ActionListener{
     Button bt1,bt2;
     JPanel jp1,jp2;
   
    public static void main(String[] args) {
        Gaibianyanse keke=new Gaibianyanse();
    }

    public Gaibianyanse() {
        bt1=new Button("红色");
        bt2=new Button("绿色");
        jp1=new JPanel();
        jp2=new JPanel();
        bt1.addActionListener(this);
        bt2.addActionListener(this);
        bt1.setActionCommand("Tutu");
        bt2.setActionCommand("Kaka");
        jp2.add(bt1);
        jp2.add(bt2);
        jp2.setLayout(new FlowLayout(FlowLayout.CENTER));
        
        this.setLayout(new GridLayout(2,1));
        this.add(jp1);
        this.add(jp2);
        
        this.setTitle("改颜色的面板");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setLocation(300, 300);
        this.setSize(300,300);        
    }
   
    public void ActionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("Tutu")) {
            jp1.setBackground(Color.BLACK);
        }
        else if(e.getActionCommand().equals("Kaka")) {
            jp1.setBackground(Color.RED);
            }
    }
    }
2018-03-09 18:33
疯狂的小a
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:383
专家分:1679
注 册:2018-2-6
  得分:20 
程序代码:
package com.xiaoa.demo;

import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Gaibianyanse extends JFrame implements ActionListener {
    Button bt1, bt2;
    JPanel jp1, jp2;

    public static void main(String[] args) {
        Gaibianyanse keke = new Gaibianyanse();
    }

    public Gaibianyanse() {
        bt1 = new Button("红色");
        bt2 = new Button("绿色");
        jp1 = new JPanel();
        jp2 = new JPanel();
        bt1.addActionListener(this);
        bt2.addActionListener(this);
        bt1.setActionCommand("Tutu");
        bt2.setActionCommand("Kaka");
        jp2.add(bt1);
        jp2.add(bt2);
        jp2.setLayout(new FlowLayout(FlowLayout.CENTER));

        this.setLayout(new GridLayout(2, 1));
        this.add(jp1);
        this.add(jp2);

        this.setTitle("改颜色的面板");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setLocation(300, 300);
        this.setSize(300, 300);
    }
    @Override
    //方法名首字母小写,否则就不是重写方法了actionPerformed
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Tutu")) {
            jp1.setBackground(Color.BLACK);
        } else if (e.getActionCommand().equals("Kaka")) {
            jp1.setBackground(Color.RED);
        }
    }
}

假如人生没有梦想,和咸鱼有什么区别!
2018-03-09 19:57
notbad301
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2018-2-17
  得分:0 
谢谢!
2018-03-09 20:05







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033845 second(s), 9 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved