Java Notepad++ Editor

Notepad++ as a Java IDE

♥ Notepad++ is one of the best editors, simple yet powerful.
♥ It can easily be used to compile and run Java programs.
♥ You can put Notepad++ and Java on a USB drive and program in Java everywhere!
♥ Thus it is a simpler, more streamlined alternative to Eclipse.
[If you can't get this to work, use Eclipse - but it won't run off a USB drive.]
♦ Unfortunately, unlike Java, it only runs on Windows.

In this article I’ll explain how to setup Notepad++ and Java so that you can use Notepad++ to compile and run Java programs.
These instructions are to set things up so that  everything run on a USB flash drive.
If  you want to install the programs onto your hard drive (i) you can download Notepad++ instead of Notepad++ Portable, and (ii) you need to find and use the correctpath to javac.exe (and java.exe) — instead of “\java\jdk1.7.0_11\bin\javac”. It will probably be something like “C:\program files\java\…” .
Also, as new versions of Java come out you’ll have to modify the path to the correct version number.

There are 4 parts to this:

  1. installing Java JDK
  2. installing Notepad++ portable
  3. adding scripts to Notepad++
  4. testing everything by compiling and running a Java program

♣ Part 1: install Java 7 JDK

(JDK means Java Development Kit — which is what you need in order to compile Java programs.)

  1. Go to: http://www.oracle.com/technetwork/java/javase/downloads/index.htmlClick on the appropriate button (as seen below) to do to the download pagebutton to click to go to download pae .
  2. On the next screen (see below) select
    Windows x86 for 32 bit windows(e.g. jdk-7u11-windows-i586.exe) or
    Windows x64 or for 64 bit windows( e.g. jdk-7u11-windows-x64.exe)
    Oracle JDK download page
  3. Next, install the JDK file you downloaded (jdk-7u11-windows-i586.exe) by clicking on it and choosing the default options..
  4. Now copy the folder C:\Program Files\Java to your USB flash drive (e.g. to M:\Java)
    ProgramFiles

♣ Part 2: download, install, configure Notepad++ NotepadppPortable_128

  1. Go to: http://portableapps.com/apps/development/notepadpp_portableDownloading Notepad++ .
  2. Download Notepad++ and Install it to your USB drive.
  3. Now run Notepad++, and go to the menu option Plugins/Plugin Manager/Show Plugin Manager and install these plugins.
      1. “Compare” is very useful for comparing versions of documents or source code
      2. “NppExec” is essential for compiling Java code
      3. “TextFx Characters” has the ability to automatically indent your code
      4. “Hex-Editor” is optional. You have to click on “Settings” and then “Show Unstable Plugins” to be able to install it.

    Notepad++ Plugins needed .

  4. Notepad++ Portable is now correctly installed on your USB flash drive (presumably, that’s where you installed it). You should also probably make a folder for where you’ll be storing your programs (I called it JavaProgs).USBfolders

♣ Part 3: adding scripts to Notepad++

Unfortunately, I’m getting tired of making all of these screen shots. Most of this section is written instructions.

  1. Enter new commands that show up in the Macros menu by doing the following:
    1. Plugins/NppExec/Execute… (or Press F6)
    2. You’ll see a box that says “Temporary Script”
      Paste in this code:

      //save current file
      NPP_SAVE
       
      cd "$(CURRENT_DIRECTORY)" 
      "\java\jdk1.7.0_11\bin\javac" $(FILE_NAME)
    3. Click “Save…”
    4. Then type in “Java-Compile” (this is the name of your script)  and click Save
    5. You then get back to the previous screen and have the choice of clicking OK or CANCEL. Click “Cancel” which exits NppExec without running the script (OK would run it)
    6. “Java-compile” is used to compile your programs. (If you have a different path, you will have to modify the scripts.)
  2. Go back to Plugins/NppExec/Execute… (or Press F6) and repeat these steps to enter the following scripts
    1. Note: first select “Temporary Script” to clear the box so that you can paste in the next script
    2. “Java-run” is the name of this second script. It will run the Java program after it has been compiled.
      //save current file
      //NPP_SAVE
       
      cd "$(CURRENT_DIRECTORY)" 
      "\java\jdk1.7.0_11\bin\java"  -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
    3. “Java-applet-HTML” is the name of this script. It is used to make a very simple HTML file for running Java applets. [Don't bother with C and D unless you plan to use applets.]
      cd $(CURRENT_DIRECTORY)
       
      cmd /c echo "lt;html><head><title>The $(NAME_PART) applet</title></head>" > $(NAME_PART).html
      cmd /c echo "<body><h2>Here is the $(NAME_PART) applet</h2><hr>" >> $(NAME_PART).html
      cmd /c  echo "<applet code="$(NAME_PART).class" width="600" height="400"></applet><hr></body></html>" >> $(NAME_PART).html
      Note: I can’t find any way of not displaying &gt; and &lt;  If I use the > and < symbols, then the code is treated as HTML instead of plain text. I also can’t use &#60;  WordPress is just screwed up.
    4. “Java-applet-run” is the name of the fourth script. It is used to run an applet after it has been compiled and the HTML file created.
      cd "$(CURRENT_DIRECTORY)" 
      "\java\jdk1.7.0_11\bin\appletviewer"  $(NAME_PART).html
  3. Now we add the scripts to the Macros menu.
    1. go to the submenu Plugins/NPPexec/Advanced Options
    2. select script from “Associated Script” combo box. It will automatically fill in the “Item Name”
    3. now click the “Add/Modify” button
    4. Check the box at the top that says “Place to the Macros Submenu”
    5. Click OK. This will exit the Advanced Options box and say that NotePad++ needs to be restarted (don’t restart it until all 4 scripts have been added).
      We have to click OK because it’s the easiest way of clearing the boxes to add the next script otherwise it’s likely to overwrite the existing menu option.
    6. Repeat these steps to add the other 4 scripts.
    7. Close Notepad++ and restart it.
  4. When you’re done, click on the Macros Menu and you should see the 4 Java scripts (not Javascript!) that we added at the bottom. (see below)macros

♣ Part 4: testing to make sure that everything works.

  1. copy and paste the following code into a Notepad++ window
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.GridLayout;
    import java.awt.Container;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class Draw4Ovals extends JPanel {
     
      Color color;
     
      public Draw4Ovals(Color color) {    
        this.color = color;
        this.setBackground(Color.BLACK);
        this.setOpaque(true);    //needed to ensure panel background is set
      }
     
      public void paintComponent(Graphics g) {
        super.paintComponent(g);    //needed to ensure that panel background is set
        int width = getWidth();
        int height = getHeight();
        g.setColor(color);
        g.fillOval(0, 0, width, height);
      }
     
      public static void main(String args[]) {
        JFrame frame = new JFrame("Oval Sample");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
        Container content = frame.getContentPane();
        content.setBackground(new Color(180,230,255));    
        content.setLayout(new GridLayout(2, 2, 5 ,5));
        Color colors[] = { Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW };
        for(Color c: colors) {
          Draw4Ovals panel = new Draw4Ovals(c);     
          content.add(panel);
        }
        //validate must be done on the component that has the .add() and the layoutManager
        content.validate();    
        frame.setSize(300, 200);
        frame.setLocation(50,100);
        frame.setVisible(true);    
      }
    }
  2. Save this file as “Draw4Ovals.java”.  Upper-case is important. Once it is saved, you’ll see that Notepad++ does syntax highlighting.
  3. Select the Macros menu, then click on the Java-compile macro near the bottom. The results should look like this:java-compile .
  4. Now select the macro “Java-run”. You should see this:
    java-run .
  5. If, in addition, you want to test an applet,
      1. paste the following code
      2. save it as “TestApplet.java”
      3. run “Java-compile”
      4. run “Java-applet-HTML”
      5. now either view the file in a browser, or else run “Java-applet-viewer”
        import java.awt.*; 
        import java.awt.event.*; 
        // import java.applet.Applet; 
        import javax.swing.*;
         
        public class TestApplet extends JApplet implements ActionListener { 
        	Button b; 
        	JLabel jl;
        	public void init(){ 
        		setLayout(new FlowLayout()); 
        		b = new Button("push me"); 
        		b.addActionListener(this); 
        		add(b);
        		jl = new JLabel("Welome to my applet");
        		add(jl);
        	} 
         
        	public void actionPerformed(ActionEvent e){ 
        		jl.setText("You clicked?");		
        	}
        }
  6. Note: ♦Applets are no longer used as much as other types of web-programming.
    ♦The Java-applet-HTML script just makes a very simple HTML page. If you want to put an applet in a webpage, you should actually make a decent webpage.
    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    Java Notepad是一款文本编辑器,用于编写和运行Java程序。它可以通过在Notepad中编写Java代码,并使用Java运行环境(JRE)来执行代码。要在Notepad中使用Java Notepad,首先需要将Java代码添加到Notepad中。确保您已经在计算机上配置了Java环境变量。然后,您可以在Notepad中安装并配置Java运行环境的插件,例如NPPExec。请注意,Java Notepad是国外的软件,在国内可能没有专门的下载通道。您可以通过在百度上搜索下载网站来找到Notepad的下载地址,并根据您的电脑配置需求选择下载。安装和使用Java Notepad之后,您可以在Notepad中编写Java代码,并使用Java运行环境来运行和测试您的程序。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Notepad++安装及java使用教程](https://blog.csdn.net/qq_45959626/article/details/123378009)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Notepad++软件下载以及Notepad++配置java环境](https://blog.csdn.net/Sheenky/article/details/125059456)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值