the type must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
publicclassRandomTestextendsJFrameimplementsActionListener{JTextFieldr1,r2,r3;JLabelb...
public class RandomTest extends JFrame implements ActionListener{
JTextField r1,r2,r3;
JLabel b1,b2,b3;
JButton jb;
JPanel jp;
public RandomTest(){
super("RandomTest");
jp=new JPanel();
b1=new JLabel("R");
b2=new JLabel("G");
b3=new JLabel("B");
r1=new JTextField(3);
r2=new JTextField(3);
r3=new JTextField(3);
jb=new JButton("确定");
jb.addActionListener(this);
jp.add(b1);
jp.add(r1);
jp.add(b2);
jp.add(r2);
jp.add(b3);
jp.add(r3);
jp.add(jb);
jp.setLayout(new FlowLayout());
add(jp,BorderLayout.CENTER);
setSize(400,400);
setResizable(false);
setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
setVisible(true);
}
public void randomcolor(ActionEvent e){
if(e.getSource().getClass().getSimpleName().equals("JButton"))
{
Random r1 = new Random();
Random r2 = new Random();
Random r3 = new Random();
int r= r1.nextInt(255);
int g= r2.nextInt(255);
int b= r3.nextInt(255);
Color c=new Color(r,g,b);
jp.setBackground(c);
}
}
public static void main(String[] args) {
new RandomTest();
}
}
我的想法是实现背景随机色,但是 RandomTest 那里提示the type must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
本人纯新手,跪求高手指点. 展开
JTextField r1,r2,r3;
JLabel b1,b2,b3;
JButton jb;
JPanel jp;
public RandomTest(){
super("RandomTest");
jp=new JPanel();
b1=new JLabel("R");
b2=new JLabel("G");
b3=new JLabel("B");
r1=new JTextField(3);
r2=new JTextField(3);
r3=new JTextField(3);
jb=new JButton("确定");
jb.addActionListener(this);
jp.add(b1);
jp.add(r1);
jp.add(b2);
jp.add(r2);
jp.add(b3);
jp.add(r3);
jp.add(jb);
jp.setLayout(new FlowLayout());
add(jp,BorderLayout.CENTER);
setSize(400,400);
setResizable(false);
setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
setVisible(true);
}
public void randomcolor(ActionEvent e){
if(e.getSource().getClass().getSimpleName().equals("JButton"))
{
Random r1 = new Random();
Random r2 = new Random();
Random r3 = new Random();
int r= r1.nextInt(255);
int g= r2.nextInt(255);
int b= r3.nextInt(255);
Color c=new Color(r,g,b);
jp.setBackground(c);
}
}
public static void main(String[] args) {
new RandomTest();
}
}
我的想法是实现背景随机色,但是 RandomTest 那里提示the type must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
本人纯新手,跪求高手指点. 展开
1个回答
展开全部
继承ActionListener的时候要实现里面的actionPerformed方法,
可参考http://zhidao.baidu.com/question/372024883.html
可参考http://zhidao.baidu.com/question/372024883.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询