程序员学会这个Java系统详细设计的活马上月薪过万!

程序员学会这个Java系统详细设计的活马上月薪过万!

在这里插入图片描述
关于程序员对Java系统详细设计的设计思路,有很多人都会有一些误区,那么我们今天就来讲一下系统详细设计的具体思路,希望可以给大家带来帮助。

1.初始化组件

initTextContent();

initMenu();

initAboutDialog();

2.构建菜单栏及其下拉菜单

JMenu[] menus=new JMenu[]{

new JMenu(“文件”),

new JMenu(“编辑”),

new JMenu(“关于”)

};

JMenuItem optionofmenu[][]=new JMenuItem[][]{{

new JMenuItem(“新建”),

new JMenuItem(“打开”),

new JMenuItem(“保存”),

new JMenuItem(“退出”)

     },

{

new JMenuItem(“复制”),

new JMenuItem(“剪切”),

new JMenuItem(“粘贴”),

new JMenuItem(“颜色”)

           },

           {

           new JMenuItem("关于")

           }

    };

3.“文件”菜单的事件监听

ActionListener action=new ActionListener(){

 public void actionPerformed(ActionEvent e){

 	String name = e.getActionCommand();

JMenuItem MI=(JMenuItem)e.getSource();

if(“新建”.equals(name)){

content.setText("");

file=null;

}else if(“打开”.equals(name)){

                if(file !=null)openfile.setSelectedFile(file);

                int returnVal=openfile.showOpenDialog(mynotepad.this);

                if(returnVal==JFileChooser.APPROVE_OPTION){



                file=openfile.getSelectedFile();

                unfold();

                          }



 }else if("保存".equals(name)){

  if(file!=null) openfile.setSelectedFile(file);

      int returnVal=openfile.showSaveDialog(mynotepad.this);

            if(returnVal==JFileChooser.APPROVE_OPTION){

            file=openfile.getSelectedFile();

              saving();

                              }



         }else if("退出".equals(name)){

           mynotepad f=new mynotepad();

           int s=JOptionPane.showConfirmDialog(f,"退出?","退出",JOptionPane.YES_NO_OPTION);

4.“编辑”菜单的事件监听

else if(“剪切”.equals(name)){

           content.cut();

         }else if("复制".equals(name)){

           content.copy();

         }else if("粘贴".equals(name)){

           content.paste();

         }else if("颜色".equals(name)){

           color=JColorChooser.showDialog(mynotepad.this,"",color);

             content.setForeground(color);

5.异常处理

在运行程序代码是有可能会产生异常情况或异常事件,为了避免这种情况,就需要在程序中用到Java异常处理机制。本程序中选用的异常处理机制是try,catch。捕获处理异常的第一步是用try选定要监控的异常范围,try后跟随catch代码块。

saving(){

   try{

    FileWriter Writef=new FileWriter(file);

    Writef.write(content.getText());

    Writef.close();

     }

catch(Exception e){e.printStackTrace();}



              }                

void unfold(){

     try{

          FileReader Readf=new FileReader(file);

          int len=(int)file.length();

          char []buffer=new char[len];

          Readf.read(buffer,0,len);

          Readf.close();

          content.setText(new String(buffer));

          }catch(Exception e){e.printStackTrace();}



   }

转发 关注后私信我回复【架构资料】即可免费领取全套架构师学习资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值