java编译文本
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EditorJFrame extends JFrame implements ActionListener, ItemListener, MouseListener
{
private JTextField text_size; //字号文本行
private JCheckBox checkbox_bold, checkbox_italic; //粗体、斜体复选框
private JButton button_cut, button_, button_paste; //剪切、复制、粘贴按钮
private JTextArea textarea; //文本区
private JPopupMenu popupmenu; //快捷菜单
private JDialog dialog; //出错提示对话框
private JLabel label_dialog; //对话框中的标签
public EditorJFrame()
{
super("文本编辑器"); //默认BorderLayout布局
this.setSize(500,300);
this.setLocation(300,240);
this.setDefaultCloseOperation(EXIT_ON_CLOSE); //单击窗口关闭按钮时,结束程序运行
textarea = new JTextArea("TextArea");
textarea.addMouseListener(this); //为文本区注册鼠标事件监听器
this.add(textarea); //文本区添加到框架的中部
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); //面板为流布局,左对齐
this.add(panel,"North"); //面板添加到框架的北部
text_size = new JTextField("12",10);
panel.add(text_size);
text_size.addActionListener(this); //注册文本行的单击事件监听器
checkbox_bold = new JCheckBox("粗体"); //复选框
panel.add(checkbox_bold);
checkbox_bold.addItemListener(this); //注册复选框的选择事件监听器
checkbox_italic = new JCheckBox("斜体");
panel.add(checkbox_italic);
checkbox_italic.addItemListener(this);
this.addmyMenu(); //调用自定义方法,添加菜单
this.setVisible(true);
}
private void addmyMenu() //添加主菜单、快捷菜单、对话框
{
JMenuBar menubar = new JMenuBar(); //菜单栏
this.setJMenuBar(menubar); //框架上添加菜单栏
JMenu menu_file = new JMenu("文件"); //菜单
menubar.add(menu_file); //菜单栏中加入菜单
menu_file.add(new JMenuItem("打开")); //生成菜单项并加入到菜单
menu_file.add(new JMenuItem("保存"));
menu_file.addSeparator(); //加分隔线
JMenuItem menuitem_exit = new JMenuItem("退出");
menu_file.add(menuitem_exit);
menuitem_exit.addActionListener(this); //为菜单项注册单击事件监听器
JMenu menu_edit = new JMenu("编辑");
menubar.add(menu_edit);
JMenu menu_style = new JMenu("字形");
menu_style.add(new JCheckBoxMenuItem("粗体")); //复选菜单项
menu_style.add(new JCheckBoxMenuItem("斜体"));
menu_edit.add(menu_style); //菜单加入到菜单中成为二级菜单
JMenu menu_color = new JMenu("颜色");
menu_edit.add(menu_color);
ButtonGroup buttongroup = new ButtonGroup(); //按钮组
JRadioButtonMenuItem rbmi_red = new JRadioButtonMenuItem("红",true); //单选菜单项
buttongroup.add(rbmi_red); //单选菜单项添加到按钮组
menu_color.add(rbmi_red); //单选菜单项添加到菜单
JRadioButtonMenuItem rbmi_green = new JRadioButtonMenuItem("绿",true);
buttongroup.add(rbmi_green);
menu_color.add(rbmi_green);
JRadioButtonMenuItem rbmi_blue = new JRadioButtonMenuItem("蓝",true);
buttongroup.add(rbmi_blue);
menu_color.add(rbmi_blue);
menubar.add(new JMenu("帮助"));
popupmenu = new JPopupMenu(); //弹出式菜单对象
JMenuItem menuitem_cut = new JMenuItem("剪切");
menuitem_cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK));//设置快捷键Ctrl+X
popupmenu.add(menuitem_cut); //加入剪切菜单项
menuitem_cut.addActionListener(this);
JMenuItem menuitem_ = new JMenuItem("复制");
menuitem_.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));//设置快捷键Ctrl+C
popupmenu.add(menuitem_);
menuitem_.addActionListener(this);
JMenuItem menuitem_paste = new JMenuItem("粘贴");
menuitem_paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));//设置快捷键Ctrl+V
popupmenu.add(menuitem_paste);
menuitem_paste.addActionListener(this);
textarea.add(popupmenu); //文本区添加快捷菜单
dialog = new JDialog(this,"提示");
dialog.setSize(240,80);
label_dialog = new JLabel("",JLabel.CENTER);
dialog.add(label_dialog);
dialog.setDefaultCloseOperation(HIDE_ON_CLOSE); //单击对话框的关闭按钮时,隐藏对话框而不结束程序运行
}
public void actionPerformed(ActionEvent e) //单击事件处理程序
{
if(e.getActionCommand()=="退出") //不能用switch(int)语句
System.exit(0); //单击菜单项时结束程序
if(e.getActionCommand()=="剪切")
textarea.cut(); //将选中文本剪切送系统剪贴板
if(e.getActionCommand()=="复制")
textarea.();
if(e.getActionCommand()=="粘贴")
textarea.paste();
if(e.getSource()==text_size) //单击文本行时,改变字号
{
int size=0;
try
{
size = Integer.parseInt(text_size.getText());
if (size<=0 || size>72)
throw new Exception("SizeException"); //抛出异常对象
java.awt.Font font = textarea.getFont();
textarea.setFont(new Font(font.getName(),font.getStyle(),size));
}
catch(NumberFormatException nfe)
{
label_dialog.setText("\""+text_size.getText()+"\" 不能转换成整数,请重新输入!");
dialog.setLocation(this.getX()+100,this.getY()+100);
dialog.setVisible(true);
}
catch(Exception ex)
{
if (ex.getMessage()=="SizeException") //捕获自己抛出的异常对象
{
label_dialog.setText(size+" 字号不合适,请重新输入!");
dialog.setLocation(this.getX()+100,this.getY()+100);
dialog.setVisible(true);
}
}
finally{}
}
}
public void itemStateChanged(ItemEvent e) //复选框选择事件处理程序
{ //实现ItemListener接口中的方法
Font font = textarea.getFont();
int style = font.getStyle();
if (e.getSource()==checkbox_bold)
style = style ^ 1; //整数的位运算,异或^
if (e.getSource()==checkbox_italic)
style = style ^ 2;
textarea.setFont(new Font(font.getName(),style,font.getSize()));
}
public void mouseClicked(MouseEvent mec) //单击鼠标时触发
{ //实现MouseListener接口中的方法
if (mec.getModifiers()==mec.BUTTON3_MASK) //单击的是鼠标右键
popupmenu.show(textarea,mec.getX(),mec.getY());//在鼠标单击处显示快捷菜单
}
public void mousePressed(MouseEvent mep) { }
public void mouseReleased(MouseEvent mer) { }
public void mouseEntered(MouseEvent mee) { }
public void mouseExited(MouseEvent mex) { }
public void mouseDragged(MouseEvent med) { }
public static void main(String arg[])
{
new EditorJFrame();
}
}
B. 如和用java编写文本
我写了两个类
使用方法:把这两个类保存了,第一个类的命名为Edit.java,第二个类的命名为WindowEdit.java
然后javac Edit.java ,最后输入java Edit,这样就相当于一个简单的文件编辑器
参考链接http://student.csdn.net/space.php?uid=362253&do=blog&id=36612
第一个:
public class Edit {
public static void main (String[] args){
new WindowEdit ();
}
}
第二个:
import javax.swing.* ;
import java.io.* ;
import java.awt.event.* ;
class WindowEdit {
private JFrame frame = null ; //声明窗体
private JButton open = null ; //打开按钮
private JButton save = null ; //保存按钮
private JTextField text = null ; //路径文本区
private JTextArea area = null ; //查看文本域
private JScrollPane jsp = null ; //滚动条
private boolean flag = true ; //设置标志位
public WindowEdit (){ //构造方法
frame = new JFrame ("文件编辑器"); //实例化窗体,并设置名称
open = new JButton ("打开"); //实例化按钮
save = new JButton ("保存"); //实例化按钮
text = new JTextField ("在此输入打开文件的路径名" , 50); //实例化文本区
area = new JTextArea (); //实例化文本域
jsp = new JScrollPane (area); //实例化滚动条
frame.setLayout (null); //把默认布局设为空
frame.add (open); //添加组件
frame.add (save); //添加组件
frame.add (text); //添加组件
frame.add (jsp); //添加组件
text.setBounds (10,10,390,25); //设置组件位置
open.setBounds (410, 10 , 70 , 24); //设置组件位置
jsp.setBounds (10, 45 , 480 , 380); //设置组件位置
save.setBounds (240,430,70,24); //设置组件位置
frame.addWindowListener (new WindowAdapter (){ //设置窗体监听
public void windowClosing (WindowEvent e){ //窗体监听方法
System.exit (1);
}
});
open.addActionListener (new ActionListener (){ //设置对“打开”按钮的监听
public void actionPerformed (ActionEvent arg0){
while (flag){
if (arg0.getSource () == open){ //如果按钮的事件是"open"按钮的话,则发生以下事件
String path = text.getText (); //通过文本区,取得文件路径
File file = new File (path); //实例化文件
Reader reader = null ; //用字符流读入内容,避免中文乱码
try {
reader = new FileReader (file); //实例化字符流
}catch (Exception e){
e.printStackTrace ();
}
try {
char c[] = new char[(int)file.length ()] ; //设置字符数组的长度,根据文件的长度确定,避免越界
int len = 0 ; //设置读出内容的长度
len = reader.read (c); //读入数据
reader.close (); //关闭数据流
area.append (new String (c,0,len)); //为文本域输入内容
flag = false ; //只对open按钮监听一次
}catch (Exception e){
e.printStackTrace ();
}
}
}
}
});
save.addActionListener (new ActionListener (){ //设置对“保存”按钮的监听
public void actionPerformed (ActionEvent arg1){
if (arg1.getSource () == save){ //如果按钮的事件是"save"按钮的话,则发生以下事件
Writer writer = null ; //用字符流写入内容,避免中文乱码
String path = text.getText (); //通过文本区,取得文件路径
File file = new File (path); //得到写入文件的路径
try {
writer = new FileWriter (file); //实例化字符流对象
}catch (Exception e){
e.printStackTrace ();
}
try {
String str = area.getText (); //得到文本域的字符串对象
writer.write (str); //为文件写入内容
writer.close (); //关闭数据流
}catch (Exception e){
e.printStackTrace ();
}
}
}
});
frame.setSize (500,500); //设置窗体大小
frame.setVisible (true); //设置窗体可见性
}
}
C. 你好,我java文本写好了该如何去编译
你安装JDK了吗?
如果没有,先安装JDK,现在最新的正式版本为JDK7(也叫做JDK1.7),安装完成后,配置环境变量(网络搜索配置Java环境变量,非常简单)。
然后点击“开始”--“运行”---“cmd”, 打开dos窗口,然后类似于如下方式运行:
C:\> javac Example.java
C:\> java Example
提醒:如果你不知道自己电脑上是否安装了JDK,那么就在dos窗口中输入以下命令:
java -versioin 看看,如果安装了,则会显示JDK版本信息
D. 如何将java的class反编译为.j文本文件又如何将.j文件重新编译
网上有很多的反编译工具,基本都是简单的视图界面形式。你只要选择对应的class文件的路径,点反编译即可。想重新编译.java文件,如果是单个文件的话,开始--》运行--》cmd--》进入dos命令行,输入javac 要编译的文件名即可。如果要编译整个项目的话,就要借助TOMCAT,WEBLOGIC等应用服务器软件了,或者用myeclipse也能自动编译的。
E. 用java制作一个简单的文本编译器,要能保存、打开,并对打开的文字进行字体、颜色、大小的设置~帮忙好吗
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
public class wawu{
public static void main(String args[]){
EditWindowKeyEvent win=new EditWindowKeyEvent();
win.setVisible(true);
win.setTitle("Notebook");
}
}
class EditWindowKeyEvent extends JFrame implements ActionListener {
int s=14,f=Font.PLAIN;
JMenuBar menubar;
JMenu menu1,menu2,color,font,size;
JMenuItem open,save,red,blue,yellow,green,bold,italic,size16,size32,size48,size64;
JTextArea text;
JFileChooser fileDialog;
BufferedReader in;
FileReader fileReader;
BufferedWriter out;
FileWriter fileWriter;
EditWindowKeyEvent(){
init();
setBounds(150,160,280,290);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
void init(){
menubar=new JMenuBar();
menu1=new JMenu("File");
menu2=new JMenu("Format");
open=new JMenuItem("Open");
save=new JMenuItem("Save");
color=new JMenu("Color");
font=new JMenu("Font");
size=new JMenu("Size");
red=new JMenuItem("Red");
yellow=new JMenuItem("Yellow");
green=new JMenuItem("Green");
blue=new JMenuItem("Blue");
bold=new JMenuItem("Bold");
italic=new JMenuItem("Italic");
size16=new JMenuItem("Size16");
size32=new JMenuItem("Size32");
size48=new JMenuItem("Size48");
size64=new JMenuItem("Size64");
menubar.add(menu1);
menubar.add(menu2);
setJMenuBar(menubar);
fileDialog=new JFileChooser();
menu1.add(open);
menu1.add(save);
menu2.add(color);
menu2.add(font);
color.add(red);
color.add(yellow);
color.add(green);
color.add(blue);
font.add(bold);
font.add(italic);
font.add(size);
size.add(size16);
size.add(size32);
size.add(size48);
size.add(size64);
text=new JTextArea();
text.setEditable(true);
add(new JScrollPane(text),BorderLayout.CENTER);
open.addActionListener(this);
save.addActionListener(this);
color.addActionListener(this);
font.addActionListener(this);
red.addActionListener(this);
yellow.addActionListener(this);
green.addActionListener(this);
blue.addActionListener(this);
bold.addActionListener(this);
italic.addActionListener(this);
size16.addActionListener(this);
size32.addActionListener(this);
size48.addActionListener(this);
size64.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==open){
int state=fileDialog.showOpenDialog(this);
if(state==JFileChooser.APPROVE_OPTION){
text.setText(null);
try{
File dir=fileDialog.getCurrentDirectory();
String name=fileDialog.getSelectedFile().getName();
File file=new File(dir,name);
fileReader=new FileReader(file);
in=new BufferedReader(fileReader);
String s=null;
while((s=in.readLine())!=null){
text.append(s+"\n");
}
in.close();
fileReader.close();
}
catch(IOException exp){}
}
}
else if(e.getSource()==save){
int state=fileDialog.showSaveDialog(this);
if(state==JFileChooser.APPROVE_OPTION){
try{
File dir=fileDialog.getCurrentDirectory();
String name=fileDialog.getSelectedFile().getName();
File file=new File(dir,name);
fileWriter=new FileWriter(file);
out=new BufferedWriter(fileWriter);
out.write(text.getText());
out.close();
fileWriter.close();
}
catch(IOException exp){}
}
}
else if(e.getSource()==red){
text.setForeground(Color.red);
}
else if(e.getSource()==blue){
text.setForeground(Color.blue);
}
else if(e.getSource()==green){
text.setForeground(Color.green);
}
else if(e.getSource()==yellow){
text.setForeground(Color.yellow);
}
else if(e.getSource()==bold){
f=Font.BOLD;
}
else if(e.getSource()==italic){
f=Font.ITALIC;
}
else if(e.getSource()==size16){
s=16;
}
else if(e.getSource()==size32){
s=32;
}
else if(e.getSource()==size48){
s=48;
}
else if(e.getSource()==size64){
s=64;
}
Font F=new Font(null,f,s);
text.setFont(F);
}
}
F. 用java做文本编译器
给你个简单的记事本代码,自己看着修改吧!
package com.csk.notepad;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class MyNotepad implements ActionListener {
private JFrame frame = new JFrame("Notepad By ChenXiaoKang");
private JTextArea jta = new JTextArea();
private String result = "";
private boolean flag = true;
private File f;
private JButton jb = new JButton("开始");
private JTextField jtf = new JTextField(15);
private JTextField jt = new JTextField(15);
private JButton jbt = new JButton("替换为");
private JButton jba = new JButton("全部替换");
private Icon ic = new ImageIcon("D:\\java课堂笔记\\GUI\\11.gif");
private String value;
private int start = 0;
private JFrame jf = new JFrame("查找");
private JFrame jfc = new JFrame("替换");
@Override
public void actionPerformed(ActionEvent e) {
String comm = e.getActionCommand();
if ("新建".equals(comm)) {
if (!(frame.getTitle().equals("新记事本"))) {
if (!flag) {
write();
newNew();
} else {
JFileChooser jfc = new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null, "保存为");
if (returnVal == JFileChooser.APPROVE_OPTION) {// 选择文件后再执行下面的语句,保证了程序的健壮性
f = jfc.getSelectedFile();
flag = false;
write();
}
}
} else if (!(jta.getText().isEmpty())) {
JFileChooser jfc = new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null, "保存为");
if (returnVal == JFileChooser.APPROVE_OPTION) {// 选择文件后再执行下面的语句,保证了程序的健壮性
f = jfc.getSelectedFile();
flag = false;
write();
newNew();
}
} else {
newNew();
}
} else if ("打开".equals(comm)) {
JFileChooser jfc = new JFileChooser("D:\\java课堂笔记");
jfc.setDialogType(JFileChooser.OPEN_DIALOG);
int returnVal = jfc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {// 选择文件后再执行下面的语句,保证了程序的健壮性
f = jfc.getSelectedFile();
frame.setTitle(f.getName());
result = read();
flag = false;
value = result;
jta.setText(result);
}
} else if ("保存".equals(comm)) {
JFileChooser jfc = new JFileChooser("D:\\java课堂笔记");
if (flag) {
int returnVal = jfc.showDialog(null, "保存为");
if (returnVal == JFileChooser.APPROVE_OPTION) {// 选择文件后再执行下面的语句,保证了程序的健壮性
f = jfc.getSelectedFile();
flag = false;
write();
}
} else {
write();
}
} else if ("另存".equals(comm)) {
JFileChooser jfc = new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null, "另存");
if (returnVal == JFileChooser.APPROVE_OPTION) {// 选择文件后再执行下面的语句,保证了程序的健壮性
f = jfc.getSelectedFile();
write();
}
} else if ("退出".equals(comm)) {
System.exit(0);
} else if ("撤销".equals(comm)) {
jta.setText(value);
} else if ("剪切".equals(comm)) {
value = jta.getText();
jta.cut();
} else if ("复制".equals(comm)) {
jta.();
} else if ("粘贴".equals(comm)) {
value = jta.getText();
jta.paste();
} else if ("删除".equals(comm)) {
value = jta.getText();
jta.replaceSelection(null);
} else if ("全选".equals(comm)) {
jta.selectAll();
} else if ("查找".equals(comm)) {
value = jta.getText();
jf.add(jtf, BorderLayout.CENTER);
jf.add(jb, BorderLayout.SOUTH);
jf.setLocation(300, 300);
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} else if ("替换".equals(comm)) {
value = jta.getText();
GridLayout gl = new GridLayout(3, 3);
JLabel jl1 = new JLabel("查找内容:");
JLabel jl2 = new JLabel("替换为:");
jfc.setLayout(gl);
jfc.add(jl1);
jfc.add(jtf);
jfc.add(jb);
jfc.add(jl2);
jfc.add(jt);
jfc.add(jbt);
JLabel jl3 = new JLabel();
JLabel jl4 = new JLabel();
jfc.add(jl3);
jfc.add(jl4);
jfc.add(jba);
jfc.setLocation(300, 300);
jfc.pack();
jfc.setVisible(true);
jfc.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} else if ("版本".equals(comm)) {
JDialog jd = new JDialog(frame, "关于对话框");
jd.setSize(200, 200);
JLabel l = new JLabel("哈哈哈哈哈哈哈哈哈哈呵呵呵呵呵呵呵呵呵呵呵呵呵");
jd.add(l, BorderLayout.CENTER);
jd.setLocation(100, 200);
jd.setSize(300, 300);
jd.setVisible(true);
// jd.pack();
jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
} else if ("开始".equals(comm) || "下一个".equals(comm)) {
String temp = jtf.getText();
int s = value.indexOf(temp, start);
if (value.indexOf(temp, start) != -1) {
jta.setSelectionStart(s);
jta.setSelectionEnd(s + temp.length());
jta.setSelectedTextColor(Color.GREEN);
start = s + 1;
jb.setText("下一个");
// value=value.substring(s+temp.length());//不能截取字串
} else {
JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);
jf.dispose();
}
} else if ("替换为".equals(comm)) {
String temp = jtf.getText();
int s = value.indexOf(temp, start);
if (value.indexOf(temp, start) != -1) {
jta.setSelectionStart(s);
jta.setSelectionEnd(s + temp.length());
jta.setSelectedTextColor(Color.GREEN);
start = s + 1;
jta.replaceSelection(jt.getText());
} else {
JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);
jf.dispose();
}
} else if ("全部替换".equals(comm)) {
String temp = jta.getText();
temp = temp.replaceAll(jtf.getText(), jt.getText());
jta.setText(temp);
}
}
public String read() {
String temp = "";
try {
FileInputStream fis = new FileInputStream(f.getAbsolutePath());
byte[] b = new byte[1024];
while (true) {
int num = fis.read(b);
if (num == -1)
break;
temp = temp + new String(b, 0, num);
}
fis.close();
} catch (Exception e1) {
e1.printStackTrace();
}
return temp;
}
public void write() {
try {
FileOutputStream fos = new FileOutputStream(f);
fos.write(jta.getText().getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void newNew() {
frame.dispose();
new MyNotepad();
flag = true;
}
public MyNotepad() {
JMenuBar jmb = new JMenuBar();
String[] menuLab = { "文件", "编辑", "帮助" };
String[][] menuItemLab = { { "新建", "打开", "保存", "另存", "退出" },
{ "撤销", "剪切", "复制", "粘贴", "删除", "全选", "查找", "替换" }, { "版本" } };
for (int i = 0; i < menuLab.length; i++) {
JMenu menu = new JMenu(menuLab[i]);
jmb.add(menu);
for (int j = 0; j < menuItemLab[i].length; j++) {
JMenuItem jmi = new JMenuItem(menuItemLab[i][j]);
menu.add(jmi);
jmi.addActionListener(this);
}
}
frame.setJMenuBar(jmb);
jta.setLineWrap(true);// 自动换行
JScrollPane jsp = new JScrollPane(jta);// 滚动窗口面板
frame.add(jsp);
jb.addActionListener(this);
jbt.addActionListener(this);
jba.addActionListener(this);
frame.setLocation(200, 50);
frame.setSize(620, 660);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyNotepad();
}
}
G. 如何用java进行编程
D:Javajdk1.5.0in 目录下都是jdk的工具,使用java编程主要用到的是javac.exe、java.exe这两个命令行工具。具体使用步骤如下:
1、配置java系统环境变量:新建文本文件,复制下面代码,然后另存为jdk.bat文件。 @echo setx /M JAVA_HOME "D:Javajdk1.5.0" setx /M CLASSPATH ".;%%JAVA_HOME%%lib;%%JAVA_HOME%%lib ools.jar;" setx /M PATH "%PATH%;%%JAVA_HOME%%in;%%JAVA_HOME%%jrein;" pause
H. java如何将编译结果输出到文本
FileOutputStream
RandomAccessFile
都可以实现
I. 如何用java实现一个文本编译器
JDK自带一个简单的Notepad,你可以研究一下他的源代码。
在%JAVA_HOME%\demo\jfc\Notepad 目录下
JDK自带一个稍复杂的Stylepad,你可以研究一下他的源代码。
在%JAVA_HOME%\demo\jfc\Stylepad目录下
J. 用文本文档写的java程序 怎么编译啊
先得安装jdk,然后配置环境变量class_path、home_java、path这三个,一般配第一个path就可以了
配置class_path的步骤:
在桌面上选中“我的电脑”,
鼠标右键单击,
打开“属性”,选中“高级”,
有个“系统变量”,
在系统变量里寻找“path”,选中,点击“编辑”
把你配置jdk的bin的路径加到path的最前边,与后边的系统设定的用 “;”隔开,保存就可以了
打开命令提示符框,输入java,回车,没有出现错误提示,而是java的一些相关信息,则表示成功
再输入javac看是否能成功,如果提示找不到路径则配置可能有问题
如果成功就可以对程序进行编译了。
首先,在命令提示符下切换到你写程序的路径下
编译:输入javac + 你的java文件名 回车
运行:java+你的文件名