import java.util.ArrayList; import java.util.List; import java.util.Scanner;

/**

  • 导航菜单管理工具 */ public class NavigationMenu {

    private static List navigationItems = new ArrayList<>();

    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);

     boolean running = true;
     while (running) {
         System.out.println('请选择操作:');
         System.out.println('1. 添加导航项');
         System.out.println('2. 显示导航项');
         System.out.println('3. 退出程序');
    
         int option = scanner.nextInt();
         scanner.nextLine(); // consume the newline character
    
         switch (option) {
             case 1:
                 addNavigationItem(scanner);
                 break;
             case 2:
                 displayNavigationItems();
                 break;
             case 3:
                 running = false;
                 break;
             default:
                 System.out.println('无效的选项,请重新选择。');
                 break;
         }
     }
    
     scanner.close();
    

    }

    /**

    • 添加导航项

    • @param scanner 扫描器 */ private static void addNavigationItem(Scanner scanner) { System.out.println('请输入主标题:'); String title = scanner.nextLine();

      System.out.println('请选择标题样式:'); System.out.println('1. 标题样式1'); System.out.println('2. 标题样式2'); int styleOption = scanner.nextInt(); scanner.nextLine(); // consume the newline character String style = ''; switch (styleOption) { case 1: style = '样式1'; break; case 2: style = '样式2'; break; default: System.out.println('无效的选项,使用默认样式。'); style = '默认样式'; break; }

      System.out.println('请输入图表附图:'); String image = scanner.nextLine();

      System.out.println('请选择是否填充背景:'); System.out.println('1. 是'); System.out.println('2. 否'); int backgroundOption = scanner.nextInt(); scanner.nextLine(); // consume the newline character boolean fillBackground = false; switch (backgroundOption) { case 1: fillBackground = true; break; case 2: fillBackground = false; break; default: System.out.println('无效的选项,不填充背景。'); break; }

      System.out.println('请输入跳转的设置:'); String link = scanner.nextLine();

      NavigationItem newItem = new NavigationItem(title, style, image, fillBackground, link); navigationItems.add(newItem);

      System.out.println('导航项添加成功!'); }

    /**

    • 显示所有导航项 */ private static void displayNavigationItems() { System.out.println('导航项列表:'); if (navigationItems.isEmpty()) { System.out.println('暂无导航项。'); } else { for (NavigationItem item : navigationItems) { System.out.println('主标题:' + item.getTitle()); System.out.println('标题样式:' + item.getStyle()); System.out.println('图表附图:' + item.getImage()); System.out.println('填充背景:' + (item.isFillBackground() ? '是' : '否')); System.out.println('跳转设置:' + item.getLink()); System.out.println(); } } } }

/**

  • 导航项类 */ class NavigationItem { private String title; private String style; private String image; private boolean fillBackground; private String link;

    public NavigationItem(String title, String style, String image, boolean fillBackground, String link) { this.title = title; this.style = style; this.image = image; this.fillBackground = fillBackground; this.link = link; }

    public String getTitle() { return title; }

    public String getStyle() { return style; }

    public String getImage() { return image; }

    public boolean isFillBackground() { return fillBackground; }

    public String getLink() { return link; }

导航菜单创建工具 - 添加、管理、展示导航项

原文地址: https://www.cveoy.top/t/topic/pf1F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录