简体   繁体   English

用 Java 构建“关于我”的 GUI 页面

[英]Build a "About Me" GUI page in Java

I am doing a GUI application, and now building the "About Me" page of the GUI.我正在做一个 GUI 应用程序,现在正在构建 GUI 的“关于我”页面。 This "About Me" should contain introduction about myself and also a picture of me.这个“关于我”应该包含我的自我介绍和一张我的照片。 Below are the codes I did:下面是我做的代码:

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!");
    }
}

Error 1:错误 1:

error: Main is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
public class ContactMe extends JFrame implements ActionListener

Error 2:错误 2:

error: cannot find symbol sPImg
add(sPImg, BorderLayout.CENTER);

Error 3:错误 3:

error: cannot find symbol labelStatus
 add(labelStatus, BorderLayout.SOUTH);

However I have got three errors and cannnot solve it, I really need some help and hints.但是我遇到了三个错误并且无法解决它,我真的需要一些帮助和提示。 Thank You !!谢谢你 !!

How to fix your errors如何修复您的错误

Error 1: Main is not abstract and does not override abstract method ...错误 1:Main 不是抽象的,并且没有覆盖抽象方法......

When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.当抽象类被子类化时,子类通常为其父类中的所有抽象方法提供实现。 However, if it does not, then the subclass must also be declared abstract.但是,如果不是,则子类也必须声明为抽象的。

Source:https://docs.oracle.com/javase/tutorial/java/IandI/abstract.htm来源:https ://docs.oracle.com/javase/tutorial/java/IandI/abstract.htm

This means you must provide your own implementation of the method actionPerformed(ActionEvent) .这意味着您必须提供自己的方法actionPerformed(ActionEvent)

Errors 2 and 3: cannot find symbol错误 2 和 3:找不到符号

You did not declare the variables sPImg and labelStatus .您没有声明变量sPImglabelStatus You need to define any variable that you want to use in Java.您需要定义要在 Java 中使用的任何变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM