为了账号安全,请及时绑定邮箱和手机立即绑定

java内部类问题?

java内部类问题?

呼啦一阵风 2019-02-24 19:20:20
目的是实现一个具有切换圈圈颜色及标签内容的程序 package com.elyong.noway; /** * Created by ely ong on 2017/11/27. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TwoButtons{ JFrame frame; JLabel label; public static void main(String[] args){ TwoButtons gui=new TwoButtons(); gui.go(); } public void go(){ frame=new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton labelButton=new JButton("Change Label"); labelButton.addActionListener(new LabelListener()); JButton colorButton=new JButton("Change Circle"); colorButton.addActionListener(new ColorListener()); label=new JLabel("I'm a label"); MyDrawPanel drawPanel=new MyDrawPanel(); frame.getContentPane().add(BorderLayout.SOUTH,colorButton); frame.getContentPane().add(BorderLayout.CENTER,drawPanel); frame.getContentPane().add(BorderLayout.EAST,labelButton); frame.getContentPane().add(BorderLayout.WEST,label); frame.setSize(300,300); frame.setVisible(true); } class LabelListener implements ActionListener{ public void actionPerformed(ActionListener event){ label.setText("Ouch!"); } } class ColorListener implements ActionListener{ public void actionPerformed(ActionListener event){ frame.repaint(); } } } class MyDrawPanel extends JPanel{ public void paintComponent(Graphics g){ Graphics2D g2d=(Graphics2D) g; int red=(int)(Math.random()*255); int green=(int)(Math.random()*255); int blue=(int)(Math.random()*255); Color startColor=new Color(red,green,blue); red=(int)(Math.random()*255); green=(int)(Math.random()*255); blue=(int)(Math.random()*255); Color endColor=new Color(red,green,blue); GradientPaint gradient=new GradientPaint(70,70,startColor,150,150,endColor); g2d.setPaint(gradient); g2d.fillOval(70,70,100,100); } } 报错: Error:(32, 5) java: com.elyong.noway.TwoButtons.LabelListener不是抽象的, 并且未覆盖java.awt.event.ActionListener中的抽象方法actionPerformed(java.awt.event.ActionEvent) Error:(37, 5) java: com.elyong.noway.TwoButtons.ColorListener不是抽象的, 并且未覆盖java.awt.event.ActionListener中的抽象方法actionPerformed(java.awt.event.ActionEvent)
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 605 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信