本文介绍了我的代码plzzz出了什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是Java GUI的简单代码,它给了我错误
ExampleD不是抽象的,并且不会覆盖ActionListener中的抽象方法actionPerformed(ActionEvent)
公共类ExampleD扩展JFrame实现ActionListener
this is a simple code for JAVA GUI it gives me the error
ExampleD is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
public class ExampleD extends JFrame implements ActionListener
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ExampleD extends JFrame implements ActionListener//?
{
Container c;
JLabel lbl1,lbl2;
JTextField txt1,txt2;
public ExampleD()
{
c=getContentPane();
c.setBackground(Color.GRAY);
c.setLayout(new FlowLayout(FlowLayout.LEFT));
lbl1=new JLabel("enter the width");
lbl2=new JLabel("enter the hight");
txt1=new JTextField(10);
txt2=new JTextField(10);
txt1.addActionListener(this);//?
txt2.addActionListener(this);//?
c.add(lbl1);
c.add(txt1);
c.add(lbl2);
c.add(txt2);
setTitle("ExampleD");
setSize(800,600);
setVisible(true);
}//end container
public void main(Graphics g)
{
super.paint(g);
int x=0;
int y=0;
x=Integer.parseInt(txt1.getText());
y=Integer.parseInt(txt2.getText());
//g.setBackground(Color.BLUE);
g.fillRect(100,100,x+10,y+10);
}//end paint
public void ActionPerformed(ActionEvent e)
{
repaint();
}//public static void main(String args[])
{
ExampleD e2=new ExampleD();
}
}
推荐答案
public void actionPerformed(ActionEvent e) {
repaint();
}
请尝试格式化"代码,以便为您提供更多概述.
在Eclipse中,右键单击-> 源"-> 格式"
在Netbeans中应该相等.
Please try to "format" the code, that gives you more overview.
In Eclipse that is right click -> "Source" -> "format"
Should be equal in Netbeans.
这篇关于我的代码plzzz出了什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!