5. java代码怎么用记事本写 下载JDK后,总点下一步让他默认安装 。
安装的结果在C:\Program Files\Java下面 。
然后就设环境变量:(方法如下)
1.在桌面上右击"我的电脑"图标,选择"属性"
再选"高级",再点"环境变量"
2.在系统变量中双击path(不分大小写,如果找不到path则点新建,新建变量path),在变量值的最后面添加: ;C:\Program Files\Java\jdk1.5.0_01\bin (前面的小分号不能省哦)
3.再在系统变量中新建变量名:classpath
在值的最后面加上: ;C:\Program Files\Java\jdk1.5.0_01\lib\tools.jar
4.再在系统变量中新建变量名: java_home
在值的最后面加上: ;C:\Program Files\Java
你再去桌面,点击“开始”“运行”
输入cmd 回车,(为了简单你把你的java文件复制到 e盘根目录下好吧 。)在黑色屏幕中输入e:
再回车,再输入: javac 文件名.java 如果没错误,再输入: java 文件名 就运行了
6. JAVA记事本程序怎么写 这是一个我以前写的简单的记事本,里面有新建,保存,另存,打开等功能,但是只是逻辑最简单的那种,你看看吧,希望对你有帮助;import java.awt.FileDialog;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;public class NotePad { public static void main(String[] args) { NotePadFrame notPadFrame = new NotePadFrame(); notPadFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); notPadFrame.setVisible(true); }}class NotePadFrame extends JFrame { private JMenu jmb, jmb1; private JMenuBar Jmenu = new JMenuBar(); private JMenuItem fm, fm1, fm2, fm3, fm4, fe1, fe2, fe3, fe4; String fileName, copy, paste, cut; NotePadPanel notePadPanel = new NotePadPanel(this); private NotePadFrame f; public NotePadFrame() { jmb = new JMenu("文件"); this.setJMenuBar(Jmenu); fm = new JMenuItem("新建"); jmb.add(fm); jmb.addSeparator(); // 新建 fm.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (e.getSource() == fm) { if (!(notePadPanel.getTa().getText()).equals("")) { Object[] options = ; int response = JOptionPane.showOptionDialog(null, "你是否保存", "提示", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (response == 0) { FileDialog d = new FileDialog(f, "保存文件", FileDialog.SAVE); d.setVisible(true); fileName = d.getDirectory() + d.getFile(); FileOutputStream fout = new FileOutputStream( fileName + ".txt"); byte[] bb = notePadPanel.getTa().getText() .getBytes(); fout.write(bb); // 关闭 fout.close(); JOptionPane.showMessageDialog(null, "已保存"); notePadPanel.getTa().setText(""); } if (response == 1) { JOptionPane.showMessageDialog(null, "你选择了取消"); notePadPanel.getTa().setText(""); } } } } catch (Exception e2) { System.out.println(e2.getMessage()); } } }); fm1 = new JMenuItem("打开"); jmb.add(fm1); jmb.addSeparator(); // 打开文件 fm1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (e.getSource() == fm1) { FileDialog d = new FileDialog(f, "打开文件", FileDialog.LOAD); d.setVisible(true); File file = new File(d.getDirectory() + d.getFile()); for (int i = 0; i <= file.length(); i++) { char[] ch = new char[1024]; FileReader fr = new FileReader(file); fr.read(ch); String str = new String(ch); notePadPanel.getTa().setText(str); } } } catch (IOException e3) { System.out.println(e3.getMessage()); } } }); fm2 = new JMenuItem("保存"); jmb.add(fm2); jmb.addSeparator(); // 保存文件 fm2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (e.getSource() == fm2) { if (fileName == null) { fileName = JOptionPane.showInputDialog("请输入文件名", "java"); FileOutputStream fout = new FileOutputStream( fileName + ".txt"); byte[] bb = notePadPanel.getTa().getText() .getBytes(); fout.write(bb); // 关闭 fout.close(); JOptionPane.showMessageDialog(null, "已保存"); } else { FileOutputStream fout = new FileOutputStream( fileName + ".txt"); byte[] bb = notePadPanel.getTa().getText() .getBytes(); fout.write(bb); // 关闭 fout.close(); JOptionPane.showMessageDialog(null, "已保存"); } } } catch (IOException e1) { System.out.println(e1.getMessage()); } } }); fm3 = new JMenuItem("另存为"); jmb.add(fm3); jmb.addSeparator(); // 另存为 fm3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() == fm3) { try { FileDialog d = new FileDialog(f, "另存为", FileDialog.SAVE); d.setVisible(true); fileName = d.getDirectory() + d.getFile(); FileOutputStream fout = new FileOutputStream(fileName + ".txt"); byte[] bb = notePadPanel.getTa().getText().getBytes(); fout.write(bb); // 关闭 fout.close(); } catch (Exception e4) { System.out.println(e4.getMessage()); } } } }); fm4 = new JMenuItem("关闭"); jmb.add(fm4); fm4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() == fm4) { System.exit(0); } } }); jmb1 = new JMenu("编辑"); fe1 = new JMenuItem("复制"); jmb1.add(fe1); jmb1.addSeparator(); fe1.addActionListener(new ActionListener() { public void actionPerformed( 。