By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

Running java program

lifeisgreat20009
P: 70
This is what i am getting on running the program.........

C:\PROGRA~1\Java\JDK15~1.0\bin>javac Editor.java
Note: Editor.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.


I did run the program like this after compiling it using javac command.........

I get this........

C:\PROGRA~1\Java\JDK15~1.0\bin>Editor
'Editor' is not recognized as an internal or external command,
operable program or batch file.



On giving Editor.java as the command the file itself gets opened and not a new text editor that i want................



Below is my code with no errors but its not running.........


Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4.  
  5. class Editor extends Frame implements ActionListener
  6. {
  7. TextArea textArea = new TextArea();
  8.  
  9. //Set up the menu on the default CTOR.
  10. Editor()
  11. {
  12. super("Text AWT Editor");
  13. setLayout(new BorderLayout());
  14. add("Center", textArea);
  15. Menu menu = new Menu("File");
  16. menu.add(makeMenuItem("Open"));
  17. menu.add(makeMenuItem("Save"));
  18. menu.add(makeMenuItem("Quit"));
  19. MenuBar menuBar = new MenuBar();
  20. menuBar.add(menu);
  21. setMenuBar(menuBar);
  22. pack();
  23. }
  24. private MenuItem makeMenuItem(String name)
  25. {
  26. MenuItem m = new MenuItem(name);
  27. m.addActionListener(this);
  28. return m;
  29. }
  30. public static void main(String[] s)
  31. {
  32. new Editor().show();
  33. }
  34. public void actionPerformed(ActionEvent e)
  35. {
  36. String command = e.getActionCommand();
  37. if (command.equals("Quit"))
  38. dispose();
  39. else if (command.equals("Open"))
  40. openFile();
  41. else if (command.equals("Save"))
  42. saveFile();
  43. }
  44. private void openFile()
  45. {
  46. //Show the Open File dialog box to the user.
  47. FileDialog fd = new FileDialog(this, "Open File", FileDialog.LOAD);
  48. fd.show();
  49.  
  50. //Get the file path.
  51. StringBuffer sbPath = new StringBuffer(fd.getDirectory());
  52. sbPath.append("\\");
  53. String fileName = fd.getFile();
  54.  
  55. //Cancel if null:
  56. if (fileName == null)
  57. {
  58. return;
  59. }
  60. else sbPath.append(fileName);
  61.  
  62. // Open and fill the input stream; paint the TextArea.
  63. try
  64. {
  65. FileInputStream fs = new FileInputStream(sbPath.ToString());
  66. byte[] data = new byte [ sbPath.length() ];
  67. fs.read(data);
  68. textArea.setText(new String(data));
  69. }
  70. catch (IOException e)
  71. {
  72. textArea.setText(e.toString());
  73. }
  74. }
  75.  
  76. private void saveFile()
  77. {
  78. try
  79. {
  80. // Show the dialog box to the user.
  81. FileDialog fd = new FileDialog(this, "Save File", FileDialog.SAVE);
  82. fd.show();
  83.  
  84. //Get the path and file name.
  85. StringBuffer sbPath = new StringBuffer(fd.getDirectory());
  86. sbPath.append("\\");
  87. // Get the file name to create:
  88. sbPath.append(fd.getFile());
  89. FileOutputStream fo = new FileOutputStream(sbPath.ToString());
  90.  
  91. // Parse the data: 
  92. String strdata = textArea.getText();
  93. byte[] data = new byte [strdata.length()];
  94. for (int idx = 0; idx < strdata.length(); idx++)
  95. {
  96. data[idx] = (byte)strdata.charAt(idx);
  97. }
  98. // Write the array to the file.
  99. fo.write(data);
  100. }
  101. catch (IOException ex)
  102. {
  103. textArea.setText(ex.toString());
  104. }
  105. }
  106. }
  107.  
  108.  
Nov 1 '07 #1
Share this Question
Share on Google+
4 Replies


10K+
P: 13,264
The
Expand|Select|Wrap|Line Numbers
  1. javac
command does not run the program. It compiles the .java file into a .class file.
To run the .class file, run the
Expand|Select|Wrap|Line Numbers
  1.  java 
command

That deprecated warning thing means exactly what it says there.
Nov 1 '07 #2

lifeisgreat20009
P: 70
I did run the program like this after compiling it using javac command.........

I get this........

C:\PROGRA~1\Java\JDK15~1.0\bin>Editor
'Editor' is not recognized as an internal or external command,
operable program or batch file.
Nov 1 '07 #3

10K+
P: 13,264
Do not start many threads on the same topic. Use one thread for one problem.

Type
Expand|Select|Wrap|Line Numbers
  1.  java Editor
at the command after compiling to run the program
Nov 1 '07 #4

lifeisgreat20009
P: 70
Ok Sorry.............
I will remember that..............
And thanks a lot..................
Thank you sooooooooooooo much...............

Bye.............
take care...........
Nov 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.