我正在做一个GUI应用程序,现在正在构建GUI的“关于我”页面。此“关于我”应包含有关我自己的介绍以及我的照片。以下是我执行的代码:
import javax.swing.event.*;
import javax.swing.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
public class ContactMe extends JFrame implements ActionListener
{
JPanel panelTop = new JPanel(); // new GUI components
JButton butAboutMe = new JButton("About Me...");
JButton butOpenFile = new JButton("Open File...");
// ...
BufferedImage orgImg; // image of opened file
ContactMe()
{ // A No-Argument Constructor
setTitle ( "MyName Image Viewer X" ); //...
}
void initGUI()
{
panelTop.add(butOpenFile); //add buttons and slider to top JPanel
panelTop.add(butAboutMe);
add(panelTop, BorderLayout.NORTH); //add JPanel to top of JFrame
add(butOpenFile, BorderLayout.NORTH);
add(sPImg, BorderLayout.CENTER);
add(labelStatus, BorderLayout.SOUTH);
// registering this class object as event listener for the Button
butOpenFile.addActionListener(this);
// EVENT HANLDING below, with Anonymous Class approach:
// register a new listener object (of an anonymous class) to Button
butAboutMe.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
// show AboutMe Message Dialog window
JOptionPane.showMessageDialog(null,
"Members(left to right):\n" +
"MyName(ME)\n CHAN Tai Man\n CHAN Siu Man",
"About Me: G22m2, 2019-2020, OOP",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("AboutMe.jpg"));
} });
}
//...
public static void main(String[] args)
{ // Method to start program
(new Contact()).setVisible(true);
System.out.println("END of main() method!");
}
}
错误1:
error: Main is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
public class ContactMe extends JFrame implements ActionListener
错误2:
error: cannot find symbol sPImg
add(sPImg, BorderLayout.CENTER);
错误3:
error: cannot find symbol labelStatus
add(labelStatus, BorderLayout.SOUTH);
但是我遇到三个错误,无法解决,我确实需要一些帮助和提示。谢谢!
答案 0 :(得分:0)
当抽象类被子类化时,该子类通常提供 父类中所有抽象方法的实现。 但是,如果没有,则还必须声明子类 抽象。
来源:https://docs.oracle.com/javase/tutorial/java/IandI/abstract.htm
这意味着您必须提供方法actionPerformed(ActionEvent)
的自己的实现。
您没有声明变量sPImg
和labelStatus
。您需要定义要在Java中使用的任何变量。