[英]Build a "About Me" GUI page in Java
我正在做一個 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);
但是我遇到了三個錯誤並且無法解決它,我真的需要一些幫助和提示。 謝謝你 !!
當抽象類被子類化時,子類通常為其父類中的所有抽象方法提供實現。 但是,如果不是,則子類也必須聲明為抽象的。
來源:https ://docs.oracle.com/javase/tutorial/java/IandI/abstract.htm
這意味着您必須提供自己的方法actionPerformed(ActionEvent)
。
您沒有聲明變量sPImg
和labelStatus
。 您需要定義要在 Java 中使用的任何變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.