BufferedReader简单的菜单
Menu
boolean flag; public Menu() { while(true) { this.show(); } } public void show() { System.out.println("--------菜单管理--------"); System.out.println(" [1] 创建菜单 "); System.out.println(" [2] 修改菜单 "); System.out.println(" [3] 删除菜单 "); System.out.println(" [0] 退出菜单 "); System.out.println("请选择相关的菜单进行操作:"); BufferedReader buf = null; buf = new BufferedReader( new InputStreamReader( System.in ) ); String str = null; int i = 0; this.flag = true; while(flag) { try { str = buf.readLine(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } if(str.matches("\\d")) { i = Integer.parseInt(str); operater(i); }else{ System.out.println("请重新选择一个菜单:"); } } } public void operater(int i) { switch(i) { case 1: MenuOperater.add(); break; case 2: MenuOperater.update(); break; case 3: MenuOperater.del(); break; case 0: this.flag = false; MenuOperater.exit(); System.exit(1); break; default: System.out.println("您输入了一个错误的数字"); break; } }
MenuOperater
public static void add() { System.out.println("新建菜单操作"); } public static void update() { System.out.println("修改菜单操作"); } public static void del() { System.out.println("删除菜单操作"); } public static void exit() { System.out.println("退出菜单"); }
BufferedReaderDemo3
public static void main(String[] args) { // TODO 自动生成的方法存根 new Menu(); }
时间: 2024-10-11 11:32:47