0

我创建了一个注册表类,用于向注册表添加和删除学生,还包含一个学生类。现在我必须构建一个带有主菜单的界面,其中有 4 个选项可供选择,包括:添加学生、删除学生、打印注册表并退出。扫描仪将用于破译用户选择的选项。

我真的不知道如何创建这个,我得到了一个模板来填写,但我无法理解它。此外,由于我的 RegistryInterface 没有 main 方法,因此我必须创建一个 RegistryApp,我也有一个模板。

任何有关如何创建它的帮助/建议将不胜感激,我对界面构建完全陌生,抱歉!

RegistryInterface代码模板:

import java.util.*;
public class RegistryInterface {

private Registry theRegistry = null;

public RegistryInterface(Registry theRegistry){}

//Displays the main menu and gets valid option from user

public void doMenu()
{
    System.out.println("Registry Main Menu");
    System.out.println("****************** \n");
    System.out.println("1. Add a Student");
    System.out.println("2. Delete a Student");
    System.out.println("3. Print Registry");
    System.out.println("4. Quit");
    System.out.println("Select option [1, 2, 3, 4] :>");    
}


private void doAddStudent() {}


private void doDeleteStudent() {}


private void doPrintRegistry() {}

}

RegistryApp 代码模板:

public class RegistryApp {
public static void main (String[] args)
{
    //Create the registry object
    Registry theRegistry = new Registry();

    //Create an interface
    RegistryInterface aRegistryInterface
            = new RegistryInterface (theRegistry);

    //Display the menu
    aRegistryInterface.doMenu();
}

}
4

3 回答 3

0

RegistryInterface是一个类而不是一个接口

  • 必须像这样声明接口public interface
  • 它应该只包含要使用的属性和方法的声明,并且不应该包含任何实现
  • 您必须创建一个RegistryImpl实现此接口及其方法的类(如 )
  • 要使用它,您只需要创建一个界面实例(如RegistryInterface RI = new RegistryInterface(R);
于 2013-04-22T13:49:18.153 回答
0

这样的事情可能会有所帮助:

public interface RegistryInterface {

  //Displays the main menu and gets valid option from user
  public void doMenu();

  public void doAddStudent();

  public void doDeleteStudent();

  public void doPrintRegistry();

}

注册表:

public class Registy implements RegistryInterface {

    //java will force you to write methods the same as the ones declared in
    //RegistryInterface...
}

主类:

public static void main (String[] args)
{
  //Create the registry object
  RegistryInterface theRegistry = new Registry();

  //Display the menu
  theRegistry.doMenu();

   //etc...

}

于 2013-04-22T14:04:32.267 回答
-1

您似乎在谈论图形用户界面,如果您对 java GUI 完全陌生,那么http://docs.oracle.com/javase/tutorial/uiswing/上有一个非常详尽的教程

于 2013-04-22T13:54:27.210 回答