java吧 关注:1,254,590贴子:12,742,564
  • 26回复贴,共1

求各路师傅,大神帮忙!!!

只看楼主收藏回复

如图 谢谢各位了!


1楼2014-06-08 15:53回复
    @ayane000


    2楼2014-06-08 15:55
    回复
      表示4个题,其他三个,不到20分钟就做完了,第二题解一元二次居然做不出来,数学差果然是个大问题.


      IP属地:湖北4楼2014-06-08 16:16
      收起回复
        /**
        * java简易记事本
        * @author Efy 2014-6-9 16:36:30
        *
        */
        public class NotePad{
        /**
        * 初始化
        */
        public void init(){
        //主窗体
        JFrame mainFrame = new JFrame("记事本");
        //设置主窗体大小
        mainFrame.setSize(550, 650);
        //主窗体居中显示
        mainFrame.setLocationRelativeTo(null);
        //主窗体关闭时退出程序
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //主面板
        JPanel mainPanel = new JPanel();
        //菜单栏
        JMenuBar menuBar = new JMenuBar();
        //菜单项
        JMenu menu = new JMenu("文件");
        //二级菜单项
        JMenuItem save = new JMenuItem("保存/Save");
        //二级菜单项
        JMenuItem open = new JMenuItem("打开/Open");
        //文本域
        JTextArea text = new JTextArea();
        //滚动条面板
        JScrollPane jSPane = new JScrollPane(text);
        //设置鼠标滚动速度
        jSPane.getVerticalScrollBar().setUnitIncrement(50);
        //自动换行
        text.setLineWrap(true);
        //断行不断字
        text.setWrapStyleWord(true);
        //文本域自动滚动
        text.setAutoscrolls(true);
        //文本域可见
        text.setVisible(true);
        //文本域外边距
        text.setMargin(new Insets(0,10,0,0));
        //各项组件按顺序添加
        menu.add(save);
        menu.add(open);
        menuBar.add(menu);
        mainPanel.add(jSPane);
        mainFrame.add(jSPane);
        //为菜单项注册监听
        menuListener(save,text);
        //为菜单项注册监听
        menuListener(open,text);
        //设置菜单栏
        mainFrame.setJMenuBar(menuBar);
        //主窗体为可见(最后设置主窗体可见,否则组件未加载完成时,会不显示)
        mainFrame.setVisible(true);
        }


        IP属地:湖北5楼2014-06-09 16:50
        回复
          /**
          * 菜单项的监听
          * @param item
          * @param text
          */
          private void menuListener(JMenuItem item,final JTextArea text) {
          item.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
          //默认保存时为F盘
          JFileChooser chooser = new JFileChooser("F:/");
          //过滤类型
          chooser.setFileFilter(new FileFilter() {
          @Override
          public String getDescription() {
          return null;
          }
          @Override
          public boolean accept(File f) {
          //只显示所有文件和txt后缀文件
          if(f.isDirectory()||f.getName().contains(".txt")){
          return true;
          }
          return false;
          }
          });
          //弹出文件选择窗
          chooser.showOpenDialog(null);
          //未选择文件则不执行
          if(chooser.getSelectedFile() == null){
          return;
          }
          //根据菜单执行不同方法
          if(e.getActionCommand().contains("保存") || e.getActionCommand().contains("Save")){
          try {
          //如果未键入后缀则自动添加后缀
          if(!chooser.getSelectedFile().getName().contains(".txt")){
          chooser.setSelectedFile(new File(chooser.getSelectedFile().getAbsolutePath()+".txt"));
          }
          saveFile(chooser.getSelectedFile(),text.getText());
          } catch (Exception e1) {
          e1.printStackTrace();
          }
          }else if(e.getActionCommand().contains("打开") || e.getActionCommand().contains("Open")){
          try {
          //读取文件内容
          String content = openFile(chooser.getSelectedFile());
          //将文件内容显示在文本域中
          text.setText(content);
          } catch (Exception e1) {
          e1.printStackTrace();
          }
          }
          }
          });
          }


          IP属地:湖北6楼2014-06-09 16:51
          回复
            /**
            * 保存当前内容为文本
            * @param text
            * @throws Exception
            */
            private void saveFile(File file,String text) throws Exception{
            FileOutputStream output;
            output = new FileOutputStream(file, false);
            output.write(text.getBytes());
            output.flush();
            output.close();
            }
            /**
            * 打开选择文件
            * @param file
            * @return
            */
            private String openFile(File file){
            BufferedReader input = null;
            String temp = null;
            StringBuffer content = new StringBuffer();
            try {
            input = new BufferedReader(new FileReader(file));
            while ((temp = input.readLine()) != null) {
            content.append(temp + "\r\n");
            }
            } catch (Exception e) {
            e.printStackTrace();
            }
            return content.toString();
            }
            public static void main(String[] args) {
            new NotePad().init();
            }
            }


            IP属地:湖北7楼2014-06-09 16:51
            回复
              只实现了基本功能,希望你能自己实现搜索,替换,文字格式等等,反正仿照windows的记事本来做.


              IP属地:湖北8楼2014-06-09 16:53
              收起回复
                @伤不起的小绵羊


                9楼2014-06-09 17:52
                收起回复
                  @Finaly游戏
                  学长帮帮忙,谢谢学长了


                  10楼2014-06-09 20:48
                  收起回复
                    加班到现在,,,,苦逼的IT啊..
                    package com.sunyard.etp.ag.util.test;
                    import java.awt.event.ActionEvent;
                    import java.awt.event.ActionListener;
                    import javax.swing.JButton;
                    import javax.swing.JFrame;
                    import javax.swing.JOptionPane;
                    import javax.swing.JPanel;
                    /**
                    * 猜数游戏
                    * @author Efy 2014-6-9 21:33:10
                    *
                    */
                    public class GuestNum {
                    private int num;
                    private void init(){
                    //主窗体
                    JFrame mainFrame = new JFrame("猜数游戏");
                    //设置主窗体大小
                    mainFrame.setSize(200, 100);
                    //主窗体居中显示
                    mainFrame.setLocationRelativeTo(null);
                    //主窗体关闭时退出程序
                    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    //主面板
                    JPanel mainPanel = new JPanel();
                    JButton start = new JButton("开始吧");
                    //各项组件按顺序添加
                    mainPanel.add(start);
                    mainFrame.add(mainPanel);
                    //为按钮注册监听
                    buttonListener(start);
                    //主窗体为可见(最后设置主窗体可见,否则组件未加载完成时,会不显示)
                    mainFrame.setVisible(true);
                    }
                    /**
                    * 开始按钮监听
                    * @param button
                    */
                    private void buttonListener(JButton button) {
                    button.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                    //100以内随机
                    num = (int) (Math.random()*100);
                    //标记是否猜对了
                    boolean flag = false;
                    //没猜对继续猜,直到猜对
                    while(!flag){
                    String inputNum = JOptionPane.showInputDialog("请输入数字");
                    try {
                    if(Integer.parseInt(inputNum) == num){
                    JOptionPane.showMessageDialog(null, "恭喜你猜对了~");
                    flag = true;
                    }else if(Integer.parseInt(inputNum) < num){
                    JOptionPane.showMessageDialog(null, "魂淡,人家怎么可能那么小嘛~");
                    }else{
                    JOptionPane.showMessageDialog(null, "没猜对哦,人家没你想的那么大啦~");
                    }
                    } catch (Exception e2) {
                    JOptionPane.showMessageDialog(null, "你输入的不是数字!");
                    }
                    }
                    }
                    });
                    }
                    /**
                    * @param args
                    */
                    public static void main(String[] args) {
                    new GuestNum().init();
                    }
                    }


                    IP属地:湖北11楼2014-06-09 21:44
                    收起回复
                      感觉应该很简单的吧


                      IP属地:江西13楼2014-06-10 12:35
                      收起回复