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+你的文件名